Apply Multiple Shopping Cart Price Rules to One Item

shopping-cart-price-rules

I have a Shopping Cart Price Rule that if a product meets a condition that it applies the rule, simple normal. I have another rule for the same product that is set for a different condition. The issue is that, due to the way the promotion is set up I need to let both rules be applied to the item, but what happens is that only one is applying to the item. I have tested this out by turning one rule off, which I'll see the other be applied, and then flip it and I'll see the other active rule applied.

What needs to happen is that I need to let both be applied to the item for a combined discount. There are like 3 versions of the rules now, and if I was to try to do all the combinations of these current rules, then I'd have like 50 rules to try to account for all the possible conditions. Well not 50 but point is making new rules is not a clean way to deal with this.

Any ideas on how to extend the promotions so that more then one rule may apply? Maybe a simple extension example to be clear?

update 1

It seems to me that I may want to try to extend Mage_SalesRule_Model_Resource_Rule_Collection ? I'm still trying to find the root of where the override should take place to allow for a clean implementation to get more then one rule to apply to an item. I know there will need to be things accounted for like the order/quote to the reports, but the thought here is that if I start at the collection, that it'll apply in all the other places.

update 2 (further inspection of the core)

I have been rooting around to find answer this question:

Where does it stop processing a discount for an item(action)?

This seems to me to be the root area where one would address the solution to the issue, at the time of writing I believe, Mage_SalesRule_Model_Validator->process(). In there it does a

    $appliedRuleIds = array();
    foreach ($this->_getRules() as $rule) {

Which is promising in the sense that Magento is looping over all the rule on the (Mage_Sales_Model_Quote_Item_Abstract)$item and it seems that

        /* @var $rule Mage_SalesRule_Model_Rule */
        if (!$this->_canProcessRule($rule, $address)) {
            continue;
        }

        if (!$rule->getActions()->validate($item)) {
            continue;
        }

is the deciding factor, but I see nothing that indicates a check for a rule that is already applied. At this time, it's not apparent where the "stop we already applied a rule" part is coming in.

Still running it down

I see that if I check

        if ($rule->getStopRulesProcessing()) {
            //$this->_stopFurtherRules = true;
            //break;
        }

in the Mage_SalesRule_Model_Validator->process() it will move on to the next rule, but, it seems to just over ride the next rule (I think) and it's not cumulative. One step forward two steps back

pushing forward

It seems that maybe the issue of the cumulative discount not occurring is that the base discounts are hardcoded to 0.

        $discountAmount = 0;
        $baseDiscountAmount = 0;
        //discount for original price
        $originalDiscountAmount = 0;
        $baseOriginalDiscountAmount = 0;

Is that is in that foreach loop. It would seem that I would want to be getting those from the item object not set as 0

side thought I ran down

So I had a thought.. what if the product in the order that has the qty of 3 (mind you this is what I'm testing) is $25 and the two discounts are $25 and $10. What I'm thinking is that it's not that its 3*25 – 35, but it's that it was only picking up the 1 of 3 and trying to do the math on that so it'd be a – number.. but doesn't seem to be supported in the code, and when I switch it to the off cart fixed mode, it still isn't working..

———————————————————-

screenshots

———————————————————-

rule 1

No conditions, Action shown below with item rule

rule 1

rule 2

No conditions, Action shown below with item rule

enter image description here

results

Both discounts show but the total is not matching

enter image description here

Best Answer

Here is working example of how 2 shopping cart price rules can affect one item. The final screen uses this module to show discount breakdown.

The setup is straightforward:

Rule #1

Conditions tab:
Conditions 1

Actions tab:
Actions 1

and Rule #2

Conditions tab:
Conditions 2

Actions tab:
Actions 2

Result: result

Please edit your answer in the same way, so I can get better advice step by step. No code, just the Magento version and rules set up.

It's definitely possible to apply several discounts to one product (as shown above).

Related Topic