最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Formating a price in Magento using JavaScript - Stack Overflow

programmeradmin6浏览0评论

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?

Share Improve this question edited May 1, 2014 at 11:35 Dairo 8181 gold badge9 silver badges24 bronze badges asked Sep 20, 2013 at 9:54 janwjanw 6,6626 gold badges28 silver badges49 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 6

Try 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().

发布评论

评论列表(0)

  1. 暂无评论