How to calculate a product with multiple discount applied ?

I have setup two discounts.
One for new product identify by a taxonomy tag 'NEW' say 10% off
One for registered member by role say 5% off

For instance, if a product cost $220
There will be two calculation method

1. {220-(220 x 0.1)}( 1 - 0.05) = $188.1

2. 220-((220x0.1) + (220x0.05)) = $187

Small amount may not significant but large amount.

Which one is more common sense ?

This module will use method 2 for multiple discounts applied on a product.

I asked some of my friends, multiple discount should be method 2

CommentFileSizeAuthor
#8 Snap1.jpg13.46 KBadrianmak
#8 Snap2.jpg21.36 KBadrianmak
#5 Snap1.jpg53.27 KBadrianmak
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ryangroe’s picture

I need to rewrite some of the discount calculation code. In my opinion all discounts should calculate in order and have knowledge of one another. So "10% weight 1" will take effect before "5% weight 2" and you will get a total discount of 14.5%. The eventual implementation will ensure that no single item can be discounted more than 100%. This rationale is also in response to http://drupal.org/node/384844. When dealing with non-percent discounts and discounts that don't apply to the basket as a whole I think #1 makes more sense.

adrianmak’s picture

My typo, the last word should be......

I asked some of my friends, multiple discount should be method 1

Waiting for ur new calculation code as my client did ask me, calculation on multiple discount looks not properly.

ryangroe’s picture

I've tested percent off discounts quite a bit. There are still some issues with discounts that don't apply to all products in the cart. I am about make a new release (beta 30) with a small change for ARay (http://drupal.org/node/447102). It works as described below.

Percent off discounts apply one at a time (#1 in your post) UNLESS the weight is the same. If percent off discounts have the same weight and products, both discounts apply based on the same subtotal (see below).

On my site I have this (all discounts can be combined, all discounts apply to all products):
discount A: 10% off weight = 1
discount B: 10% off weight = 1
discount C: 10% off weight = 2

Order subtotal: 70

with discount A:
70 - 7 = 63

with discount B:
70 - 7 = 63

with discount C:
70 - 7 = 63, (7 = 70 * 10%)

with discount A and B (same weight, so discounts get applied together):
70 - 14 = 56, (14 = 70 * 10% + 70 * 10%)

with discount A and C (different weights, so discounts get combined one at a time):
70 - 13.30 (7 + 6.30) = 56.70, (13.30 = 70 * 10% + 63 * 10%)

with discount B and C (different weights, so discounts get combined one at a time):
70 - 13.30 (7 + 6.30) = 56.70, (13.30 = 70 * 10% + 63 * 10%)

with discount A, B and C:
70 - 19.60 (7 + 7 + 5.60) = 50.40, (19.60 = 70 * 10% + 70 * 10% + 56 * 10%)

adrianmak’s picture

ryangroe,

Great to hear this update. I will try immediately.
I think my client should be happy with the correct discount calculation.

adrianmak’s picture

FileSize
53.27 KB

update.
updated to beta31, but it seems not work on me ><

Discount A : 10% off, filter by term - 'new', can combined with other discounts, wieght 0
Discount B : 5% off , filter by term - 'new' and filter based on roles -'authenticated user', can combined with other discounts, wieght 0

Order total, 148
with discount A and B,

148- 22.2 ( 14.8 + 7.4) = 125.8 , (22.2 = 148 * 10% + 148 * 5%)

Why discount B is filter based on roles too, because this discount will be applied for registered member only.

ryangroe’s picture

I think this is the expected behavior. The discounts have the same weight and apply to the same products, so they both are calculated based on 148. The two discounts effectively calculate as the same time. If the weights were different one would be calculated before the other.

The behavior of two discounts with the same weight had been undefined. Beta 31 established the behavior when both discounts are "percent off" and apply to the same products.

adrianmak’s picture

I tried set Discount B to weight 5, Discount A keep it on weight 0

But the Discount B still base on the order total.

However it Discount B is filter by product - All product, (no matter weight is same or greater than Discount B), the calculation is work properly.

Then is it shown that some issue on filter by terms ?

There are two set of products , new and on sales product and using two taxonomy term to classify it is a new or on sales product. So I have to filter by term instead of by product.

adrianmak’s picture

FileSize
21.36 KB
13.46 KB

Here are the product node edit form for classification new product or a on sales product.

Is it related to taxonomy issue if a product node has more than one taxonomy terms.

that0n3guy’s picture

I know this is almost 2 years old, but I have this issue.

I need the first discount to go like normal. But the second discount to go off the discounted total.

So if the item is $1000.
Discount1 = $400
new total = $600

Discount 2 = 30% .... 600x(1-.3)=$180
new total should be = 420

The current way is like:
Discount1 = $400
new total = $600

Discount 2 = 30% .... 1000x(1-.3)=$300
new total should be = 300

In my case this is a BIG difference, not just a couple dollars.

that0n3guy’s picture

After looking at the code, I see that to do something like this my "discount2" needs to be set to "all products" for this to work. Kinda odd, whats the logic behind this?

timmetj’s picture

I am having trouble with the calculation of the discount per product.

In this module the only function that looks like doing this is: get_codeless_discounts_for_product()

But this function return a total of all available discounts, and not the exact discount per order.

Example:
- You got discount1: Fixed amount off : 20€ (here you must select a filter type, and total order isnt in it so you choose all products)
- when I now buy 3 products(1: 10€, 2: 30€, 3:40€) = total 80€
- discount -30€ = 50€

This whole part works nice if you only work with total amounts.
But the problem is that I want to know the discount price for all products.

So when i use get_codeless_discounts_for_product() function, this returns me all the products but under "discount amount" it shows 30€ for ALL products. (wich will make 90€ total discount).

The calculation that needed it to be was:
Product1: {10€(product price) / 80€(total order price)}*30€(total discount price) = 3,75€
Product2: {30€(product price) / 80€(total order price)}*30€(total discount price) = 11,75€
Product3: {40€(product price) / 80€(total order price)}*30€(total discount price) = 15€

This only one example, but has to only works with all disocunt types. To calcutale the exact product discount price for that order. Also depending ofcourse what discounts apply to the product.

To give it a start the uc_coupon module looks like doing the good calculation using the uc_coupon_calculate_discounts() function.

I realy hope some more are having this issue and somebody can try and get the calculations right :)

timmetj’s picture

Version: 6.x-1.0-beta28 » 6.x-2.2