From 2753ca3b6a2edc50fe7a238908bf3eef302274ec Mon Sep 17 00:00:00 2001
From: mike holloway <mike@dimension-associates.co.uk>
Date: Mon, 19 Sep 2011 22:00:38 +0100
Subject: [PATCH] Issue #1181998: fix buy X get Y free when for any X

---
 uc_discounts/uc_discounts.module |    5 +++++
 1 files changed, 5 insertions(+), 0 deletions(-)

diff --git a/uc_discounts/uc_discounts.module b/uc_discounts/uc_discounts.module
index 22ef992..332792f 100644
--- a/uc_discounts/uc_discounts.module
+++ b/uc_discounts/uc_discounts.module
@@ -1604,6 +1604,11 @@ function get_discounts_for_order($order, &$errors = NULL, &$warnings = NULL, &$m
 
     switch ($discount->discount_type) {
       case DISCOUNT_TYPE_FREE_ITEMS:
+        //With buy X get Y free, apply discount to groups of X products not every product. 
+        if ($discount->qualifying_amount != 0) {
+          $discount->times_applied = (int)($discount_products_qty / $discount->qualifying_amount);
+        }
+
         //The variable discount_amount is the monitary amount of discount
         $discount_amount = 0;
 
-- 
1.7.0.4

