【问题标题】:Format price in the current locale and currency以当前语言环境和货币格式化价格
【发布时间】:2011-10-07 11:52:06
【问题描述】:

我用:

$product->getPrice();

要获得我可以用 ajax 计算“数量 X 价格”的未格式化价格。

我想以当前语言环境和货币重新格式化总计。我该怎么做?

【问题讨论】:

    标签: php magento


    【解决方案1】:

    试试这个:

    <?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(); ?>
    

    【讨论】:

      【解决方案2】:

      我认为 Google 可以回答您的问题 ;-) 请参阅 http://blog.chapagain.com.np/magento-format-price/

      你可以这样做

      $formattedPrice = Mage::helper('core')->currency($finalPrice, true, false);
      

      【讨论】:

      • Google 回答了我的问题……它把我带到了这里!
      • 各位小伙伴们,货币法不仅会格式化,还会转换成商店的货币。如果你想要格式化但没有转换,那么选择 Mage::helper('core')->formatPrice($price)。有关第二个参数的信息,请参见方法签名。
      【解决方案3】:
      $formattedPrice = Mage::helper('core')->currency($_finalPrice,true,false);
      

      【讨论】:

      • 投票赞成成为第一个提供答案的人(接受的答案只是稍后添加了此信息)
      • ... 并且接受答案最初应该被标记为删除链接的答案
      【解决方案4】:

      通过此代码在产品列表中格式化价格

      echo Mage::helper('core')->currency($_product->getPrice());
      

      【讨论】:

        【解决方案5】:

        未格式化和格式化:

        $price = $product->getPrice();
        $formatted = Mage::helper('core')->currency($price, true, false);
        

        或使用:

        Mage::helper('core')->formatPrice($price, true);
        

        【讨论】:

          【解决方案6】:

          用于以不同于当前货币的另一种货币格式化价格:

          Mage::app()->getLocale()->currency('EUR')->toCurrency($price);
          

          【讨论】:

            【解决方案7】:

            这是一个迷人的答案。适用于为商店选择的任何货币。

            $formattedPrice = Mage::helper('core')->currency($finalPrice, true, false);
            

            【讨论】:

              猜你喜欢
              • 1970-01-01
              • 1970-01-01
              • 2021-06-08
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              相关资源
              最近更新 更多