Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 22
  1. #11
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    123
    Plugin Contributions
    5

    Default Re: Discount coupon value

    I updated ot_coupon.php file. Calculations for both 'Discount coupon' and 'Credit note' are supported for different type of coupons.
    'Discount coupon' are discounts applied on customer order, which mean they are calculated on net prices.
    'Credit note' are generally used for refunds and are calculated on products or order gross price.
    'Penny loss' problem appeared but was solved by applying a rounding on coupon value just before it is included in order total.
    There are still lots of testing/fixing with discount per item option, multiple tax class items in cart, coupon validation in general...

  2. #12
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,497
    Plugin Contributions
    88

    Default Re: Discount coupon value

    Quote Originally Posted by pilou2 View Post
    I updated ot_coupon.php file. Calculations for both 'Discount coupon' and 'Credit note' are supported for different type of coupons.
    'Discount coupon' are discounts applied on customer order, which mean they are calculated on net prices.
    'Credit note' are generally used for refunds and are calculated on products or order gross price.
    'Penny loss' problem appeared but was solved by applying a rounding on coupon value just before it is included in order total.
    There are still lots of testing/fixing with discount per item option, multiple tax class items in cart, coupon validation in general...
    Thanks, @pilou2. I'll check it out early next week.

  3. #13
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    123
    Plugin Contributions
    5

    Default Re: Discount coupon value

    Quote Originally Posted by lat9 View Post
    Thanks, @pilou2. I'll check it out early next week.
    Wait until next update, I realized there were some mistakes. I did not upload the right version and anyway, now that I am testing with multiple tax rates, I need to rewrite part of the code.

  4. #14
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    123
    Plugin Contributions
    5

    Default Re: Discount coupon value

    Last update uploaded to GitHub.
    Results look very good. ;)
    Discount coupons should be ok with all coupons options.
    Credit notes (refund) too with all usable options. When using credit notes, setting in admin for ot_coupon are important. Some settings should not be used, like setting tax class to 'none'. Always choose a tax class, or total tax won't be right.
    I did some testing with products in cart using two different tax classes and all numbers added well, although calculation to check numbers can get pretty complicated.

  5. #15
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    123
    Plugin Contributions
    5

    Default Re: Discount coupon value

    Well... I did all my testing, modifications using a shipping module with tax class set and when I removed this tax class, problems appeared.
    I have to rethink everything as I made two assumptions that were wrong:
    I thought option 'include shipping' and 'include tax' were here just to choose the limit for discount, which was true for fixed discount, but I realized that it modified how percentage discount are calculated.
    And most important, I thought the actual calculation for tax was good... It is if you use free shipping or shipping has a tax class defined, but when tax class is not defined (default in all shipping modules), shipping tax is missing from final tax. Whatever you display prices with or without tax, shipping has always the same value.
    I checked and as far as I know, shipping is always taxable. Basic rule for sale tax calculation is:
    Taxable amount = Sales - discount + charges
    Sales include goods and service provided.
    Discount includes sale discount, refunds, non-taxable items...
    Charges are shipping fees, handling fees and any other indirect cost incurred to provide goods or services.
    Before going further with discount module, this needs to be fixed.

    In 'ot_coupon.php', the variable
    PHP Code:
    $order->info['shipping_tax'
    is 0 when no tax class has been defined. In this case, it should be populated by calculating tax (using shop's tax class) from shipping cost considered as a tax included value.
    I don't know how to do that...

  6. #16
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    123
    Plugin Contributions
    5

    Default Re: Discount coupon value

    After more research on the topic, it seems that shipping with no tax is necessary in some situations, especially in the United States.
    Now that I understand more about taxes and ZC, I was able to write some new code that provides correct calculations. I did a lot of testing, considering all the possibilities with different options in coupon and ot_coupon settings...
    There is still one option that has some mystery left, 'Per Qualifying Items'. I did not find where/what are criteria for qualifying or not a product.

    New file is available on GitHub.
    https://github.com/piloujp/zencart/tree/Coupons

  7. #17
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    123
    Plugin Contributions
    5

    Default Re: Discount coupon value

    This week I did more testing than writing code, and discount coupons should now be usable with most of the options available in Zen Cart.
    By the way, I did same kind of work on GV module as it is related.

    Here is a quick summary of how discount coupon module work.
    In Admin->Modules->Order Total->Discount Coupon, there are few options:

    'Include Shipping' will include shipping cost when tax is recalculated and in maximum possible discount amount calculation.

    'Include Tax' will include tax amount when tax is recalculated and in maximum possible discount amount calculation. This option should not be used when tax is recalculated, as it does not make sense to do that. A message will pop up if you try anyway.

    'Re-calculate Tax' is probably the most important one. It has 3 options:
    'None' as it says, no re-calculation is done.
    'Standard' does calculate new tax after discount has been made on net total amount. It is for standard discount given to customers on their order total.
    'Credit note' will calculate new tax for refund type discounts that are made on gross price. It is useful to correct some mistake in precedent order, like item missing or defective.

    'Tax Class' will assign a tax class to discount. It is important to set this when doing tax recalculation. Not setting it will give wrong tax if recalculation is done.


    Then, in Discounts->Coupons Admin page, you can set coupons' value, date limit, number of use, if it applies by item or on order total, to all items or only those with no restrictions...
    By the way, the button to set restrictions is on the bottom right of the screen and can be easily missed on small screens where it is not visible...


    Gift Certificate module has similar options, but it is a discount manageable by customers. Considering tax recalculation, it is exactly the same as discount coupons.

  8. #18
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    12,497
    Plugin Contributions
    88

    Default Re: Discount coupon value

    Thanks for your hard work on this, @pilou2! It'll take me a couple of weeks, but I will review and provide the testing feedback for these corrections.

  9. #19
    Join Date
    Feb 2006
    Location
    Tampa Bay, Florida
    Posts
    9,703
    Plugin Contributions
    123

    Default Re: Discount coupon value

    +1. Thank you @pilou2 for your contributions.
    That Software Guy. My Store: Zen Cart Modifications
    Available for hire - See my ad in Services
    Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
    Do you benefit from Zen Cart? Then please support the project.

  10. #20
    Join Date
    Jun 2008
    Location
    Japan
    Posts
    123
    Plugin Contributions
    5

    Default Re: Discount coupon value

    Thanks are always welcome. ;)
    I really need someone else looking at it. The file was definitely a work in progress with lots of debug comments, and it is complicated. Although most of the calculations were right, I think their base was wrong. For example, when shipping has no taxes but cart has, then depending on displaying option of tax, you get two different results.
    I think an invoice whether using numbers including tax or without tax should always have the same final total and tax. This is the first important difference with actual ZC calculations, and because of this my code won't pass ZC validation tests.
    Another difference is, as I already wrote, the definition of standard discount and credit note discount.
    Standard customer level discount is done on total price (tax incl.) and credit note is product level refund and should be done on gross prices.

    My results are (or should be) consistent with these principles.
    There should not be important updates from now, but it is always better to download last GitHub file before testing.

    I have some nice fix for the lost penny problem, but I will explain in another thread.

 

 
Page 2 of 3 FirstFirst 123 LastLast

Similar Threads

  1. v155 Discount Coupon - Minimum Order Value Excluding Tax
    By allmart in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 12
    Last Post: 20 Jul 2020, 06:38 PM
  2. Replies: 6
    Last Post: 19 Jun 2011, 07:06 AM
  3. Replies: 18
    Last Post: 12 Mar 2010, 06:37 PM
  4. Ideas/Suggestions for Discount Coupon - How to give a credit and a discount
    By vegascoug in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 0
    Last Post: 15 Nov 2007, 05:40 PM
  5. Coupon welcome message showing discount when coupon is expired
    By tracyselena in forum Discounts/Coupons, Gift Certificates, Newsletters, Ads
    Replies: 4
    Last Post: 26 Jan 2007, 06:32 PM

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