Question

I have made a coupon [coupon_code = SWIMFREE] if category is swimming equipment and hobby is swimming will be discount by 50%.

and now I have problem about 3 steps checkout. Here's the description ...

  1. Checkout Cart : to apply to coupon
  2. First Step : Shipping and Billing Address
  3. Second Step : Pick your Hobby (has another sales_flat_quote table, sales_flat_quote_hobby)
  4. Final Step : Checkout->Overview

What i wanted is: when the coupon applied and the hobby is swimming, the third step changing the price to price every product, and coupon is still be shown there.

How to intercept the coupon after Hobby step?


Example case step by step:

1. On cart it's already added

  • Swim Suit's normal price is 100$ (Swimming Equipment Category)
  • Kevlar's normal price is 50$ (Shooting Equipment Category)
  • Coupon Applied SWIMFREE, Grand Total is 100$ (because of the Coupon condition)

2. On Shipping&Billing Step

  • Shipping and Billing address - Next

3. On Hobby Step

  • The Football hobby is checked (radio button) and confirmed

4. On Overview Step then

  • Swim Suit's price is 50$ (Swimming Equipment Category)
  • Kevlar's price is 50$ (Shooting Equipment Category)
  • Coupon Applied SWIMFREE, Grand Total now is 150$ (because the hobby isn't swimming)

i have a lot of products, I've tried to add new attributes, but it's not related with the attribute, because it's on sales_flat_quote_hobby

I've tried to change Sales/Model/Quote/Subtotal.php to set the all product prices on cart, but it seems useless.

Was it helpful?

Solution

already found the answer by myself:

It is possible to create a customized coupon condition.

coupon example

rewrite the Mage_SalesRule_Model_Rule_Condition_Product

    public function validate(Varien_Object $object){
        if ($this->getAttribute() == 'quote_item_with_hobby') {

            $quote = Mage::getSingleton('checkout/cart')->getQuote();
            $hobby= $quote->getHobbyByItemId($object->getId());

            if ($hobby){
                if ($this->getOperator() == '=='){
                    if (strtolower($this->getValue()) == $hobby->getHobby()) return true;
                    else return false;
                }
                else if ($this->getOperator() == '!='){
                    if (strtolower($this->getValue()) == $hobby->getHobby()) return false;
                    else return true;
                }

            }
            return true;
        }

        return parent::validate($object);
    }

this function will be called every step loaded. then checked if return true, then the coupon will be applied, if return false then the coupon won't be applied.

Thank's to All Who Participated. i appreciate it.

OTHER TIPS

You should implement your custom collector for collecting totals. It could be based on Mage_SalesRule_Model_Quote_Discount.
How to create custom collectors: see stackoverflow answer, or you can check this article.

Yes, that would be my idea.

You implement a new salesrule condition which gives 50% discount.

The salesrules are called for every product. then you need to check, wether the attribute is swimming and the hobby is set. If that is the case, you can copy the rest from the %-salesrule

You find code to have a look on in Mage_SalesRule_Model_Validator::process()

An example for a self implemented condition can be found here: https://github.com/magento-hackathon/DiscountForATweet/blob/master/app/code/community/Hackathon/DiscountForATweet/Model/Condition/Tweet.php

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top