0

So on the product page (view.phtml) I had:

<div class="no-display" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
<span itemprop="price"><?php echo Mage::helper('core')->currency($_product->getFinalPrice()); ?></span>
<link itemprop="availability" href="http://schema.org/InStock" />

Which give me the result of eg €70.30

But for rich snippet the currency has to be declared separately

So i used the code:

<meta itemprop="priceCurrency" content="<?php echo $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode(); ?>"/>
<span itemprop="price"><?php echo Mage::helper('core')->currency($_product->getFinalPrice(), false, false); ?></span>

Which give the the Currency separately from the Price but the price is now not rounded so I get eg: 70.30132312323

How do I get the price (with out the currency) to 2 decimal points?

Edit: just to clarify, there are 2 store fronts with different currencies, so if you just call the base price it will give the wrong value for one of the store fronts ( eg you get 64.99 instead of 70.30)

Thanks

2 Answers 2

0

Just put following code:

<meta itemprop="priceCurrency" content="<?php echo $currency_code = Mage::app()->getStore()->getCurrentCurrencyCode(); ?>"/>
<span itemprop="price"><?php echo $_product->getFinalPrice(); ?></span>

If, for some reason, you still get too many decimals, you can use:

<span itemprop="price"><?php echo round($_product->getFinalPrice(), 2); ?></span>
2
  • While that does show the price in 2 decimal places, it shows the base currency price and not the price of the currency for the store front, so it is show 64.99 and not 70.30
    – PaddyD
    Commented Mar 1, 2017 at 12:29
  • OK, i just changed my code to: <span itemprop="price"><?php echo Mage::helper('core')->currency($_product->getFinalPrice(), 2, false, false); ?>
    – PaddyD
    Commented Mar 1, 2017 at 12:34
0

The price is stored in the Mage registry already rounded. You can access the price like this:

<?php Mage::registry('product')->getFinalPrice(); ?>
1
  • While that does show the price in 2 decimal places, it shows the base currency price and not the price of the currency for the store front, so it is show 64.99 and not 70.30
    – PaddyD
    Commented Mar 1, 2017 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.