I have come up with a way to eliminate some items from a group_discount using the Order Total discount. It requires editing a core file, which I am generally opposed to, but it is working for us, satisfying an important requirement for our store.
I am using Zen Cart v1.5.7c
1. Create a category NO DISCOUNT
2. Make NO DISCOUNT the master category for all items you wish to eliminate from group discounts.
3. Create links of your NO DISCOUNT items to the categories where you want the items to appear.
4. Disable the NO DISCOUNT category so it is not visible to customers, but leave all items in that category Active.
5. In /includes/modules/order_total/ot_group_pricing.php, lines 93, 94 and 95, you will see
Code:
$discount = ($orderTotal['total'] - $gift_vouchers) * $group_discount->fields['group_percentage'] / 100;
// echo "discout = $discount<br>";
$od_amount['total'] = round($discount, 2);
Add this after line 93 and before line 95:
Code:
// Remove NO DISCOUNT items from the discount calculation
$products_in_cart = $_SESSION['cart']->get_product_id_list(); // Get a list of the products_id's that are in the cart
$no_discount_id = $db->Execute("select categories_id from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_name = 'NO DISCOUNT'")->fields['categories_id']; // Get the id of the NO DISCOUNT category
$prod_ids = explode(',', $products_in_cart); // split string returned by get_product_id_list() into array
$discountTotal = $orderTotal['total']; // Assume everything gets a discount
foreach($prod_ids as $this_id) //loop over the products_ids that are in the cart
{
$products_id = strtok($this_id, ':'); // Remove linked item portion of $this_id
$master_categories_id = $db->Execute("select master_categories_id from " . TABLE_PRODUCTS . " where products_id = $products_id")->fields['master_categories_id']; // Get the master_categories_id of this cart item
if ( $master_categories_id == $no_discount_id ) { // This item does not get a discount
$qty_in_cart = $_SESSION['cart']->get_quantity($this_id); // How many of this item are in the cart?
$price = $db->Execute("select products_price from " . TABLE_PRODUCTS . " where products_id = $products_id")->fields['products_price']; // Get the price of this item
$discountTotal = $discountTotal - ($qty_in_cart * $price); // Subtract this item's price from the total amount to be discounted
}
}
// Recalculate the discount without the NO DISCOUNT items
$discount = ($discountTotal - $gift_vouchers) * $group_discount->fields['group_percentage'] / 100;
Bookmarks