TransWikia.com

How to make Cart Rule test against Subtotal *with* Discount?

Magento Asked by Chad C. Davis on January 8, 2021

Consider the following snippet from my populated Magento CE 1.9.0.1 cart:

Cart Example

I have two test cart rules in play here:

  1. “50 Bucks Texas”, Priority 1, discounts the cart by 50.00 if the customer has selected Texas as their region.
  2. “Over 100.00 get 10.00 off”, Priority 9999, discounts the cart by 10.00 if the subtotal is greater than 100.00

As you can see both rules are coming up valid and are being applied even though after Rule #1 the subtotal (with discount) is less than 100.00. The desired action would be that Rule #2 does not validate because with Rule #1 in play the customer would be spending less than 100.00.

I have fought this issue in a number of ways to no avail. If it can be solved through rule configuration or other configuration I haven’t been able to figure out what that is.

If it can be solved by modifying code can someone point me in the right direction? One thing I tried as a proof-of-concept was to add a new attribute option of “Base Subtotal with Discount” to the Cart Attributes by modifying:

/app/code/core/Mage/SalesRule/Model/Rule/Condition/Address.php

class Mage_SalesRule_Model_Rule_Condition_Address extends Mage_Rule_Model_Condition_Abstract
{
    public function loadAttributeOptions()
    {
        $attributes = array(
            'base_subtotal_with_discount' => 'Subtotal with Discount',
            'base_subtotal' => Mage::helper('salesrule')->__('Subtotal'),
            'total_qty' => Mage::helper('salesrule')->__('Total Items Quantity'),
            'weight' => Mage::helper('salesrule')->__('Total Weight'),

Here I blindly added the first attribute key in that array “base_subtotal_with_discount” simply based on finding that string elsewhere in the code alongside the string ‘base_subtotal’. I was hoping I would get lucky and that would resolve to what I needed but unfortunately it does not. I haven’t been able to figure out where upstream I would define “base_subtotal_with_discount” so that I can use it.

One Answer

You are half way there. You added the attribute to be validated, but you haven't crafted the validation action that uses the attribute.

If you look at the sales rule configuration in the backend, the third tab on the left has an action, which contains a form specifying where the discount should be applied on. That's where a new option should be for subtotal after discount.

You do this by rewriting and extending Mage_SalesRule. This is one of the few resources I've been able to find that explains some of the complexities involved.

Answered by Melvyn on January 8, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP