PrestaShop/PrestaShop — pull request #1873 by peterept (2014-06-07 12:55:13+00:00)
Title: [*] FO/BO: Added Cart Rule Action: Apply a discount to the cheapest selected produc...

...t

background:

This is useful when you want to discount the cheapest product of a category (eg: Ties). Currently the cheapest option applies to the entire cart.

One request for the feature is in this forum thread: http://www.prestashop.com/forums/topic/325571-problem-with-cart-rules

Implementation:

I've added a new action "Cheapest selected product(s)" to the admin screen. If selected it sets reduction_product to a new id of -3 (-1 is "selected" product(s) and -2 is "cheapest" product).

I updated the logic in CartRules.php which is handling the cheapest product logic to also check for "cheapest selected" in which case it ignores any products not in the selected group.

How Tested:
- Verified the admin screen stores the value when "cheapest selected" is picked and saved.
- Verified that the "cheapest seleted" option hides/shows if the percentage option is on/off.
- Verified that the option is disabled if the user has not made a product selection (and a helper link is displayed to prompt them to make a selection)
- Created a cart rules with cheapest selection of a single category:
- item in cart not from category - discount is not applied
- item in cart of category - discount is applied
- item in cart of category - qty 2 - discount is applied to only 1
- items 2 in cart: 1 of category, 1 of other - discount is applied to 1 of category
- items 3 in cart: 2 of cateory different prices, 1 of other - discount is applied to cheapest of the category