Ok, here is what I've come up with. I'm totally new to php programming, and zen cart programming, so I'm basically just copying what I've seen elsewhere, with changes based on a little browsing of the wiki. I may be barking up the wrong tree entirely. If there's a better way to do this, please point me to it.
I've modified function in_cart_mixed_discount_quantity in file includes/classes/shopping_cart.php. I've changed
PHP Code:
// compute total quantity regardless of attributes
$in_cart_mixed_qty_discount_quantity = 0;
$chk_products_id= zen_get_prid($products_id);
// reset($this->contents); // breaks cart
$check_contents = $this->contents;
while (list($products_id, ) = each($check_contents)) {
$test_id = zen_get_prid($products_id);
if ($test_id == $chk_products_id) {
$in_cart_mixed_qty_discount_quantity += $check_contents[$products_id]['qty'];
}
}
to:
PHP Code:
// compute total quantity regardless of attributes
$in_cart_mixed_qty_discount_quantity = 0;
//!! $chk_products_id= zen_get_prid($products_id);
$product = $db->Execute("select products_id, master_categories_id from " . TABLE_PRODUCTS . " where products_id='" . zen_get_prid($products_id) . "' limit 1");
$chk_products_id= $product->fields['master_categories_id'];
// reset($this->contents); // breaks cart
$check_contents = $this->contents;
reset($check_contents);
while (list($products_id, ) = each($check_contents)) {
//!! $test_id = zen_get_prid($products_id);
$product = $db->Execute("select products_id, master_categories_id from " . TABLE_PRODUCTS . " where products_id='" . zen_get_prid($products_id) . "' limit 1");
$test_id= $product->fields['master_categories_id'];
if ($test_id == $chk_products_id) {
$in_cart_mixed_qty_discount_quantity += $check_contents[$products_id]['qty'];
}
}
I've changed the count from products with the same id to products with the same master category id. It seems to work. I realize that it will only combine totals if the product has "Discount Qty Applies to Mixed Attributes" set to "yes", but I think that may be a good thing. If there's a product that I don't want to combine, all I have to do is change that setting to "No".
Since it's checking the master category id, I think it will combine linked products based on the primary category, not the category that the customer used to navigate to them. Again, I think that's a good thing. It allows me to set up a category for products with combined discounts, and other categories that link those products for easier navigation.
I'm slightly concerned that counting this way may result in quantity totals that exceed a product's maximum purchase quantity, but I don't see where that causes any problem.
Again, I'm new at this, so I've probably overlooked something. If I missed any important points, or if there's a better way to do this, please let me know. I welcome any feedback.
Regards,
Eric
Bookmarks