I have a site that allows multiple coupon codes to be used together in the checkout. This works correctly except when it comes to using multiple Bulk Coupon codes that were generated together.

Example Setup:

I generated 10 single use bulk codes:
TEST0B21A913
TEST19057203
TEST20FF2F76
TEST3910F387
TEST4D137E87
TEST59D2A993
TEST656DC642
TEST721A3247
TEST800A9267
TEST957BCE9F

I apply the first code. It works and I see the code as a line item in the payment method area.

I apply the 2nd code. The line items show that this code has been applied twice. The first code that I used is no longer referenced in the line items.

Apply the 2nd code again. Now I'm seeing the same code applied 3 times in the line items. If I continue to apply the same code, it will continue to apply and increment the discount. See attachment.

Any help is appreciated. Thank you.

Comments

retiredpro created an issue. See original summary.

retiredpro’s picture

drupal_josh’s picture

This should be bumped to critical. It allows people to get free orders and use a coupon multiple times.

amorsent’s picture

wodenx has just granted me co-maintainer access.

If anyone has a patch I can review and commit.

drupal_josh’s picture

I've been trying to figure this out, but I'm not having much luck. I make a change, but another bug gets introduced.

drupal_josh’s picture

StatusFileSize
new447 bytes

Finally got it figured out! The problem was the cache. Since different codes from a bulk coupon are technically the same entity, the runtime cache was returning the same object for both codes. And since objects are passed by reference by default in PHP, the object would end up getting modified throughout the code and the`$coupon->code` would end up getting changed and not matching the actual coupon code we were working on... resulting in this bug.

The simplest fix was to return a new object per code.

This also fixes an issue where the coupon pane and the order summary pane would only show one of the coupon codes.

Here's the patch
https://www.drupal.org/files/issues/2021-01-19/fix-bulk-coupon-bug-31064...

@amorsent, can you review and commit, please?
I don't foresee any issues since all that is really happening is it's bypassing the runtime cache and hitting the db again.

  • amorsent committed 66d5333 on 7.x-3.x
    git commit -m 'Issue #3106427 by drupal_josh, retiredpro: Bulk coupon...
amorsent’s picture

Status: Active » Fixed

Makes sense to me. I've committed your fix. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.