News:

Looking for documentation? Take a look on our wiki

Main Menu

Coupon values incorrectly calculated

Started by Oliver Griffiths, April 10, 2008, 14:20:07 PM

Previous topic - Next topic

Oliver Griffiths

Hi,

I believe we've found a bug in VM1.1 with coupons being applied BEFORE tax and shipping.

I have 1 product in my cart with a net value of £8.5
I have 1 coupon for 10%
My VAT rate is 17.5%
My shipping is 2.35
My Shipping tax is 0.41
My product tax is 1.34
My order tax is 1.75

The shipping, shipping tax and order tax is calculated correctly - however the coupon amount and order total is not.

The calculation should (i believe) be as follows:

Products net value * 1 - coupon % = new product net
8.5 * 0.9 = 7.65

New product net * product tax = product gross
7.65 * 1.175 = 8.98875

Product gross + shipping + shipping tax = order total
8.98875 + 2.35 + 0.41 = 11.74875

= £11.75

However, the value stored in the database is £11.60

Any ideas anyone?

aravot

This depends where you live, in USA we deduct coupons before tax and shipping.

In VirtueMart configuration there is an option for this, look for "Subtract payment discount before tax/shipping?"

Oliver Griffiths

Hi,

yes, ive got that option selected. Ive been dumping out some variables from the cart, and if I dump out $totals from the return of $this->calc_order_totals( $d ) in $ps_checkout->add() with the figures above, I get 11.60 for the total of the order, however, the cart displays the correct value.

you can check it out at http://www.superliving.co.uk/newsite

Oli


Oliver Griffiths

I havent, I want it to deduct the coupon before tax and shipping - the values in the cart and the values in $d don't match?

aravot

I haven't yet started testing coupons, there is a problem with tax which we are working to fix it, once that is done, I will move the coupons, if you have the time and would like to help speed up by testing different methods of taxing (no coupon yet) please do and let us know of your findings.

Oliver Griffiths

Hi Peter,

Thanks for the reply. Ive done alot of work with VM and am fairly familiar with the codebase.

From what I can see, the coupon is being applied to the taxed figure rather than the untaxed figure, however the value that comes out in the cart for the total appears to be correct (somehow), but the value that is stored in the database is not.

Im not test on the latest build so would you mind putting an order in for a product that has a net value of 8.5 and a 10% discount and see what values are present in the cart and then subsequently saved in the DB.

This is a real sticking point for us as our client has sent out hundreds of promotional flyers with the coupon code, and we cant launch the site if the coupons dont work properly.

I believe I can modify the relevant basket and ro_basket scripts to pass the untaxed value if coupons should be applied before tax and work from there, unless you have any other ideas?

Also, it appears that the serialised product values stored in the DB for the order are the original values and not the values affected by the discount, is this a bug or a feature - as far as I can see, it should be the values affected by the discount.

Im not sure if a post I made a while ago was ever picked up regarding shipping tax, can you tell if it has been noted?

Regards

Oli

Oliver Griffiths

Hi Peter,

Just to keep you posted, Ive downloaded the latest SVN and put through an order and the figures are coming out incorrectly.

You can checkout the default installation of virtuemart with sample data installed (though price in pounds and vat at 17.5%), the figure you get in the cart and the figure you get on the invoice email are different, the difference being the difference between the two coupon ammounts (0.85 and 1).

Ive assertained that th value that is held in the session is incorrect, it doesnt check if you are calculting the coupon ammount before or after tax so in this case the coupon ammount is 1, where it should be 0.85.

Will keep you posted.

Oli

mauri

I tested this to VM 1.0.15 and the case is same that in VM 1.1.0.
When you submit coupon in cart, $_SESSION['coupon_discount'] get value with tax. If PAYMENT_DISCOUNT_BEFORE_TAX is enabled the $_SESSION['coupon_discount'] value should be without tax.
This can see better if coupon discount is total.
Can this fix in ps_coupon.php or where?
VirtueMart,(Joomla-phpShop, mambo-phpShop) since 2004-03-11

Oliver Griffiths

Inface, ive noticed that if you turn coupons to after shipping and tax in the config, the coupon amount and order totals are calculated correctly, however, the shipping is not taxed! Which is fine by me because we dont want shipping taxed, so ive got it working, but by using one bug to fix another.

For reference, it would be best if there were 3 options for ocupongs:

