Author Topic: Rounded prices - how?  (Read 1758 times)

lausianne

  • Beginner
  • *
  • Posts: 47
Re: Rounded prices - how?
« Reply #30 on: May 22, 2018, 17:30:07 pm »
Prices are not inclusive of VAT in this shop, there simply is no VAT (can be, if customer in CH, but is not related to this issue anyway). I don't expect anyone to work backwards from anywhere. On the contrary, I'd hope calculations worked forward from base prices.

And, as I said, it does not matter at all what cost prices are set to. They could be rounded to a hundred dollars - after currency conversion they'd still have lots of digits. And then produce wrong prices in the frontend.

And if you check the original VM demo shop - without changing any of the default settings, the error is right there.

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 2738
  • VirtueMart Version: 3.2.15
Re: Rounded prices - how?
« Reply #31 on: May 22, 2018, 18:50:13 pm »
Ok - I am still hanging in here

Just tested the latest version

NO tax
I went with a price of 18.97749
"Round only display" switched off
Currency is 2dp

When I add 10 to cart - it calculates to 2 dp based on the single item rounded first.

The last image is where I switch on "Round only display"
regards
A

Joomla 3.8.8
php 5.6 + php 7.0

lausianne

  • Beginner
  • *
  • Posts: 47
Re: Rounded prices - how?
« Reply #32 on: May 30, 2018, 12:00:55 pm »
Sorry, very busy last few days. All right, so there is one example where the rounding leads to a correct result. But should these results not ALWAYS be correct, not just randomly?
Even if it says in the config that it "Round only display off" mathematically give more accurate results, to which I totally agree - in the backend. But customer sees what customer sees. He sees no backend. And if he sees 18.00 x 2 = 36.10 and has doubts about the mathematical correctness, what can I say? My mathematics are correcter than yours?



lausianne

  • Beginner
  • *
  • Posts: 47
Re: Rounded prices - how?
« Reply #33 on: May 30, 2018, 12:10:40 pm »
Demo shop, your example price, no tax, no rounding.

EDIT: In the demo shop I cannot see or set rounding on display. But in the shop I'm working on (VM 3.2.14) it makes no real difference.

AH

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 2738
  • VirtueMart Version: 3.2.15
Re: Rounded prices - how?
« Reply #34 on: May 31, 2018, 09:54:37 am »
Luisanne

I am working on 3.2.15

Wait until that is released - then try that.

regards
A

Joomla 3.8.8
php 5.6 + php 7.0

lausianne

  • Beginner
  • *
  • Posts: 47
Re: Rounded prices - how?
« Reply #35 on: May 31, 2018, 14:24:38 pm »
Thank you!

For the time being, I applied a quick & dirty workaround, added to .\components\com_virtuemart\views\productdetails\tmpl\default.php:

Code: [Select]
<script type="application/javascript">
correctTotal = function() {
jQuery('.spacer-buy-area span.PricepriceWithoutTaxTt').off( "DOMNodeInserted", correctTotal);
quantity = jQuery("input.quantity-input").val();
basePriceStr = jQuery(".spacer-buy-area span.PricebasePriceVariant").text();
basePriceParts = basePriceStr.split(' ');
basePrice = parseFloat(basePriceParts[0]);
totalPrice = (basePrice*quantity).toFixed(2);
currencyStr  = basePriceParts[1];
jQuery(".spacer-buy-area span.PricepriceWithoutTaxTt").html(totalPrice  +" "+currencyStr);
console.log("Total price fixed");
jQuery('.spacer-buy-area span.PricepriceWithoutTaxTt').on("DOMNodeInserted", correctTotal);
};
jQuery('.spacer-buy-area span.PricepriceWithoutTaxTt').on("DOMNodeInserted", correctTotal);
</script>