Author Topic: Coupon Code Discount Shows in Cart and Stores positive values - bug  (Read 3575 times)

Fernando Soares

  • Translator Team
  • Beginner
  • **
  • Posts: 34
    • Fernando Soares Website
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]
Fernando Soares - Joomleiros Brasil!
Espeshitpillta em Joomla! e VirtueMart
Website: http://www.fernandosoares.com.br
Twitter: http://twitter.com/fernando_soares

seyi

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 404
    • AwoDev
Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
« Reply #1 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.
Seyi A
--------------------
Promotion enhancement for Virtuemart:
   - AwoCoupon FREE - http://www.awocoupon.com/starter
   - AwoCoupon Pro - http://awodev.com/products/joomla/awocoupon
   - AwoRewards - http://awodev.com/products/joomla/aworewards
   - AwoAffiliate - http://awodev.com/products/joomla/awoaffiliate

Fernando Soares

  • Translator Team
  • Beginner
  • **
  • Posts: 34
    • Fernando Soares Website
Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
« Reply #2 on: March 09, 2012, 16:32:08 pm »
... 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.

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!
Fernando Soares - Joomleiros Brasil!
Espeshitpillta em Joomla! e VirtueMart
Website: http://www.fernandosoares.com.br
Twitter: http://twitter.com/fernando_soares

palpal

  • Beginner
  • *
  • Posts: 14
Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
« Reply #3 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 !!


seyi

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 404
    • AwoDev
Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
« Reply #4 on: March 31, 2012, 16:06:06 pm »
You could try this:
in www/administrator/components/com_virtuemart/helpers/currencydisplay.php right after this
Code: [Select]
<?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
Code: [Select]
<?php 
if($name=='couponTax' || $name=='salesPriceCoupon'$product_price *= -1# seyi_code
 
?>


This should change the display of coupons everywhere to negative
Seyi A
--------------------
Promotion enhancement for Virtuemart:
   - AwoCoupon FREE - http://www.awocoupon.com/starter
   - AwoCoupon Pro - http://awodev.com/products/joomla/awocoupon
   - AwoRewards - http://awodev.com/products/joomla/aworewards
   - AwoAffiliate - http://awodev.com/products/joomla/awoaffiliate

palpal

  • Beginner
  • *
  • Posts: 14
Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
« Reply #5 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 ?

Code: [Select]
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])){

seyi

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 404
    • AwoDev
Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
« Reply #6 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?
Seyi A
--------------------
Promotion enhancement for Virtuemart:
   - AwoCoupon FREE - http://www.awocoupon.com/starter
   - AwoCoupon Pro - http://awodev.com/products/joomla/awocoupon
   - AwoRewards - http://awodev.com/products/joomla/aworewards
   - AwoAffiliate - http://awodev.com/products/joomla/awoaffiliate

Fernando Soares

  • Translator Team
  • Beginner
  • **
  • Posts: 34
    • Fernando Soares Website
Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
« Reply #7 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
Fernando Soares - Joomleiros Brasil!
Espeshitpillta em Joomla! e VirtueMart
Website: http://www.fernandosoares.com.br
Twitter: http://twitter.com/fernando_soares

seyi

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 404
    • AwoDev
Re: Coupon Code Discount Shows in Cart and Stores positive values - bug
« Reply #8 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
Code: [Select]
<?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);
?>
Seyi A
--------------------
Promotion enhancement for Virtuemart:
   - AwoCoupon FREE - http://www.awocoupon.com/starter
   - AwoCoupon Pro - http://awodev.com/products/joomla/awocoupon
   - AwoRewards - http://awodev.com/products/joomla/aworewards
   - AwoAffiliate - http://awodev.com/products/joomla/awoaffiliate