Mar*_*phy 5 zend-framework currency magento
我打算创建一个新的奖励积分货币,所以我想要它显示300个奖励积分,而不是我的Magento商店销售价值300美元的产品.
我已经通过将其添加到lib/Zend/Locale/Data/en.xml中的currency部分尝试了一个不好的练习解决方案
<currency type="RWP">
<displayName>Reward Point</displayName>
<displayName count="one">Reward Point</displayName>
<displayName count="other">Reward Points</displayName>
<symbol>Reward Points</symbol>
</currency>
Run Code Online (Sandbox Code Playgroud)
我可以通过以下线程在Magento中启用和使用
它:http:
//www.magentocommerce.com/boards/viewthread/56508/但它仍然使用默认的格式化模式:¤ #,##0.00
所以它看起来像奖励积分800.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;
}
Run Code Online (Sandbox Code Playgroud)
我对货币体系只是略知一二,所以对这一切持保留态度。(另外,假设 Magento 1.4.2)
一种方法是directory/currency
模型。这是所有货币格式化函数和方法最终调用的类。您将在整个源代码中看到这样的调用
Mage::getModel('directory/currency')
Run Code Online (Sandbox Code Playgroud)
看起来没有办法说“对这种货币使用这种货币模型/类”,所以你将被困在这里进行类重写。和方法就是您所追求的formatPrecision
。formatTxt
另外,看起来该类directory/currency
包装了对 Magento 的区域设置对象的调用(对getNumber
和 的调用currency
)
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);
}
Run Code Online (Sandbox Code Playgroud)
语言环境对象是一个core/locale
. 您也可以重写这个类。如果这些是您所追求的方法。
最后,因为这是 Stack Overflow,所以 Magento 已经实现了许多奖励积分系统。检查这些内容以了解它们如何解决您遇到的问题可能是值得的。
归档时间: |
|
查看次数: |
3493 次 |
最近记录: |