If a discount is created for Buy X product, get Y free, and then that discount is combined with a discount for 5% off your order, if the 5% discount is set to filter by SKU, Term, or Class, the discount is calculated with all products, including the free ones.

For example, the first discount is buy 10 get 2 free, and the product is $10 each. The second discount, with a heavier weight, is 5% off your order of at least $100.

The discounts should be $20 in free products, and $5 (5% off $100) off the order. Instead it comes in as $20 in free products and $6 (5% off $120) off.

If the 5% discount it set to filter by products, the weighting and discounts work correctly. If the 5% is lighter than Buy 10 Get 2 Free, then it is $6 off. If it is heavier it is $5 off.

This behavior occurs whether or not the discount is configured to apply only to discounted items.

CommentFileSizeAuthor
#1 uc_discounts.module.patch2.09 KBAnonymous (not verified)

Comments

Anonymous’s picture

Title: Combined discounts do not apply properly when filtered by SKU, Term or Class » Discounts do not apply only to eligible products when filtered by SKU, Term or Class
Status: Active » Needs review
StatusFileSize
new2.09 KB

I have a similar, simpler problem which I think has the same cause (apologies if not, and I'll start a new issue).

Essentially, 'Calculate the order subtotal using only discounted products' doesn't work when filtered by SKU, Term or Class. This means that discounts are applied to ALL products in the cart and not just eligible ones.

It looks like a simple coding oversight (patch attached). This solves my problem, but please can someone who knows the code check it won't cause other problems.

ferrangil’s picture

I just upgraded uc_discounts_alt and some other modules and I'm having the same problem.
I have some products that have a 5% off, but others not.
The discount is applied to all products on the cart. If I just leave a product which is not selected for the 5%off, then the discount is not applied.
I'll try the patch and report back.
UPDATE: The patch made my site all white, so it's not working for me.

Anonymous’s picture

If you've whited-out, you probably have some sort of php error. Try putting:

error_reporting(E_ALL);
ini_set('display_errors', '1');

in your settings.php file and you should find the problem.

It's the first time I've done a git-style patch, so perhaps I got something wrong.

Anonymous’s picture

#2 - any more info on this? I can't do anything with "it doesn't work" since it does work for me. What's the php error?

jrust’s picture

Status: Needs review » Fixed

Thanks, patch committed.

DanGarthwaite’s picture

@imonemus

Thank you.

ferrangil’s picture

Sorry for not replying @imonemus. Great to see it commited.

ferrangil’s picture

It is working just great. Just updated the live server with drush. No problems at all. Thanks!

timmetj’s picture

I have also changes the "TRUE" to "$exclude_all_products" in all cases in the function get_product_ids_for_discount_object()
But this gives me an error if you choose "all SKU/CLASS/TERMS".

And also doesn't work when selecting one option. This will keep the same problem counting the discount of all products instead of first calculating the free product off.

I have tested this in the 6.x-2.2 version. since it was only changing a little i thought this might work.

When selecting "all" it gives me this errors:

Warning: in_array() expects parameter 2 to be array, null given in get_discounts_for_order()
and
Warning: array_intersect(): Argument #1 is not an array in get_discounts_for_order()
and
Warning: Invalid argument supplied for foreach() in get_discounts_for_order()

Status: Fixed » Closed (fixed)

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