Hi

My use case is the following : users can apply discounts of 10€ using discount code. Each code can be used only once.

Discount set up is the following :

  • Maximum times applied : 0
  • Max uses : 0
  • Max uses per user : 0
  • Max uses per code : 1
  • Codes created : code1, code2

At checkout (say cart total is 50€), If I enter code1 and code2, only the last code is picked up, hence discounted price is 50-10 = 40€.
It shall be 50-10-10 = 30€.

Thanks for your help

Laurent

Comments

ryangroe’s picture

Are the two codes attached to the same discount? If so, that is the reason for the behavior.

Unfortunately even though you put two codes on the discount it still internally acts as a single discount, which means the module will only apply it once to the cart. To accomplish what you want you will need to copy your discount and add one code to each (the original and copy). You will also need to allow both discounts to be "combined with other discounts".

Agence Web CoherActio’s picture

Thanks for your quick answer.

If I want to use to a single discount to handle this, could you please point me to the functions I'd need to modify? Do you think this would a simple change or a complex one?

Many thanks

Laurent

ryangroe’s picture

I am still using the 1.0 version of the code, so what I say below may be a little out of date.

You will need to update uc_discounts.module's get_discounts_for_order function. Unfortunately the SQL uses a subquery rather than a join to match entered codes and discounts. As a result the easiest thing may be to add a loop for each matched code just beneath the discounts loop (just inside "while ( $discount = db_fetch_object($result) )"). It's a bit crude and would scale as well but may suffice as long as you don't go above a few thousand codes in the system. A permanent solution would be to change the "OR d.discount_id IN( SELECT discount_id FROM {uc_discounts_codes} WHERE code IN(%s) )" block to perform a join instead.

Agence Web CoherActio’s picture

Thanks
I'll do the change over the next few weeks and post the code when done
Laurent

robbertnl’s picture

#4 Laurent can you post your code change?