This module is great. It is exactly what I need for a site that I am setting up.
I did find though that in some circumstances discounts do not apply. I set up a discount with a minimum quantity (5) that applies to multiple products and does not require a single product to qualify. It applies properly when I add 5 of one product to the cart or 2 of one and then 3 of another. It does not work when I add 2 of product A and then add 3 more of product A. Resulting in two lines in the cart 2xA and 3xA. Line 790 creates an array of product quantity based upon product ID. Since both of the products in my cart have the same ID only the second quantity is contained in the array. Then on line 1000 when you sum the total amount of products it only picks up the last 3.
In my case product A has multiple attributes and therefor is quite common that someone would have two product As in their cart with different attributes.
Comments
Comment #1
ryangroe commentedSorry for the delay, I hadn't signed up for issue notification so I am just seeing this today.
Thank you so much for the detailed bug report.
Unfortunately since I am not using attributes on my system I'm not completely sure as to the best way to totally fix this. For the line 790 code (in beta 2), I updated the code to add to any existing values in $order_product_id_subtotal_map and $order_product_id_quantity_map. So you should now properly get the quantity 5 in $order_product_id_quantity_map for your product's nid. This works on my system which does not have attributes. I need your help in testing this with attributes.
The part I am unsure about is with $order_product_id_line_item_map and how it relates to discounting free items. As the name implies I use $order_product_id_line_item_map to quickly access products from their IDs (nids). What I believe it should be is an array of product objects that have a particular nid. So that's what I changed it to. There is no impact on my system because all my cart items have unique nids. Again, I need your help in testing this with attributes.
Here's what I did:
1. Store not just one but all products associated with each nid in $order_product_id_line_item_map
Changed:
$order_product_id_line_item_map[$nid] = $product;
To:
$a = $order_product_id_line_item_map[$nid];
if ( !is_array($a)
$a = array();
$a[] = $product;
$order_product_id_line_item_map[$nid] = $a;
2. Loop over all the products in $order_product_id_line_item_map
}Changed:
foreach ($discount_product_ids as $product_id)
{
$product = $order_product_id_line_item_map[$product_id];
To:
$products = array();
foreach ($discount_product_ids as $product_id)
array_merge($products, $order_product_id_line_item_map[$product_id]);
foreach ($products as $product)
{ }
This will be available in beta 3 to be released tonight.
Comment #2
ezra-g commentedThis is committed, so I'm marking it as fixed ;).