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/
1 2 3 4 5 6 |
<?php \Magento\Framework\Component\ComponentRegistrar::register( \Magento\Framework\Component\ComponentRegistrar::MODULE, 'Magemonkeys_Cartrule', __DIR__ ); |
2. Create module.xml in app/code/Magemonkeys/Cartrule/etc/
1 2 3 4 5 |
<?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
1 2 3 4 |
<?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="Magento\SalesRule\Model\Rule\Condition\Address" type="Magemonkeys\Cartrule\Model\Rule\Condition\Address" /> </config> |
4. Create Address.php in app/code/Magemonkeys/Cartrule/Model/Rule/Condition/Address.php
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
<?php namespace Magemonkeys\Cartrule\Model\Rule\Condition; /** * Class Address */ class Address extends \Magento\SalesRule\Model\Rule\Condition\Address { /** * 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
Please follow the below methods to get the attribute options...
Update product attribute value programmatically in Magento 2 . [crayon-62877bfac1e2a479734896/]...
If you want restrict customer to checkout based on your...
Sometime we need to set html data without load or...
If you want get query string params in controller file,...