Shopping Cart Rules with Custom Condition?

前端 未结 3 1340
臣服心动
臣服心动 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.

提交回复
热议问题