PDA

View Full Version : 3 for 2 discount on specific product.


CraigR
04-16-2009, 12:07 AM
My client would like to offer 3 for 2 discount on a specific product type (only), so that when 3 items of a certain ItemTypeID are in the cart, either a 33% discount or (preferably) the cheapest of the 3 items is free.

The calculation should allow for groups of 3 items, so that if 4 or 5 items (of this ItemTypeID) are in the cart, the discount will apply so that the customer doesn't save 1/3 off the whole cart, but 1/3 off the 3 items, (or multiple of 3 items)

The ultimate ambition is a formula where i can plug in different variables to allow for 2 for 1, 4 for 3 etc.

I am using a dynamic cart with php and DW CS4, latest version of ecart

On paper, i calculated some scenarios for up to 6 items and their prices
The calculations are based upon the best discount possible

Item1 = 10
Item2 = 12
Item3 = 11
Item4 = 20
Item5 = 18
Item6 = 25

Items 1-3 in cart, total price = (10+12+11) - (10) = 23
Items 1-4 in cart, total price = (10+12+11+20) - (11) = 42
Items 1-5 in cart, total price = (10+12+11+20+18) - (12) = 59
Items 1-6 in cart, total price = (10+12+11+20+18+25) - (18+10) = 68


but would appreciate some advice on the next steps...

Ray Borduin
04-16-2009, 08:47 AM
What is your server language. This can be done, but because of the complexity it would probably require some hand scripting in the language you are using.

I would probably write a function to handle it and then write a calculation that refers to that function.

Does it need to account for quantity as well... for instance if you buy two of item1 and one of item2 would you get $10 off? You would need to account for all of this in your calculation.

CraigR
04-16-2009, 09:21 AM
Hi Ray.

I am using php.
I am quite comfortable with hand coding, but have only been using php for about 6 months, (asp before this).

i also want to adopt the best approach wrt ecart

re your question, 3 for 2 would apply to any combination. even 3 of the same item.

Ray Borduin
04-16-2009, 09:39 AM
You would need to write the function by hand.

I would write it in the ecart definition include file so you won't have to add the function to every page manually.

Save a backup of the function since the place where I am having you write it would be rewritten any time you update your cart object.

Then you just need to write the function to perform the logic. PHP is exactly like asp, so the logic is identical and the syntax is only slightly different. The main difference is the function library which is documented well at http://www.php.net.

CraigR
05-08-2009, 09:53 AM
I have managed to create 3 for 2 (or 4 for 3) or n for n-1 discount, where items are in the same product category, (and only if they are in this category).

With only a little bit of extra hand coding, I have linked the variables with the database so the client can change the product category, date parameters, voucher password etc.

If you are comfortable with creating and manipulating arrays in php, it is fairly straightforward

If you are interested, drop me a line and i will post a 'how-to' guide.