VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: Fernando Soares on March 07, 2012, 20:00:17 PM

Title: Coupon Code Discount Shows in Cart and Stores positive values - bug
Post by: Fernando Soares on March 07, 2012, 20:00:17 PM
Hi,

Think I found an bug in the presentation and treatment of the value of coupons in the cart...
Let me explain:
The "shipments" have the following three fields where a positive value means an increase in the value of the purchase order. Negative values ​​mean a discount.
- Shipment Cost
- Package Fee
- Tax
The values ​​are displayed with the correct signs ("-" for negative values) in the shopping cart. OK

The "payments" have the following three fields where a positive value means an increase in the value of the purchase order. Negative values ​​mean a discount.
- Fee per transaction
- Percent of the total product amount
- Tax
The values ​​are displayed with the correct signs ("-" for negative values) in the shopping cart. OK

Up to this point all right!

But for the coupons is the reverse process, a positive value (percentage or total) means a discount (-) in the amount of the purchase order. Negative values ​​mean an increase.

example:
Purchase Order: $100.00
Coupom Code: 50% (discount) = $-50.00
Order total: $50.00

The problems:
1 - The values ​​of the discount from discount coupons are being displayed as positive values ​​although they are discounting the value of the order.

2 - If you put a coupon with a negative value, which generates an increase in the purchase order, then the value is displayed as negative (-) in your shopping cart.

3 - The values ​​in the variable $cart(Like in $cart->pricesUnformatted['salesPriceCoupon']) for the discount coupon are also positive values and these values ​​are also stored thus inverted in the database.

Although the final value is correct, I think ocurred a small inversion mistake on the sign to the values from coupons.

Joomla! 2.5.1
VirtueMart 2.0.2
VirtueMart AIO 2.0.2

Thanks

[attachment cleanup by admin]
Title: Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
Post by: seyi on March 09, 2012, 00:42:35 AM
I see your point on the front end.  The display would flow a little better if there was a minus sign in front of the discount.  It makes it easier for the customer to read.  For the storage of the discount in the backend, it really is up to the shop to choose which they prefer and code accordingly.  Since vm1.1.x stores the coupon_discount as a positive number, it is probably best to leave it that way as most developers are used to it.
Title: Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
Post by: Fernando Soares on March 09, 2012, 16:32:08 PM
Quote from: seyi on March 09, 2012, 00:42:35 AM
... For the storage of the discount in the backend, it really is up to the shop to choose which they prefer and code accordingly.  Since vm1.1.x stores the coupon_discount as a positive number, it is probably best to leave it that way as most developers are used to it.
I understand that is for compatibility reasons that cupom values are stored in positive format. This is not a problem for coding a plugin, I simply do a multiplication by "-1" to invert the signal.

Quote from: seyi on March 09, 2012, 00:42:35 AM
I see your point on the front end.  The display would flow a little better if there was a minus sign in front of the discount.  It makes it easier for the customer to read. ...
This is the point in fact: for front end customer the value of cupons must be shown in negative format when this is a discount, and in positive format when is an increase...
Is much important for the user flow read during checkout process.

Thanks!
Title: Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
Post by: palpal on March 31, 2012, 13:57:44 PM
Hi, i have exactly same problem here regarding the coupon shows positive values during check out.

Hi Fernando, when you say "" simply do a multiplication by "-1" to invert the signal. "" , may i know where would be the code i should change?  thank you !!

Title: Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
Post by: seyi on March 31, 2012, 16:06:06 PM
You could try this:
in www/administrator/components/com_virtuemart/helpers/currencydisplay.php right after this

<?php 
public function 
createPriceDiv($name,$description,$product_price,$priceOnly=false,$switchSequel=false,$quantity 1.0){

//  vmdebug('createPriceDiv '.$name,$product_price[$name]);
if(empty($product_price)) return '';
 
?>




add this

<?php 
if($name=='couponTax' || $name=='salesPriceCoupon'$product_price *= -1# seyi_code
 
?>



This should change the display of coupons everywhere to negative
Title: Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
Post by: palpal on April 02, 2012, 15:57:19 PM
Hi seyi, thanks for your reply. I have followed the way you mentioned but seems it is still not working at all.
I realized the code of the version I installed  (Vm2.0.2) is slightly different from yours. Would it matter ?

public function createPriceDiv($name,$description,$product_price,$priceOnly=false,$switchSequel=false){

if(empty($product_price)) return '';

if($name=='couponTax' || $name=='salesPriceCoupon') $product_price *= -1; //seyi_code

//This could be easily extended by product specific settings

if(!empty($this->_priceConfig[$name][0])){
Title: Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
Post by: seyi on April 02, 2012, 18:08:46 PM
That is strange.  I tested this on the latest code in svn as of 3 days ago.  After adding the code, the coupon discount displayed in the shopping cart is negative.  Are you using some type of cart override?  one page checkout?
Title: Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
Post by: Fernando Soares on April 03, 2012, 02:28:03 AM
Hi,

Seyi, the SVN version is a development shapshot and can change literally "from day to night" then my option is use the latest released stable version available... (now 2.0.2)

You can check your changes in this version and post here?

Thanks
Title: Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
Post by: seyi on April 03, 2012, 13:40:58 PM
for version 2.0.2
in www/components/com_virtuemart/views/cart/tmpl/default_pricelist.php, before the closing php tag "?>" add this
<?php
$currency 
CurrencyDisplay::getInstance( );
$this->cart->prices['couponTax'] = $currency->priceDisplay($this->cart->pricesUnformatted['couponTax'] * -1);
$this->cart->prices['salesPriceCoupon'] = $currency->priceDisplay($this->cart->pricesUnformatted['salesPriceCoupon'] * -1);
?>