Shopping Cart Rules with Custom Condition?

醉酒当歌 提交于 2019-11-29 14:53:38

问题


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.


回答1:


already found the answer by myself:

It is possible to create a customized coupon condition.

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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/11864012/shopping-cart-rules-with-custom-condition

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!