magento价格getPrice()值

web*_*kul 11 php magento

function getDescriptionHtml($tpl, $p){
    $out = "";
    $pr = $p["product"];

    if(Mage::getStoreConfig('featuredproducts/displayoptions/title') == 'description'){
        $out .= "<ins><h4>{$pr->getName()}</h4></ins>";
    }
    $out .= "<span class=\"description\"".
            (!Mage::getStoreConfig('featuredproducts/displayoptions/description') ?
                    "style=\"display:none;\""
                :
                    ""
            )
            .">{$p['description']}</span>";
    $out .= "<ins><div>".
            (Mage::getStoreConfig('featuredproducts/displayoptions/price') ?
                    "<span style=\"font-size:45px\">{$pr->getPrice()}</span>"
                :
                    ""
            )       
            ."".
            (Mage::getStoreConfig('featuredproducts/displayoptions/bnb') ?
                    "<div><button style=\"postion:relative;margin-left:80px;margin-top:140px\" class=\"form-button\" onclick=\"setLocation('{$p["url"]}')\"><span>{$tpl->__('Buy Now')}</span></button></div>"
                :
                    "")
            ."
            </div></ins>";
    return $out;        
}
Run Code Online (Sandbox Code Playgroud)

根据显示的代码,当我使用$ pr-> getPrice()时,它的输出看起来像299.0000,但我希望它像299.00.我怎样才能做到这一点?

Ala*_*ton 43

为什么不尝试一下......

Mage::helper('core')->currency($pr->getPrice());
Run Code Online (Sandbox Code Playgroud)

它也为您提供货币符号.


R T*_*R T 20

Mage::helper('core')->currency($_product->getFinalPrice(),true,false);
Run Code Online (Sandbox Code Playgroud)
  • 价格格式"真实".
  • 没有HTML的"假".

这是我在Magento 1.7.0.2中所做的


Yan*_*ton 16

尝试数字格式

"<span style=\"font-size:45px\">{" . number_format($pr->getPrice(), 2) . "}</span>"
Run Code Online (Sandbox Code Playgroud)

  • 但不是最佳解决方案,因为价格应始终使用Magento的内部价格功能来实现garant兼容性 (2认同)