1

I need to add coupon codes for a e-com shop built using Drupal Commerce, and have been playing with Commerce Coupon and Commerce Discount modules, but I can't seem to fix the problem of coupons being removed during checkout. This has been reported many times (see issues below), with various supposed fixes but I've tried everything and nothing works.

So, is there any alternative for this kind of functionality?

I really only need discounts on full orders (instead of products) but do need both percentage and fixed price options.

Alternatively if anyone has a real fix for the issue please let me know!

Issues for reference:

https://www.drupal.org/node/2619448

https://www.drupal.org/node/2328357

https://www.drupal.org/node/2464525

3
  • Are you using discount compatibility? I've seen coupons cycle on and off based on those settings before. Mar 6, 2017 at 15:36
  • I've tried using and not using - same result. As soon as I get to the billing section the coupon line item is removed (though still referenced).
    – Chris
    Mar 7, 2017 at 1:28
  • Ok, thanks for the information. I'm going to make sure we prioritize Commerce Discount / Coupon module clean-up in our upcoming contributed module days for the team. Mar 7, 2017 at 16:57

1 Answer 1

0

Both of those modules have caused me headaches, however I know of no alternative.

In order to fix the bug you need to ideally step through Commerce Coupon and Commerce Discount's implementation of commerce_cart_order_refresh and commerce_cart_line_item_refresh.

Line items kept getting deleted for me when they didn't have a properly formatted price.

By implementing my own commerce_cart_line_item_refresh I was able to fix any problems with line items before their code ran.

If I was to do a discount / coupon system again and the spec was not too complex I would be tempted to write something from scratch as both of those modules are suffering from a bit of bloat.

3
  • Do you have an example by any chance? I'm looking at commerce_discount_commerce_cart_order_refresh() but don't know where to begin. I can't see any implementation of commerce_cart_line_item_refresh()
    – Chris
    Mar 6, 2017 at 6:31
  • Or, as I'm tempted to roll my own too, what sort of approach would you use to achieve this?
    – Chris
    Mar 6, 2017 at 6:56
  • I would create a custom line item type for discount. This can hold the reference to the coupon (a custom entity) which has the fixed amount / percentage off value. Then either add a price component to each line item with a negative value equal to the discount (for discount applied to individual line items), or just set the value of the discount line item to the total order discount (for discount applied to the whole order). All of these calculations will need to take place in commerce_cart_order_refresh so it's calculated fresh after every change to the order.
    – Felix Eve
    Mar 6, 2017 at 7:09

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.