Re-sorting Zen Cart Discounting Modules
This article will be of interest to shopowners who are re-calculating tax (using Standard or VAT methods) and who wish to place the Coupon or Group Discounts modules after one of my modules.By default, the built-in Zen Cart Coupon module is designed to sort at order 280, and the Group Discount module is designed to sort at order 290. This means all my modules below will be sorted after these native modules.
- Quantity Discounts for Zen Cart
- Better Together for Zen Cart
- Combination Discounts for Zen Cart
- Big Spender for Zen Cart
- Big Chooser for Zen Cart
- Table Discounts for Zen Cart
- BOGO Discount for Zen Cart
- Manufacturer Discount for Zen Cart
- Free Gift Spender for Zen Cart
- Free Gift Chooser for Zen Cart
First, the default operation. We'll use a Big Chooser deduction which allows you to get a $30 item for free, and a 10% off coupon. Assume a 7% rate of tax, with "Standard" Recalculation. The default mode of operation puts the coupon before my discount as follows:
1 x Hewlett Packard LaserJet 1100Xi Linked | $499.99 |
1 x Blade Runner - Director's Cut Linked | $30.00 |
1 x Disciples: Sacred Lands Linked | $90.00 |
Sub-Total: | $619.99 |
Store Pickup (Walk In): | $0.00 |
Discount Coupon: SAVETEN : | -$62.00 |
Big Chooser Discount: | -$30.00 |
FL TAX 7.0%: | $36.96 |
Total: | $564.95 |
$619.99 - $62 - $30 = $527.99; $527.99 * 0.07 = $36.96. So these numbers look good.
But if we move the coupon to after the Big Chooser discount, the discount changes:
Sub-Total: | $619.99 |
Store Pickup (Walk In): | $0.00 |
Big Chooser Discount: | -$30.00 |
Discount Coupon: SAVETEN : | -$58.79 |
FL TAX 7.0%: | $37.17 |
Total: | $568.37 |
The discount provided by the coupon appears lower than might be expected because the reduced tax is taken into account when computing the discount. This is a bug which only shows up in the situation described (recalculating tax and re-sorting the native discount modules).
One Big Chooser user Oliver Somers suggested that the figures below would be better:
Sub-Total: | $619.99 |
Store Pickup (Walk In): | $0.00 |
Big Chooser Discount: | -$30.00 |
Discount Coupon: SAVETEN : | -$59.00 |
FL TAX 7.0%: | $37.17 |
Total: | $568.16 |
$619.99 - $30 - $59 = $530.99; $530.99 * 0.07 = $37.17.
Fortunately, arriving at these numbers is a simple one line change (which was actually made in Group Discounts and Coupons starting in 1.3.8, but was never added to my modules): in the file
includes/modules/order_total/my-mod-name
in the function process(), after the line
$order->info['total'] = $order->info['total'] - $od_amount['total'];add the line
$order->info['tax'] = $order->info['tax'] - $od_amount['tax'];So you now have
$order->info['total'] = $order->info['total'] - $od_amount['total']; $order->info['tax'] = $order->info['tax'] - $od_amount['tax'];Line numbers for these changes (based on the latest version of these mods, circa Oct. 2012) are:
- Quantity Discounts for Zen Cart - line 165
- Better Together for Zen Cart - line 274
- Combination Discounts for Zen Cart - line 186
- Big Spender for Zen Cart - line 581
- Big Chooser for Zen Cart - line 696 in version 1.2.15 (Fixed in version 1.2.16)
- Table Discounts for Zen Cart - line 243
- BOGO Discount for Zen Cart - line 143
- Manufacturer Discount for Zen Cart - line 57