Shopping Cart Rules with Custom Condition?

Josua Marcel C picture Josua Marcel C · Aug 8, 2012 · Viewed 7.8k times · Source

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.

Answer

Josua Marcel C picture Josua Marcel C · Aug 23, 2012

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.