简体   繁体   中英

Creating a custom condition for a shopping cart price rule

I'm customizing an existing Magento install, and the customer wants a complicated condition for shopping cart price rules, which the built in conditions don't apply.

I essentially want to plug in my own custom php code. ie

function doesRuleApply() {
    //complicated code
    if ($someCondition) {
        return true; //i.e. apply the rule
    } else {
        return false; //i.e. don't apply rule
    }
}

I assume this is possible, given a custom module, but I'm not sure where to start. Looking at the existing rules, it looks very confusing.

Is there any guide or sample out there that describes how to start doing this, or can anyone point me in the right direction?

(it would also be ideal for them to be able to choose this rule in the frontend!)

I found a very straight forward and simple open-source plugin on github called DiscountForATweet .

They implemented a custom rule along with a Observer class , pointed me in exactly the direction I needed. It also happens to be a nice simple, self contained module that should help anyone learning Magento.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM