Shopping Cart Rules with Custom Condition?

前端 未结 3 1339
臣服心动
臣服心动 2021-01-01 00:47

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

相关标签:
3条回答
  • 2021-01-01 01:01

    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.

    0 讨论(0)
  • 2021-01-01 01:15

    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.

    0 讨论(0)
  • 2021-01-01 01:24

    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

    0 讨论(0)
提交回复
热议问题