We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

If you want to apply cart price rules like free shipping after discount and tax calculation, then you need to do customization in the sales rule module.

To add new option in the cart price rule condition drop-down, You need to create custom extension like “Magemonkeys_Cartrule”.

1. Create registration.php in app/code/Magemonkeys/Cartrule/

<?php 
MagentoFrameworkComponentComponentRegistrar::register(
    MagentoFrameworkComponentComponentRegistrar::MODULE,
    'Magemonkeys_Cartrule',
    __DIR__
);

2. Create module.xml in app/code/Magemonkeys/Cartrule/etc/

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
    <module name="Magemonkeys_Cartrule" setup_version="1.0.0">
    </module>
</config>

3. Create di.xml in app/code/Magemonkeys/Cartrule/etc/adminhtml/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">    
    <preference for="MagentoSalesRuleModelRuleConditionAddress" type="MagemonkeysCartruleModelRuleConditionAddress" />
</config>

4. Create Address.php in app/code/Magemonkeys/Cartrule/Model/Rule/Condition/Address.php

<?php

namespace MagemonkeysCartruleModelRuleCondition;

/**
 * Class Address
 */
class Address extends MagentoSalesRuleModelRuleConditionAddress
{
    
    /**
     * Load attribute options
     * @return $this
     */
    public function loadAttributeOptions()
    {
        $attributes = [
            'base_subtotal_with_discount' => __('Subtotal (Excl. Tax)'),
            'base_subtotal' => __('Subtotal'),
            'total_qty' => __('Total Items Quantity'),
            'weight' => __('Total Weight'),
            'shipping_method' => __('Shipping Method'),
            'postcode' => __('Shipping Postcode'),
            'region' => __('Shipping Region'),
            'region_id' => __('Shipping State/Province'),
            'country_id' => __('Shipping Country'),
        ];

        $this->setAttributeOption($attributes);

        return $this;
    }

    /**
     * Get input type
     * @return numeric
     */
    public function getInputType()
    {
        switch ($this->getAttribute()) {
            case 'base_subtotal_with_discount':
            case 'base_subtotal':
            case 'weight':
            case 'total_qty':
                return 'numeric';

            case 'shipping_method':
            case 'payment_method':
            case 'country_id':
            case 'region_id':
                return 'select';
        }
        return 'string';
    }

}

5. Run php bin/magento setup:upgrade command

So you can see the “Subtotal (Excl. Tax)” option in cart price rule’s condition drop-down.

Note: This option has already added by Magento in Magento 2.3.2+ version

field_5bfb909c5ccae

    Recent Articles
    Get a Free Quote