Shopping Cart Rules with Custom Condition?

别说谁变了你拦得住时间么 提交于 2019-11-30 09:49:07

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.

Roman Snitko

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

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