2011-03-11 51 views
5

我期待创造一个新的奖励积分货币,所以我想要它显示300奖励积分,而不是我的Magento商店销售价值300美元的产品。如何在Magento或Zend中创建自定义货币类型?

我已经加入这在LIB货币节尝试了不好的做法,解决方案/的Zend /区域设置/数据/ en.xml

<currency type="RWP"> 
      <displayName>Reward Point</displayName> 
      <displayName count="one">Reward Point</displayName> 
      <displayName count="other">Reward Points</displayName> 
      <symbol>Reward Points</symbol> 
</currency> 

我能够启用和使用在Magento下面这个线程: http://www.magentocommerce.com/boards/viewthread/56508/ 但它仍然使用默认的格式设置模式:¤ #,##0.00所以它看起来像奖励Points800.00

我的区域设置为en_CA,据我所知,没有办法改变格式化格式,同时不影响CDN和USD格式。

我试着覆盖Mage_Core_Model_Store,这样如果当前的货币代码是RWP,它将使用一组格式化选项格式化价格,但是当我处于产品视图时,这不起作用。更何况,这似乎是一个非常肮脏的方式来完成我想要的。

/** 
* Format price with currency filter (taking rate into consideration) 
* 
* @param double $price 
* @param bool $includeContainer 
* @return string 
*/ 
public function formatPrice($price, $includeContainer = true) 
{ 
    if ($this->getCurrentCurrency()) { 
     /** 
     * Options array 
     * 
     * The following options are available 
     * 'position' => Position for the currency sign 
     * 'script' => Script for the output 
     * 'format' => Locale for numeric output 
     * 'display' => Currency detail to show 
     * 'precision' => Precision for the currency 
     * 'name'  => Name for this currency 
     * 'currency' => 3 lettered international abbreviation 
     * 'symbol' => Currency symbol 
     */ 
     $options = array(); 

     if ($this->getCurrentCurrencyCode() == 'RWP') { 
      $options = array(
       'position' => 16, 
       'precision' => 0, 
       'format'=> '#,##0.00 ' 
      ); 
     } 
     return $this->getCurrentCurrency()->format($price, $options, $includeContainer); 
    } 
    return $price; 
} 
+0

你有没有遇到过这种情况?我正在Magento 2中做同样的事情,并且增加一个新货币似乎是一项不重要的任务。 – floorz

+0

是的,我相信我做到了,但那是6年前的事情,我几乎没有碰过PHP,更不用说Magento的时间差不多了。对不起:( –

回答

0

货币系统是我只是通常熟悉的一个,所以把所有这一切都用一粒盐。 (另外,假设Magento 1.4.2)

一种方法是directory/currency模型。这是所有货币格式化函数和方法最终调用的类。你会看到类似这样的电话在整个源代码

Mage::getModel('directory/currency') 

它看起来并不像有办法说“使用此货币模型/类此货币”,所以你会用一个类被卡住在这里重写。 formatPrecisionformatTxt方法是你所追求的方法。

此外,它看起来像directory/currency类包装调用Magento的Locale对象(调用getNumbercurrency

public function formatTxt($price, $options=array()) 
{ 
    if (!is_numeric($price)) { 
     $price = Mage::app()->getLocale()->getNumber($price); 
    } 
    /** 
    * Fix problem with 12 000 000, 1 200 000 
    * 
    * %f - the argument is treated as a float, and presented as a floating-point number (locale aware). 
    * %F - the argument is treated as a float, and presented as a floating-point number (non-locale aware). 
    */ 
    $price = sprintf("%F", $price); 
    return Mage::app()->getLocale()->currency($this->getCode())->toCurrency($price, $options); 
} 

语言环境对象是core/locale。你也可以重写这个类。如果那些是你以后的方法。

最后,由于这是堆栈溢出,因此已经为Magento实施了许多奖励积分系统。检查这些以了解他们如何解决您遇到的问题可能是值得的。