1

I am using Magento 2.4 EE.

I have created a custom cart rule but the issue i am facing with it is when the discount is 0 then also it applies to the cart.

So, I want to know which files are responsible for preventing the coupon code/cart rule to apply when the discount amount of the applied coupon is 0.

I have checked on Magento sales rule module but did not get much clue

4
  • any thoughts on this ?
    – devhs
    Jul 13, 2021 at 12:23
  • Can you write more about this?
    – Sohel Rana
    Jul 13, 2021 at 12:29
  • Can you tell what conditions are you applying while creating the rule ? Jul 13, 2021 at 15:33
  • Yes let me update the question
    – devhs
    Jul 14, 2021 at 4:49

2 Answers 2

2

Open the vendor/magento/module-sales-rule/Model/Validator.php class, Then check the following method:

public function process(AbstractItem $item)

Now open: vendor/magento/module-sales-rule/Model/RulesApplier.php and check:

public function applyRules($item, $rules, $skipValidation, $couponCode)

and

protected function applyRule($item, $rule, $address, $couponCode)

[Update]

The following location you have all discount type:

vendor/magento/module-sales-rule/Model/Rule/Action/Discount

Open vendor/magento/module-sales-rule/Model/Rule/Action/Discount/ToFixed.php and check the following method:

public function calculate($rule, $item, $qty)

[Update (2021-07-17)]

Try to add following code after $this->applyRule( in vendor/magento/module-sales-rule/Model/RulesApplier.php:: public function applyRules($item, $rules, $skipValidation, $couponCode)

if ($item->getDiscountAmount() <= 0 ) {
    continue;
}

Don't write the core, you can create a patch or overwrite that class. It's a bad class which means lots of private property and method of that class.

10
  • Thanks for the answer, i need to know where it checks if discount amount is > 0 then rule apply else not.
    – devhs
    Jul 13, 2021 at 12:44
  • Updated, you can try
    – Sohel Rana
    Jul 13, 2021 at 12:57
  • I am not sure why it sets in DiscountData if all amount are 0 ?
    – devhs
    Jul 13, 2021 at 12:59
  • 1
    Yeah. You can see that coupon in quote table and shopping cart because that is valid coupon.
    – Sohel Rana
    Jul 14, 2021 at 5:30
  • 1
    Check the updated answer
    – Sohel Rana
    Jul 17, 2021 at 7:10
0

Hello below is file and function fire when you apply Coupon Code

vendor/magento/module-quote/Model/CouponManagement.php

public function set($cartId, $couponCode){}

hope it's help you :)

1
  • Thanks for the answer, i need to know where it checks if discount amount is > 0 then rule apply else not.
    – devhs
    Jul 13, 2021 at 12:44

Your Answer

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

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