Zend framework 如何在Magento或Zend中创建自定义货币类型?
我希望创建一个新的奖励积分货币,因此我希望它显示300个奖励积分,而不是我的Magento商店销售价值300美元的产品 我已经尝试了一个错误的实践解决方案,将其添加到lib/Zend/Locale/Data/en.xml中的货币部分Zend framework 如何在Magento或Zend中创建自定义货币类型?,zend-framework,magento,currency,Zend Framework,Magento,Currency,我希望创建一个新的奖励积分货币,因此我希望它显示300个奖励积分,而不是我的Magento商店销售价值300美元的产品 我已经尝试了一个错误的实践解决方案,将其添加到lib/Zend/Locale/Data/en.xml中的货币部分 <currency type="RWP"> <displayName>Reward Point</displayName> <displayName count="one"&g
<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 1.4.2) 一种方法是
目录/currency
模型。这是所有货币格式化函数和方法最终调用的类。在整个源代码中都会看到这样的调用
Mage::getModel('directory/currency')
看起来没有办法说“使用此货币模型/类来表示此货币”,因此您将不得不在这里重写类。formatPrecision
和formatTxt
方法就是您所追求的方法
另外,它看起来像是目录/currency
类包装了对Magento的locale对象的调用(对getNumber
和currency
的调用)
区域设置对象是一个核心/locale
。你也可以重写这个类。如果这些是你想要的方法
最后,因为这是堆栈溢出,所以已经为Magento实现了许多奖励积分系统。查看这些内容,看看它们是如何解决您遇到的问题的,这可能是值得的。您有过这样的收获吗?我在Magento 2中也在做同样的事情,添加一种新的货币似乎是一项不平凡的任务。是的,我相信我做了,但那是6年前的事了,我几乎没有接触过PHP,更不用说Magento了。对不起:(
Mage::getModel('directory/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);
}