Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Join Date
    Jun 2007
    Location
    Bronx, New York, United States
    Posts
    521
    Plugin Contributions
    3

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

    (Yes this could go to the TaxCloud thread but I figured this could be asked separately.)

    Currently I'm working with a sales tax add-on that processes the items that I send to their server and then in return they send the total amount of sales tax back to me (my server).

    What I noticed is that the orders are being sent with the total $products['final_total'] as the line-item total. A problem that I'm having is that the orders aren't being processed with any discounts applied to them. I would like to know if there is any way to go through an order and apply a discount as needed or where can I find the logic that does this currently within Zen-Cart?

  2. #2
    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

    Okay here's a better question, is there a better way to retrieve the $od_amount['total'] or rather the total amount of the discount from the active order? I know on the coupon module, the value is stored in the $od_amount['total'] variable. But I would like to know if there is a way to refer to this value (sans of assigning it to a variable in $_SESSION.

  3. #3
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

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

    What about the part that sends the value to the taxer, using the difference between the two values provided that the final value is >= 0? Is that how it works/a possibility?

    Stated because it sounds like you have found the two parts needed, the final price (before discounts) and the function/variable that contains the discount. Now would just need to send the desired taxable amount to be processed. Unless there is some other method of determination being searched?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  4. #4
    Join Date
    Jul 2012
    Posts
    16,733
    Plugin Contributions
    17

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

    Alternatively, could modify the total price variable prior to going out and restore it upon return depending on what is trying to be attempted. I somewhat think it comes down to the desired math and how the data is used downstream of being collected/modified.

    Another thing to consider that is often seen related to "coupons" is that the purchaser may still be responsible for the taxes before the discount is applied. Not sure if that aspect is locality dependent or. Just a way to cover ones bases. :)
    Last edited by mc12345678; 7 Jun 2014 at 10:36 PM.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  5. #5
    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 mc12345678 View Post
    Alternatively, could modify the total price variable prior to going out and restore it upon return depending on what is trying to be attempted. I somewhat think it comes down to the desired math and how the data is used downstream of being collected/modified.

    Another thing to consider that is often seen related to "coupons" is that the purchaser may still be responsible for the taxes before the discount is applied. Not sure if that aspect is locality dependent or. Just a way to cover ones bases. :)
    That's essentially what I'm trying to do. The way the TaxCloud module works is that it takes the items from the cart to be processed (on a line by line basis) and processes it against their server. The server then returns a line by line tax total for each and the module on ZenCart tallies these and reports it back as a single line. I know where in the module the TaxCloud module where the module actually builds the XML to send via SOAP processing and I know the exact line of code where I can modify the total of the item.

    So essentially what I have to do (or what I would like to do) is take the total amount of the discount, unless its a shipping-based discount, and divide the discount up into each of the line-item totals of the order as its being processed. This way the line-item gets processed with the discount applied against it. (As Sales Tax (at least in the US) has to be applied to the discount taxed line-item.)

    So the walk through would be:

    - See if the $_SESSION['cc_id'] is not empty.
    - If it is empty, do nothing else. (There is no discount to apply.)
    - If it is not, then compute the discount or retrieve the amount of the discount from the order totals module and retrieve the ot_coupon's "value" property. Find the total number of items (or rather line-items) that exists in the order. Divide the discount into this amount and then apply it to the price being sent to the TaxCloud server being processed.

    The only problem is, I don't know how to reproduce to call the functions that process coupons without applying the discount to all items, even those which I may not be applying the discount to.

    Secondly, with regards to being due on tax for coupons, in my jurisdiction, the coupons are processed before determining the final total to be taxed.

  6. #6
    Join Date
    Jun 2003
    Location
    Newcastle UK
    Posts
    2,896
    Blog Entries
    2
    Plugin Contributions
    2

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

    Hi.

    Just wondering if you are over thinking things here.
    Given I have no real knowledge of how Tax Cloud works.

    However I would have expected Tax Cloud (while it may calculate final prices etc.) to return an effective tax rate for a given product
    surely this is all you need then just let Zen Cart do the rest.

  7. #7
    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 wilt View Post
    Hi.

    Just wondering if you are over thinking things here.
    Given I have no real knowledge of how Tax Cloud works.

    However I would have expected Tax Cloud (while it may calculate final prices etc.) to return an effective tax rate for a given product
    surely this is all you need then just let Zen Cart do the rest.
    That's the thing though, I would thought that TaxCloud would return proper tax rates and such, which it does. However using any coupons, particularly in my jurisdiction, causes me to collect too much sales tax at the time. I'm fine with return pennies and such but besides the fact that PayPal will outright lynch me and the additional fact that it would create reporting problems with TaxCloud, it's something I'd rather work outright.

  8. #8
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

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

    If I understand you correctly, I believe you said you're wanting to recalculate each line by pre-applying coupons before taxes.

    1. I'm mindful that some jurisdictions require merchants to assess tax on the sale price *before* applying discounts, so that the feds get as much tax money as possible. I just mention this not as a contradiction, but to encourage you to double-check your facts to be sure you're heading in the right direction.

    2. Are all your coupons "restricted to a specific product"? Or are all your coupons "applied to the entire shopping cart"? I ask because both cases require careful coding consideration. This is a pretty important component of what you're proposing.

    3. And of course you did mention casual awareness of the penny-rounding problems that will be created by applying discounts at a line-item level, thus requiring a complete recalculation of all totals and subtotals ... but your coding changes will need to take that into account too, else you won't be able to submit your order for payment if subtotals don't add up correctly.
    .

    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.

  9. #9
    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 DrByte View Post
    If I understand you correctly, I believe you said you're wanting to recalculate each line by pre-applying coupons before taxes.

    1. I'm mindful that some jurisdictions require merchants to assess tax on the sale price *before* applying discounts, so that the feds get as much tax money as possible. I just mention this not as a contradiction, but to encourage you to double-check your facts to be sure you're heading in the right direction.
    Well I completely understand that in some jurisdictions it must be noted that tax must be computed before AND after discounts are applied. However, I'm more or less trying to conform to the Developer Guidelines of the mod. According to the developer guide, since TaxCloud doesn't natively support discounts/promotions/etc., discounts have to be calculated on a pre-tax basis. I can't change the way their server computes it.

    The way the calculation is done with the mod from Zencart:

    - Customer builds an order.
    - Customer approaches and lands on the checkout_payment page where an initial sales tax is to be computed.
    - TaxCloud will take the order of the customer, send it to the TaxCloud server, compute the tax on their server based on the information of the order and the settings of the account (where the customer is being billed, order is shipped to, and whether I elected to collect tax in that jurisdiction), send back to ZenCart the total amount of tax computer.
    - Customer then proceeds to enter a coupon code and/or select a payment method.
    - Customer confirms the order. TaxCloud will lock in that order and capture it for reporting purposes.

    Quote Originally Posted by DrByte View Post
    2. Are all your coupons "restricted to a specific product"? Or are all your coupons "applied to the entire shopping cart"? I ask because both cases require careful coding consideration. This is a pretty important component of what you're proposing.
    In my case, since I'm trying to modify their code to be a one-size fits all for everyone, the coupons type doesn't matter. If a coupon is made to affect a certain line or the entire order, I still have to take the entirety of the discount and divide it into the order OR find a way to make the discount calculation apply only to the line-item. The question I wrote regarding line-items makes it so that if a coupon is to affect ONE item, I have to calculate it for that ONE item. (It gets more complicated when I add in the fact that I have mods like table discounts to work this out with.)

    Quote Originally Posted by DrByte View Post
    3. And of course you did mention casual awareness of the penny-rounding problems that will be created by applying discounts at a line-item level, thus requiring a complete recalculation of all totals and subtotals ... but your coding changes will need to take that into account too, else you won't be able to submit your order for payment if subtotals don't add up correctly.
    I was under the assumption that the native discount coupon in ZenCart does that. In short, I should only be affecting just the calculation of the TaxCloud's order_total entry and nothing else.

  10. #10
    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

    By the way, I've done the research on my jurisdiction (New York) and it is indeed true that sales tax must be calculated on the total AFTER the discount is removed.

 

 
Page 1 of 2 12 LastLast

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