# discount difficulty

Thread began 6/01/2011 4:27 pm by CraigR | Last modified 6/08/2011 4:12 pm by Jason Byrnes | 1602 views | 16 replies |

## 6/01/2011 4:27 pm  |  #1 CraigRBeta Tester

### discount difficulty

Not sure where to go with this.

My client has a huge number of SKU&#8217;s, each of which may have a discount, depending on order quantity.
Eg 1-9, 10-49, 50-100
My initial approach was to evaluate the discount based on product category, (each category has a different level of discount ) and apply different discount bands accordingly.
One example would be

Number of Items with DiscountGroup of A >= 10
AND Number of Items with DiscountGroup of A< =49

Calculation Based on Items with a specific value,
Total of TotalPrice where DiscountGroup has a Value of A times (my variable)

This works, but in a cumulative fashion,
ie 2 separate products in discount group A, each with 6 units, will give 12 units and apply the discount.

The desired result is now to ignore the grouping for the trigger, so that each product is dealt with separately.
So that If I have 6 of Item 1 and 6 of item 2, no discount is applicable.

Hope this makes sense.
Please advise a way in to deal with this, I have a mental block.
The discount group approach works as it gives me a lot of flexibility, and with a reasonable number of discount rules, but I can&#8217;t have a different rule for every sku !!

## 6/01/2011 4:48 pm  |  #2 Jason ByrnesWebAssist

when you need to apply a discount at the line item level, it is time to use the eCart calculations tab.

if the breaks will all be the same, i.e 1-9, 10-49 etc, you will just need a column for each discount amount (you can get really crazy though and set the quantity breaks on an item by item basis by adding a low high column for each quantity level).

For this example, lets say the discount breaks are 1-9, 10-49, 50-100. you would need to add 4 new columns to the cart discAmountA - this is the amount of discount for 1-9, discAmountB - this is the amount of discount for 10 - 49 etc...

you can then create a new calculation of:
name: itemDiscount

(abs([DiscountGroup] == 'A' && ([Quantity] >= '1' && [Quantity] <= '9'))*[discAmountA]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= '10' && [Quantity] <= '49'))*[discAmountB]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= '50' && [Quantity] <= '100'))*[discAmountC]) * [Quantity]

then on the discount tab, set the discount to be subtotal of column 'itemDiscount'

## 6/01/2011 5:01 pm  |  #3 CraigRBeta Tester

My scenario is quite complex, the price breaks not only differ by product category, but they also differ depending on the customer logged in.

I will digest your reply fully tomorrow morning, (late here in the UK) and let you know how I get on

## 6/02/2011 4:31 am  |  #4 CraigRBeta Tester

### Getting there.

I started off simply until I got this working as intended.

Discount1to9; Discount10to49; Discount50to100

I added the calculation field as described

((abs([DiscountGroup] == 'A' && ([Quantity] >= '1' && [Quantity] <= '9'))*[Discount1to9]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= '10' && [Quantity] <= '49'))*[Discount10to49]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= '50' && [Quantity] <= '100'))*[Discount50to100])) * [Quantity]

On my add to cart page, for testing purposes, I have set the discounts for each quantity break to 10% 20% and 30%

To start with, I have added a new discount rule, whose calculation is the subtotal of column 'itemDiscount'.
As the trigger, I have set ‘Total Number of Items > 0’.
This seems to give me the desired result.

With Discount group A items… If I add 10 of Item 1 and 5 of item 2, my discount calculates as 20% of Item 1 and 10% of item 2
I can even put the discount amount in line with each cart item – great.
(I assume by this method, I will only ever get one line under the discounts section, so in order to have some clarity re the discount applied, I need to use the inline method I mentioned above)

I now need to take this 2 stages further.
1. Include Discount Group B, C, D etc in the calculation field
2. Set different price breaks for each Discount Group.

I presume, to achieve stage 1, I just extend the calculation as follows…

((abs([DiscountGroup] == 'A' && ([Quantity] >= '1' && [Quantity] <= '9'))*[Discount1to9]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= '10' && [Quantity] <= '49'))*[Discount10to49]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= '50' && [Quantity] <= '100'))*[Discount50to99]) + (abs([DiscountGroup] == 'B' && ([Quantity] >= '1' && [Quantity] <= '9'))*[Discount1to9]) + (abs([DiscountGroup] == 'B' && ([Quantity] >= '10' && [Quantity] <= '49'))*[Discount10to49]) + (abs([DiscountGroup] == 'B' && ([Quantity] >= '50' && [Quantity] <= '100'))*[Discount50to99]) + (abs([DiscountGroup] == 'C' && ([Quantity] >= '1' && [Quantity] <= '9'))*[Discount1to9]) + (abs([DiscountGroup] == 'C' && ([Quantity] >= '10' && [Quantity] <= '49'))*[Discount10to49]) + (abs([DiscountGroup] == 'C' && ([Quantity] >= '50' && [Quantity] <= '100'))*[Discount50to99]) + (abs([DiscountGroup] == 'D' && ([Quantity] >= '1' && [Quantity] <= '9'))*[Discount1to9]) + (abs([DiscountGroup] == 'D' && ([Quantity] >= '10' && [Quantity] <= '49'))*[Discount10to49]) + (abs([DiscountGroup] == 'D' && ([Quantity] >= '50' && [Quantity] <= '100'))*[Discount50to99])) * [Quantity]

