3

I am working on Magento 2.2.5. I have one cart rule that gives free shipping if the subtotal is equal to or greater then $50.

It is working well, but if the user gets any discount from a coupon or any other discount then it is not working properly as subtotal is not considering discount amount.

If user purchases $55 products then he/she will get the free shipping in the checkout page. But when he uses the coupon that gives 10%($5.5) discount then the amount will be $49.5 then also the free shipping is applying.

So anyway to add this rule on subtotal including discounted amount?

Or do I need to change any code for cart rule?

I read many solutions from the stack and tried but with no luck.

Some of are of Magento 1 but I am using Magento 2.2.5

6
  • you can set the condition on subtotal if its not work try action on price in cart in cart rule
    – Hitesh
    Nov 28, 2018 at 10:06
  • Currently the rule is on subtotal. if subtotal is equal or greater then $50 then free shipping will apply/ Nov 28, 2018 at 10:08
  • Ok so try with actions on price in cart in cart rule it will solve your issue
    – Hitesh
    Nov 28, 2018 at 10:09
  • No it is not working by that way also. Nov 28, 2018 at 10:17
  • please check my answer
    – Hitesh
    Nov 28, 2018 at 10:28

4 Answers 4

0
  1. First You need to disable free shipping and enable flat rate.
  2. After that, you need to set the catalog price rules for free shipping discount over an order of 50$ or greater(add appropriate condition there). the In above case, your cart price rule(coupon code) and catalog price rule will work parallel.

Hope this helps.

5
  • I am not using free shipping method of magento. I have created rule for free shipping. Nov 28, 2018 at 10:30
  • Flate rate method is already enable Nov 28, 2018 at 10:31
  • My free shipping rule is already set with subtotal greater then $50. I am not getting your 2nd rule. Nov 28, 2018 at 10:33
  • Ok got it your case, you have created two coupon code right? one is for free shipping and other one is normal coupon code
    – Hitesh
    Nov 28, 2018 at 10:38
  • Yes I have created cart rule for free shipping. I am not using magento's free shipping method. I have many other coupon code rule that can be use in checkout page to get discount Nov 28, 2018 at 11:13
0

Don't know if your problem is still a thing, but i stumbled upon this a few month ago and found a solution for nearly the same issue, so maybe it helps someone. For me following this tutorial: https://magently.com/blog/magento-2-custom-sales-rule-condition/
and changing the validation function worked. As in the documentation of AbstractModel
(https://www.magentoextensions.org/documentation/class_magento_1_1_quote_1_1_model_1_1_cart_1_1_totals.html)
you can call the getSubtotalWithDiscount() function within the model and validate for being greater than 50.

public function validate(\Magento\Framework\Model\AbstractModel $model)
{
    $price = 0;   
    $price = $model->getSubtotalWithDiscount();

    if($price > 50){
        return true;
    }else{
        return false;
    }
}


2
  • Where I need to update this code? Jan 7, 2020 at 12:51
  • @VIPINAROY if you followed the tutorial, you can find the validate function in *YOUR CODE DIRECTORY*/CustomerRule/Model/Rule/Condition/Customer.php . This function returns true or false, so you can modify as you need it
    – Chris
    Jan 22, 2020 at 11:23
0

Actually the option Subtotal (excl. Tax) seems to be with discount, when having a look at the dropdown I see this:

<option value="Magento\SalesRule\Model\Rule\Condition\Address|base_subtotal_with_discount">Subtotal (Excl. Tax)</option>

So the base_subtotal_with_discount really seems to mean, that functionality is there in the core, but well hidden by bad translation.

EDIT

Actually this does not work :)

2
  • Hi Alex, have you found any solution to this? Aug 25, 2021 at 4:41
  • I don't think I did
    – Alex
    Aug 25, 2021 at 17:10
0

After some Extensive research, here is the answer (tested on Magento 1.9.2.3): Modify the following file websitename/app/code/core/Mage/Shipping/Model/Carrier/FreeShipping.php

Change the following line:

if (($request->getFreeShipping()) || ($request->getBaseSubtotalInclTax() >= $this->getConfigData('free_shipping_subtotal'))

Replace it with the following:

if (($request->getFreeShipping()) || ($request->getPackageValueWithDiscount() >= $this->getConfigData('free_shipping_subtotal'))

The $request->getPackageValueWithDiscount() will give you the Grand Total.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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