0

I need to show custom coupon error messages on frontend based on conditions.Where does the validation of coupon occurs when customer applies a coupon on the checkout page?

As far as I know, Magento\Quote\Model\CouponManagement::set is called. In this function the following code applies the coupon code and recollects the quote totals:

$quote->setCouponCode($couponCode);
$this->quoteRepository->save($quote->collectTotals());

But after this I am not able to find where the validation occurs.

Edit: I am able to show custom error message for some validations by adding a plugin for Magento\Quote\Model\CouponManagement::set() method, but I need to show custom message to the customer for each cart condition also. For example, if the item does not belong to a certain category, or the subtotal of the cart is below the required amount, I need to show specific custom message to the customer.

Edit 2: I found that the validation of attributes is done in Magento\Rule\Model\Condition\AbstractCondition::validateAttribute(). This method is only returning true/false boolean value. I also need the attribute at which the coupon code fails and show it in the error message.

I need to get the attribute at which the coupon fails to apply and show it in a message to customer.

1 Answer 1

2

If you look in Magento\SalesRule\Model\Utility which can be found at vendor/magento/module-sales-rule/Model/Utility.php. From what I can find canProcessRule() is where it starts. It will then mark the rule as invalid when certain conditions aren't met.

0

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.