In Magento I have a savings box, which calculates how much you save based on the difference between the regular and discount price.
Now I want that box to increase the saving amount based on the quantity. If you order 2 of the product you save twice as much. Calculating that number and updating the price in javascript is not the problem.
The problem is the number I calculate isn't formatted. How do I format that price using javascipt? I do want it to be dynamic so that I don't have to change it when I use an other currency.
In short
How do I format a number into a price in Magento using javascript?
In Magento I have a savings box, which calculates how much you save based on the difference between the regular and discount price.
Now I want that box to increase the saving amount based on the quantity. If you order 2 of the product you save twice as much. Calculating that number and updating the price in javascript is not the problem.
The problem is the number I calculate isn't formatted. How do I format that price using javascipt? I do want it to be dynamic so that I don't have to change it when I use an other currency.
In short
How do I format a number into a price in Magento using javascript?
2 Answers
Reset to default 6Try this:
<?php
$priceFormat = Mage::helper('core')->jsonEncode(Mage::app()->getLocale()->getJsPriceFormat());
?>
<script>
formatCurrency(p.c_old_price, <?php echo $priceFormat ?>);
</script>
For more details see: https://himansuboity.wordpress./2014/09/30/magento-tip-how-to-get-the-store-price-format-by-javascript/
The suggested optionsPrice didn't work for me, since it has not JSON configuration (it only works for products containing options, which makes no sense for me! It seems to be obsolete Magento code)
On a product page, if the product has options, you can use optionsPrice.formatPrice(price)
. And in case you would like to use your own variable like optionsPrice
(eg, to use it for all kind of products), it is usually defined like this var optionsPrice = new Product.OptionsPrice(jsonConfig);
, where jsonConfig
is retrieved with Mage_Catalog_Block_Product_View::getJsonConfig()
.