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