News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

Price rounding Bug

Started by niosme, January 10, 2023, 09:19:38 AM

Previous topic - Next topic

niosme

Hello,

This exists in virtuemart a lot time ago.
The problem is when we check show only rounding price from show price settings and we put e.g 0.1 as a price and calculate price without tax all works fine.
If we go to resave the product or change the description the rounding is not working and turns the price into 0.1001 and this shows in frontend as a discount from 0.1 to 0.1.

At first time we clicked the calculate price without tax and fixed and rounded the price. But if we dont check the field and we just want to change the description or the name or something in the product and we dont want to change the price it looks like the rounding method is not taken into account and the price turns into 0.1001.
This problem exists in all virtuemart versions btw.I remember it from the old one.

This happens in latest joomla 3 and latest virtuemart but i remember it happening and in all previous versions.
Attached some screenshots to see what is happening to reproduce the error.

Thanks in advance and happy new year to everyone :)
Fullstack Developer and Joomla Expert

hazael

#1
0.1001 is also 0.1
This phenomenon has been known for ages. Such a problem is generally not a problem, because this value can be rounded directly in the template.

Test the bug I wrote about in the previous post - in my case the prices are from real cosmic space ;)
https://forum.virtuemart.net/index.php?topic=149445.0

niosme

Yes but rounding only works if we tick the calculate price without tax.And a save of product without ticking that it shows as a discount without any discount on product!
How the value can be rounded in template? It shows it as a discount from 0.1 to 0.1. Its rounded but there is not a discount. In first save it shows it as 0.1 on second as 0.1001 and in frontend as a discount from the same price to the same price.
Fullstack Developer and Joomla Expert

hazael

#3
I don't know if I understand you correctly...
I think if you do not have a discount officially enabled (calculation rules) and this discount appears on the frontpage, then most likely you have a poorly written function in the template that activates this discount.

Check how the function that triggers this discount is written
com_virtuemart/sublayouts/prices.php

Correctly it should be: if ($product->prices['discountAmount'] != -0) {}

Some people incorrectly trigger a discount by comparing different price types: (example) basePriceWithTax VS salesPrice. if the prices are the same, then there is no discount. However, as a result of bad rounding causing a difference in prices, you can see such an illogical discount

niosme

There is no override in the prices file.
Its the virtuemart latest default.I am attaching it because there is no if function like this you said.

I can see this if if ($product->prices['discountedPriceWithoutTax'] != $product->prices['priceWithoutTax']) {
should this be changed to take care of some more settings and vars?
Fullstack Developer and Joomla Expert

hazael

#5
Hi,
I don't know which specific prices you display on the website. Personally, I would remove unused code strings.
This snippet of code you have:
if (round($product->prices['basePriceWithTax'],$currency->_priceConfig['salesPrice'][1]) != round($product->prices['salesPrice'],$currency->_priceConfig['salesPrice'][1])) {
echo '<span class="price-crossed" >' . $currency->createPriceDiv ('basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $product->prices) . "</span>";
}
if (round($product->prices['salesPriceWithDiscount'],$currency->_priceConfig['salesPrice'][1]) != round($product->prices['salesPrice'],$currency->_priceConfig['salesPrice'][1])) {
echo $currency->createPriceDiv ('salesPriceWithDiscount', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITH_DISCOUNT', $product->prices);
}


change to

if ($product->prices['discountAmount'] != -0) {
echo '<span class="price-crossed" >' . $currency->createPriceDiv ('basePriceWithTax', 'COM_VIRTUEMART_PRODUCT_BASEPRICE_WITHTAX', $product->prices) . "</span>";
echo $currency->createPriceDiv ('salesPriceWithDiscount', 'COM_VIRTUEMART_PRODUCT_SALESPRICE_WITH_DISCOUNT', $product->prices);
}


PS. You don't have to one prices.php file for everything. I use a separate file with prices on the product list and separately directly in the product.