1 - before tax and shipping
2 - after tax but before shipping
3- after fax and shipping

As most people wont want to discount their shipping rates otherwise they are likely to make a loss on shipping.

Oli

thewitt

You have to also keep in mind that Coupons are also used as Gift Certificates - which are the SAME AS MONEY and SHOULD be applied to Cost of Goods, Taxes and Shipping as options...

A Gift Certificate should also be decremented when used, and not deleted until it's completely gone. If someone purchases a $100 Gift Certificate for a friend, they should be able to make 4 purchases of $25 each and use the certificate for each one...

The variations for how to apply a coupon should be part of the COUPON definition - not a global variable for the entire store.

Coupons should have the following configurable attributes (may be some missing):

Applied to product price
Applied to product price and tax
Applied to product price, tax and shipping
Applied to shipping only
Applied only if the value of the order exceeds $NNN
Applied only to certain products
NOT applied to specific products
Calculated as a percentage or a total value
Limited to certain Shopper Groups
Limited to number of usages per customer
Limited by date range

I think that list covers all of our usage today in our other online stores.

Right now, with no way to apply a coupon code to Product Cost, Shipping and Taxes, they are worthless for me.

We allow a "Sample" product to be ordered with a coupon and there is NO COST to the customer at all if we decide to fill the order.

We also have a need for a "Sample - Pay Shipping" code which will allow the custom to order a sample at no charge but he DOES pay for shipping, so longer term having just one way across the store to apply the coupon makes it impossible as well.

-t

jcalvert2


I have also encountered this problem with coupon discounts not being subtracted before tax is applied, even when the box is checked in the Tax Configuration: "Subtract payment discount before tax/shipping?".  I am using VM 1.0.14.

It appears that this bug has not been fixed in VM 1.1.0.  Is that correct?

Does anyone have a patch for this?

thanks,
JC

Suzan Marie Chin

We're having a similar issue. We have apply coupon before taxes and shipping unchecked which we take to mean that the coupon will be applied after the tax and shipping are added to the order.

This doesn't happen. Although it is not checked, the cart applies the coupon to just the product cost.

This makes using Coupons for Gift Cards useless. You don't want someone gettng a gift card that is of a total that covers the goods, shipping and tax and then they have pay the tax and shipping in order to use the coupon.

Also, if a coupon is issued to act as a Gift Card, and the purchase doesn't use the entire value of the coupon, it zeros it out anyway. That's definitely a problem.

Is there a fix for this. It would appear that the deselection of this has no effect and won't let the cart calculate things properly.

Thanks to anyone out there who might know how to fix this and is willing to share the info.

siesta

I'd also like to know how to apply the coupon value AFTER shipping. This will allow the coupons to be used like gift cards and should technically be able to be used towards shipping costs.

Cheers!
Amanda

mauri

Quote from: jcalvert2 on June 18, 2008, 02:04:04 AM
I have also encountered this problem with coupon discounts not being subtracted before tax is applied, even when the box is checked in the Tax Configuration: "Subtract payment discount before tax/shipping?".  I am using VM 1.0.14.
It appears that this bug has not been fixed in VM 1.1.0.  Is that correct?
Does anyone have a patch for this?
thanks,
JC

/administrator/components/com_virtuemart/classes/ps_coupon.php
about row 200:
               /* take the subtotal for calculation of the discount */
                //$_SESSION['coupon_discount'] = round( ($subtotal * $coupon_db->f("coupon_value") / 100), 2);
                 $coupon_value = round( ($d["total"] * $coupon_db->f("coupon_value") / 100), 2);
                 if( $d["total"] < $coupon_value ) {


Edit it like this:

               /* take the subtotal for calculation of the discount */
                //$_SESSION['coupon_discount'] = round( ($subtotal * $coupon_db->f("coupon_value") / 100), 2);
                 $coupon_value = round( ($d["total"] * $coupon_db->f("coupon_value") / 100), 2);
                   if( PAYMENT_DISCOUNT_BEFORE == '1') {
              $totals = $checkout->calc_order_totals($d);
                      $coupon_value = round( ($totals['order_subtotal'] * $coupon_db->f("coupon_value") / 100), 2);
                   }
                 if( $d["total"] < $coupon_value ) {
VirtueMart,(Joomla-phpShop, mambo-phpShop) since 2004-03-11