0

I want to apply the coupon automatically to the cart. I have used the below code in my custom module to apply the coupon code.

$quote->setCouponCode($rule->getCode())->collectTotals()->save();

After this, coupon code is applied and reflected in the quote table and the discount amount is also reflected in the order summary sidebar.

But in the Quote table, discount value is not applied and applied_rule_ids value is also empty. When I refresh the cart page all are reflected.

May I know what is the issue here.

1 Answer 1

0

Try resetting 'totals_collected' flag:

$quote->setCouponCode($rule->getCode())
    ->setTotalsCollectedFlag(false)
    ->collectTotals()
    ->save();
1
  • Hi Thanks for the information. I have tried, still is not workout. I have added the code in the apply coupon module. Do I need to write this code on Checkout module ? Nov 30, 2021 at 10:51

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.