Page 2 of 2 FirstFirst 12
Results 11 to 14 of 14
  1. #11
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: Obtaining a line-item (product) total after discounts

    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.

    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?

    Question:
    In addition to coupons, what other discount methods are you using?

    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").

    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).

    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.
    Last edited by lhungil; 11 Jun 2014 at 10:15 PM.
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

  2. #12
    Join Date
    Jun 2007
    Location
    Bronx, New York, United States
    Posts
    521
    Plugin Contributions
    3

    Default Re: Obtaining a line-item (product) total after discounts

    Quote Originally Posted by lhungil View Post
    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.

    Quote Originally Posted by lhungil View Post
    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).

    Quote Originally Posted by lhungil View Post
    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"

    Quote Originally Posted by lhungil View Post
    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.

    Quote Originally Posted by lhungil View Post
    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.

    Quote Originally Posted by lhungil View Post
    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.

    PHP Code:
            $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.

  3. #13
    Join Date
    May 2009
    Location
    North Las Vegas, NV
    Posts
    44
    Plugin Contributions
    0

    Default Re: Obtaining a line-item (product) total after discounts

    While not exactly trying to do the same, it is similar enough to what I want to be able to do, which is to calculate and adjust the freeoptions shipping module to base the free shipping on Cart Total AFTER the discounts are applied, not before.

    To do that, I had to figure out a way to get the amount (of the total discount) per discount module (ot_coupon.php) and for the added mod plugin I installed, newsletter discount (ot_newsletter_discount.php) found in the includes/modules/order_total directory.

    Any other discount mods you may have installed should be located here as well. You will need to figure out what is the best method to determine if the discount is active or not. That is why I have the IF - ELSE statements.

    No explanation is necessary if you understand the code below. It works. You just need to figure out where to put it and use it for your purposes. I'm on a tight schedule and when I have more time, I may expand on it further. Or not, lol.

    Code:
    // added this for calculating Adjusted Total AFTER Discounts to base free shipping on,
    // instead of free shipping based on total BEFORE discounts!
    
    if (isset($_SESSION['cc_id'])) {
        $coupon_total = $ot_coupon->calculate_deductions($_SESSION['cart']->show_total());
    } else { $coupon_total['total'] = 0; }
    
    if ($ot_newsletter_discount->is_subscriber()) {
        $nwsltr_total = $ot_newsletter_discount->calculate_deductions();
    } else { $nwsltr_total['total'] = 0; }
    
    $total_discounts = $coupon_total['total'] + $nwsltr_total['total'];
    $adjusted_total = $_SESSION['cart']->show_total() - $total_discounts;
    
    // echo 'Total Discounts = ' . $currencies->format($total_discounts) . '<br>';
    // echo 'Adjusted Total = ' . $currencies->format($adjusted_total);

  4. #14
    Join Date
    Jan 2004
    Posts
    66,364
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: Obtaining a line-item (product) total after discounts

    Or use the commissionable_order value as explained here:
    http://www.zen-cart.com/content.php?...filiates-Tools
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 
Page 2 of 2 FirstFirst 12

Similar Threads

  1. v151 Obtaining Checkout Total Value less deductions from an observer class
    By HeatherScrooby in forum General Questions
    Replies: 1
    Last Post: 8 Jul 2013, 07:05 PM
  2. Discounts on additional items after first item purchase
    By fritzy in forum Setting Up Specials and SaleMaker
    Replies: 1
    Last Post: 5 May 2011, 08:32 AM
  3. Sales tax showing in total, but not as line item
    By brihod in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 1
    Last Post: 3 Aug 2010, 04:52 AM
  4. remove item line total
    By gnuzoo in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 9 Jan 2009, 03:52 PM
  5. Giving Discounts after total order is over a certain amount
    By medcop2000 in forum Setting Up Specials and SaleMaker
    Replies: 9
    Last Post: 5 Jun 2006, 04:02 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR