0

I want to add to sales rules for cart a rule where to add subtotal with TAX because I cannot relay on subtotal without TAX as I have products with different TAX class and different VAT values.

For example I have a product with VAT 19% and a product with VAT 9%, the I cannot trust the subtotal without TAX value, as it will depend on what type of products I add to the cart, in order for the rule to work correctly.

I want to apply a rule for subtotal bigger than 200 but I need to have subtotal with TAX.

How can I do this?

1 Answer 1

0

You could try something like this as a rewrite. I'm assuming you already know how to write a custom module.

/etc/config.xml


<config>
    <global>
        <models>
            <salesrule>
                <rewrite>      
                      <rule_condition_address>Vendor_Module_Model_SalesRule_Rule_Condition_Address</rule_condition_address>
                </rewrite>
            </salesrule>
        </models>
    </global>
</config>

Rewrite class

class Vendor_Module_Model_SalesRule_Rule_Condition_Address extends Mage_SalesRule_Model_Rule_Condition_Address
{
    public function loadAttributeOptions()

    {

        parent::loadAttributeOptions();

        $attributes = $this->getAttributeOption();

        $attributes['base_subtotal_with_tax'] = Mage::helper('salesrule')->__('Subtotal after tax');

        $this->setAttributeOption($attributes);

        return $this;

    }

    /**
     * (non-PHPdoc)
     * @see Mage_SalesRule_Model_Rule_Condition_Address::getInputType()
     */

    public function getInputType()

    {

        if ($this->getAttribute() == 'base_subtotal_with_tax')

            return 'numeric';

        return parent::getInputType();

    }

    /**
     * Add field "base_subtotal_with_tax" to address.
     * It is need to validate the "base_subtotal_with_tax" attribute
     * @see Mage_SalesRule_Model_Rule_Condition_Address::validate()
     */

    public function validate(Varien_Object $address)

    {


        $subAfterDiscount = // code to calculate subtotal with tax

        $address->setData('base_subtotal_with_tax', $subAfterDiscount);

        return parent::validate($address);

    }

}
2
  • Thank you! It is working in checkout but is not applying the rule in shopping cart page. It is working only in one page checkout!
    – andy1786
    Apr 26, 2020 at 20:24
  • I'm not sure why that is. Maybe because in shopping cart, the address is not set yet for the customer? I haven't tested it that much to be honest. I mean it's validating the rule based on address as I'm rewriting the Rule_Condition_Address.
    – gabtzi
    Apr 27, 2020 at 7:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.