Calculating Discount - Buy Two Get Another Free

Thread began 11/20/2019 9:48 am by Me | Last modified 11/21/2019 9:04 am by Ray Borduin | 164 views | 5 replies |

11/20/2019 9:48 am  |  #1 Me

Calculating Discount - Buy Two Get Another Free

I am scratching my head on this...its not as simple as it first appears.

I can easily calculate if there are three of the same item in the cart and then discount (in cash) the amount equal to the cost of one of them.

For example: Say Item price is 30.00. The user sticks three (3 x 30.00 = 90.00) in the cart and because then the quantity threshold for this item has been met, it shows in the discounts 30.00...easy so far!

Now, my client has asked me, "what if a customer puts six in the cart", it should give a discount totalling 60.00.

What the client is saying is that "for every 3 of the same item in the cart, it should show a 30.00 discount"

So, if there was (say) 4 or five items of the same in the cart, it would only show a 30.00. Once it hits 6, then show 60.00 discount...again it remains at 60.00 if the customer adds 7 or 8 unless the customer updates the quantity to 9...and so on and so on?

There's probably an easy way to do this...anyone out there got a tip or hint?

11/20/2019 10:04 am  |  #2 Ray BorduinWebAssist

I think you can do this with a custom column in the cart.

You can create a column like: QuantityDiscount = floor([Quantity]/3) * [Price]

Then create the rule to discount the total of the QuantityDiscount column instead of just discounting the 30.00.

Did this help? Tips are appreciated...

11/21/2019 1:03 am  |  #3 Me

They say you should always sleep on it. I woke this morning and realised I was approaching this in completely the wrong way. It was never a programatic code issue, it was a math issue, and so...

([Quantity] > [DiscountUnitThreshold]) ? (floor([Quantity] / ([DiscountUnitThreshold] + 1))) * [DiscountAmount] : ''

I guess its another way of doing what Ray has done with my own columns.

Thanks Ray...I will take a look at your method...it might be a little less code :-)

11/21/2019 7:39 am  |  #4 Ray BorduinWebAssist

You don't need the check in the front or the +1 I don't think. This might be right:

([DiscountUnitThreshold] > 0) ? (floor([Quantity] / ([DiscountUnitThreshold]))) * [DiscountAmount] : 0

Did this help? Tips are appreciated...

11/21/2019 8:47 am  |  #5 Me

The check at the front is to check if the quantity ordered is > than the DiscountUnitThreshold (which is variable for each product)...and yes, I updated the code slightly and I did not need to include +1.

11/21/2019 9:04 am  |  #6 Ray BorduinWebAssist

Yes, but the math will result in zero if the quantity is < the DiscountUnitThreshold anyway, so no need to check. You just need to check that the DiscountUnitThreshold is not zero since you can't divide by zero.

Did this help? Tips are appreciated...

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 --