…to include all Discount Groups.

Can you please elaborate on how I could achieve what you stated in your email

…(you can get really crazy though and set the quantity breaks on an item by item basis by adding a low high column for each quantity level). Using an example where the price breaks for Discount group A were as before, (1-9, 10-49, 50-100) and the price breaks for Discount Group B are 10-24, 25-100, 101-999)

## 6/02/2011 10:05 am  |  #5 Jason ByrnesWebAssist

yup, your on the right track with modifying the calculation for the different groups.

to set the quantity breaks on an item by item basis, you would add extra columns to cart, for example:

qtyALow
qtyAHigh
qtyBLow
qtyBHigh
qtyCLow
qtyCHigh

in the add to cart button you set the qty breaks by the values given to these columns, for example:
qtyALow = 1
qtyAHigh = 9
qtyBLow = 10
qtyBHigh = 49
qtyCLow = 50
qtyCHigh = 100

instead of hard coding the values in the calculation, refer to the quantity break columns:

((abs([DiscountGroup] == 'A' && ([Quantity] >= [qtyALow] && [Quantity] <= [qtyAHigh]))*[Discount1to9]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= [qtyBLow] && [Quantity] <= [qtyBHigh]))*[Discount10to49]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= [qtyCLow] && [Quantity] <= [qtyCHigh]))*[Discount50to100])) * [Quantity]

## 6/02/2011 1:15 pm  |  #6 CraigRBeta Tester

Thanks again Jason.

Getting the hang of it !

you're welcome.

## 6/08/2011 1:38 am  |  #8 CraigRBeta Tester

Thanks for your help on this one Jason.

I now have a very long calculation to deal with all of the potential options, but it works extremely well.

To tie it all up I have one further question.

The above calculation works by using the sessionid of the user, in order to determine their discount entitlement

My scenario is that many customers will be part way through their shopping process, when they realise they haven't yet logged in, and therefore not getting the discounts to which they are entitled.

Can you think of a way of updating the cart array 'after the fact' ?

The first part of the calculation is as follows, (there are 36 Discount groups, but the structure is the same throughout)...

((abs([DiscountGroup] == 'A' && ([Quantity] >= [DiscountAMin] && [Quantity] <= [DiscountAMax]))* [DiscountBandA]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= [DiscountBMin] && [Quantity] <= [DiscountBMax]))* [DiscountBandB]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= [DiscountCMin] && [Quantity] <= [DiscountCMax]))* [DiscountBandC]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= [DiscountDMin] && [Quantity] <= [DiscountDMax]))* [DiscountBandD]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= [DiscountEMin] && [Quantity] <= [DiscountEMax]))* [DiscountBandE]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= [DiscountFMin] && [Quantity] <= [DiscountFMax]))* [DiscountBandF]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= [DiscountGMin] && [Quantity] <= [DiscountGMax]))* [DiscountBandG]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= [DiscountHMin] && [Quantity] <= [DiscountHMax]))* [DiscountBandH]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= [DiscountIMin] && [Quantity] <= [DiscountIMax]))* [DiscountBandI]) + (abs([DiscountGroup] == 'A' && ([Quantity] >= [DiscountJMin] && [Quantity] <= [DiscountJMax]))* [DiscountBandJ])....) * [Quantity]

## 6/08/2011 9:48 am  |  #9 Jason ByrnesWebAssist

so in the add to cart button, you are setting the DiscountGroup column to use the session variable?

you have 2 options:
1) Use the session in the calculation instead of the discount group column, for example:
abs(isset(\$_SESSION['DiscountGroup']) && \$_SESSION['DiscountGroup'] == 'A')

2) Create another calculation that sets the DiscountGroup column value to the session:
abs(isset(\$_SESSION['DiscountGroup']))?[DiscountGroup] = \$_SESSION['DiscountGroup']:0

## 6/08/2011 10:02 am  |  #10 CraigRBeta Tester

Something like that.

I use the accountid session variable (id of current login) to identify which discountaccountid to use, (the same discountaccountid may apply to several accounts).

I use this discountaccountid to filter my discount recordset,

When the 'add to cart' is triggered, the discountgroup of the selected item is used in a lookup query, which returns one row, with all of the min/max parameters and associated discounts

I have 36 different discount groups, I suppose once I have filtered my recordset by discountaccountid i could put them into an array, store the array as a session and try to use the array values in my calculation

## Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

## Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

## Everything else!

Close Window

Account or customer service questions?

Need technical support?

Content

Layout

Ease of use

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Window

## We were unable to retrieve the attached file

Close Window

### Attach and remove files

• Text Formatting
• Insert Element
• Block Formatting
• Cancel
Close Window

Close Window

#### This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --