lhungil:
Clarification:
It sounds like you are currently using an "order total" module to apply discounts against the entire order. This means the customer pays the advertised price for the products and tax on the advertised price. Afterwards you are applying a discount to the customer's order.
It also sounds like you would prefer to apply the discount directly to the products. The business need is to not charge tax on the advertised price, but instead upon the actual price paid for the product.
lhungil:
The 3rd party "tax system" you are using does calculations based upon line items (product and order). Most likely to accommodate the myriad tax rules which may apply. The 3rd party "tax system" also has no way to know what line item (product or order) a discount line should be applied against. Because of this, it is not taking into consideration any "negative" line items (probably as it does not know what to do with them if mixed tax rates may apply to various line items).
Are these accurate?
Correct in all regards. A system limitation of the suite is that you cannot try to process a negative price or Qty through it to perform a discount. Instead, as per their recommendation, the discount needs to be divided across the board to all items. In my case, I'd rather not apply the discount divided into all the items of the order but rather just the line items where the discount applies (if any).
lhungil:
Question:
In addition to coupons, what other discount methods are you using?
There are three discount modules being run: the discount coupons provided with ZenCart, the Rewards Point Suite (there is a percentage discount), and the mod "Table Discounts"
lhungil:
Background:
I believe most (if not all) of the current "order total" modules for Zen Cart apply the discount only at the "order" level. Most of these can (if enabled) directly modify the tax amounts generated by "ot_tax" to apply tax only to the discounted price.
Internally, Zen Cart sales and specials are applied on a product level (and reflected in "final_price").
I looked into the "final_price" of the Cart class. It does work with sales and specials but not so much coupons which is where I'm having the problem with.
lhungil:
Another Potential Solution:
Code a new (or recode an existing) "order total" module to calculate and apply the discounts directly to the products. Then change the sort_order to occur before tax is calculated by the 3rd party tax module.
If a discount is applied based upon multiple products the code would need to account for HOW the discount should be applied. Would it be to just one of the products? Equal discount to all products? Different discount amounts per product? I am guessing this is just a small part of what DrByte was hinting at (item 2).
I ended up going with the equal discount to all products method instead. I'm not trying to find a way instead of the $_SESSION method. I tried to do this with a homebrewed add-on on to the cart object but I don't know how to pass back the value so that its being modified and updated.
lhungil:
Note 1: This was the first solution which entered my mind (there probably are some alternatives). This solution not only can handle discounts known in advance, but also discounts such as coupons applied during checkout. It also avoids needing to modify the core Zen Cart code to accommodate how prices are calculated. However it will probably require some math and an in-depth understanding of the shopping_cart class and order_total modules.
Note 2: It may be worth asking the 3rd party tax service if they have a way to pass "discounts" to their service and let them handle figuring out taxes to ensure taxes are calculated correctly in all jurisdictions which may apply.
In regards to note 2: Unfortunately there is no current way with the tax service to accept discounts. It was in fact their own advice to take the discount and divide it up into all of the lines. I did this by tallying up all the discounts over each of the modules, adding it back to a $_SESSION['order_discounts'] which I unset when the order is completed. Then I totaled up all the Qty's in a cart and made an average, applying that back onto the unit price.
$qtyCart = 0;
$discountperitem = 0;
foreach ($products as $k => $product) {
$qtyCart += $product['qty'];
}
$total_discount = 0;
if(is_array($_SESSION['order_discount'])) {
foreach ($_SESSION['order_discount'] as $ot_discount) {
$total_discount += $ot_discount["value"];
}
}
$total_discount += $_SESSION["cot_gv"];
$discountperitem = ($total_discount) / $qtyCart;
That was in general the best I could do with the situation. This actually works with PayPal and such, so I guess it works. The only thing that worries me about this is if a cart has a taxable and a non-taxable item at the same time.