Author Topic: if no discount then hide crossed base price  (Read 3978 times)

claesbas

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 78
  • VMuikit - A Virtuemart theme for Yootheme template
    • VMuikit - A Virtuemart theme for Yootheme template
  • Skype Name: cnorin
  • VirtueMart Version: 3.2.4
if no discount then hide crossed base price
« on: March 27, 2013, 13:04:56 pm »
Hello,

Can someone please instruct me on how to write a script that hides the crossed baseprice if the product has no discount.

Now its:
Baseprise 25
Price 25

it looks great if there is a discount
Baseprise 35
Price 25
Discount 10

So a if statement that hides the crossed baseprice for products that hvae no discount or vice versa.

VMuikit - A Virtuemart theme for Yootheme template
https://joomlapro.com/vmuikit

VMonepage - One Page Checkout (Was free - now is €20)
https://joomlapro.com/product/virtuemart-one-page-checkout

VMKCO - Klarna Checkout Enhanced
https://joomlapro.com/product/virtuemart-klarna-checkout

gpessoa

  • Jr. Member
  • **
  • Posts: 129
Re: if no discount then hide crossed base price
« Reply #1 on: March 28, 2013, 01:16:57 am »
 VM already do that.

Shibumi

  • ** on hiatus **
  • Full Member
  • ***
  • Posts: 591
  • if it aint broke, there must be something wrong
    • Shibumi Design Studios
  • VirtueMart Version: 2.0.20b
Re: if no discount then hide crossed base price
« Reply #2 on: March 29, 2013, 19:10:10 pm »
I have an issue where if no sale price (or discount) is applied to a product, it still displays "Sale Price" for the product as the cost price when logged in (-default- shoppergroup) like this:
Regular Price: $749.99
Sale Price: $749.99

and when not logged in (-anonymous- shoppergroup) it displays like this (it does not display "Regular Price:"):
Sale Price: $749.99

If there is no discount or price override, why does it even show the "Sale Price:" and amount?? it should only show "Regular Price:" and amount.

If there is a discount or sale price, it will display like this:
Sale Price: $854.99
You Save: $95.00
and does not display "Regular Price:" to -anonymous- shoppergroup.

Ideas
Jeff
=================================================
Scionergy.com - www.Scionergy.com
Scion Owners Club of Ottawa - www.ScionOwnersClubOttawa.ca
Capital Door Service - www.CapitalDoorService.com - VM2.0.20b, Joomla 2.5.11 PHP5.2.11 powered site

Fries

  • Beginner
  • *
  • Posts: 8
Re: if no discount then hide crossed base price
« Reply #3 on: December 11, 2013, 22:10:36 pm »
VM already do that.

No, it doesn't. Recently there is only two way: showing base and discount prices together even if they are the same or not showing discount/base price at all

Peter Pillen

  • Jr. Member
  • **
  • Posts: 223
Re: if no discount then hide crossed base price
« Reply #4 on: December 12, 2013, 09:52:28 am »
VM actually does this already ... but not quite correct.

If you will check in your virtuemart backend in the prices of a product, you may notice that the productprice for example €39 will be transformed to 39.0000061 and the final salesprice will be transformed to 39.00001. Vm then does the check "is the final salesprice smaller than the baseprice with tax?" result "goody! I found a discount and will display that!"

Two solutions

(1) in your final salesprice, you can force the final salesprice to be bigger than the first 39.0000061 and make it for example 39.0000099. Both prices will be rounded to 39 in the display and VM will not trigger the discount.

(2) solution 1 will not always work (especially in the invoice). But there you can alter the code in the file components\com_virtuemart\views\invoice\tmpl\invoice_items.php The code that determines if the discounted price must be shown is

Code: [Select]
<?php if(!empty($item->product_basePriceWithTax) && $item->product_basePriceWithTax != $item->product_final_price ) {
echo '<span class="line-through" >'.$this->currency->priceDisplay($item->product_basePriceWithTax,$this->currency,$qtt) .'</span><br />' ;
}
elseif (empty($item->product_basePriceWithTax) && $item->product_item_price != $item->product_final_price) {
echo '<span class="line-through">' . $this->currency->priceDisplay($item->product_item_price,$this->currency,$qtt) . '</span><br />';
}
?>
You can understand that $item->product_basePriceWithTax != $item->product_final_price compares the prices without rounding like 39.0000061 versus 39.000001. So adding a rounded comparison with two decimals is more correct/realistic. Below you can see my adaptations which fixed this discount issue and in the same way you can do this check in many other views such as productdetails.

Code: [Select]
<?php if(!empty($item->product_basePriceWithTax) && round($item->product_basePriceWithTax,2) != round($item->product_final_price,2) ) {
echo '<span class="line-through" >'.$this->currency->priceDisplay($item->product_basePriceWithTax,$this->currency,$qtt) .'</span><br />' ;
}
elseif (empty($item->product_basePriceWithTax) && round($item->product_item_price,2) != round($item->product_final_price,2)) {
echo '<span class="line-through">' . $this->currency->priceDisplay($item->product_item_price,$this->currency,$qtt) . '</span><br />';
}
?>

kogos

  • Beginner
  • *
  • Posts: 10
Re: if no discount then hide crossed base price
« Reply #5 on: February 24, 2015, 14:51:08 pm »
i know that this is an old topic, but since people are coming here from google, looking for an answer, i had to mention this:

the above method works great, but now there is an option in configuration-> pricing that makes things easier. Just disable  "Round only display" and the crossed price will be hidden if there's no discount. However, please check that your prices are correct in frontend after doing this.

Ed Kiefer

  • Beginner
  • *
  • Posts: 26
Re: if no discount then hide crossed base price
« Reply #6 on: April 19, 2019, 16:27:49 pm »
When I disable "Round only display", it still shows 2 prices.

Jörgen

  • Global Moderator
  • Full Member
  • *
  • Posts: 2118
    • Kreativ Fotografi
  • VirtueMart Version: 3.2.12
Re: if no discount then hide crossed base price
« Reply #7 on: April 20, 2019, 11:02:36 am »
Probably a template issue, please test with Protostar.

Jörgen @ Kreativ Fotografi
Joomla 3.9.1
Virtuemart 3.2.12
Olympiantheme Hera (customized)