尝试这个:
应用程序/etc/modules/Madison_Overrides.xml
<?xml version="1.0"?>
<config>
<modules>
<Madison_Overrides>
<active>true</active>
<codePool>local</codePool>
</Madison_Overrides>
</modules>
</config>
应用程序/代码/本地/麦迪逊/覆盖/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Madison_Overrides>
<version>1.0</version>
</Madison_Overrides>
</modules>
<global>
<models>
<directory>
<rewrite>
<currency>Madison_Overrides_Model_Currency</currency>
</rewrite>
</directory>
<core>
<rewrite>
<locale>Madison_Overrides_Model_Locale</locale>
</rewrite>
</core>
</models>
</global>
</config>
app/code/local/Madison/Overrides/Model/Currency.php
<?php
class Madison_Overrides_Model_Currency extends Mage_Directory_Model_Currency
{
/**
* Format price to currency format
*
* @param double $price
* @param bool $includeContainer
* @return string
*/
public function format($price, $options=array(), $includeContainer = true, $addBrackets = false)
{
//get the store id so you an correctly reference the global variable
$store_id = Mage::app()->getStore()->getId();
//JASE get precision from custom variable that can be set at store level
$getPrecision = Mage::getModel('core/variable')->setStoreId($store_id)->loadByCode('decimalPrecision')->getData('store_plain_value');
//Mage::log("Precision is ".$getPrecision,null,'jase.log');
//if set use it, otherwise default to two decimals
$precision = is_numeric($getPrecision) ? $getPrecision : 2 ;
return $this->formatPrecision($price, $precision, $options, $includeContainer, $addBrackets);
}
}
?>
app/code/local/Madison/Overrides/Model/Locale.php
<?php
class Madison_Overrides_Model_Locale extends Mage_Core_Model_Locale
{
/**
* Functions returns array with price formatting info for js function
* formatCurrency in js/varien/js.js
*
* @return array
*/
public function getJsPriceFormat()
{
$format = Zend_Locale_Data::getContent($this->getLocaleCode(), 'currencynumber');
$symbols = Zend_Locale_Data::getList($this->getLocaleCode(), 'symbols');
$pos = strpos($format, ';');
if ($pos !== false){
$format = substr($format, 0, $pos);
}
$format = preg_replace("/[^0\#\.,]/", "", $format);
$totalPrecision = 0;
$decimalPoint = strpos($format, '.');
if ($decimalPoint !== false) {
$totalPrecision = (strlen($format) - (strrpos($format, '.')+1));
} else {
$decimalPoint = strlen($format);
}
$requiredPrecision = $totalPrecision;
$t = substr($format, $decimalPoint);
$pos = strpos($t, '#');
if ($pos !== false){
$requiredPrecision = strlen($t) - $pos - $totalPrecision;
}
$group = 0;
if (strrpos($format, ',') !== false) {
$group = ($decimalPoint - strrpos($format, ',') - 1);
} else {
$group = strrpos($format, '.');
}
$integerRequired = (strpos($format, '.') - strpos($format, '0'));
//get the store id so you an correctly reference the global variable
$store_id = Mage::app()->getStore()->getId();
//JASE get precision from custom variable that can be set at store level
$getPrecision = Mage::getModel('core/variable')->setStoreId($store_id)->loadByCode('decimalPrecision')->getData('store_plain_value');
//if set use it, otherwise default to two decimals
$totalPrecision = is_numeric($getPrecision) ? $getPrecision : $totalPrecision ;
$requiredPrecision = is_numeric($getPrecision) ? $getPrecision : $requiredPrecision ;
$result = array(
'pattern' => Mage::app()->getStore()->getCurrentCurrency()->getOutputFormat(),
'precision' => $totalPrecision,
'requiredPrecision' => $requiredPrecision,
'decimalSymbol' => $symbols['decimal'],
'groupSymbol' => $symbols['group'],
'groupLength' => $group,
'integerRequired' => $integerRequired
);
return $result;
}
}
?>
上面的第一个 php 文件覆盖了 php 中的小数点精度,上面的第二个 php 覆盖了 javascript 中的小数点精度,这是可配置产品或带有选项的产品所必需的。
最后一步是您可以使用 Magento 中的自定义变量来控制每个商店的小数位数。尝试设置一个名为“decimalPrecision”的自定义变量。将“Plain Value”保存为 2。然后保存并返回。将“商店视图”更改为您的特定商店,并将“使用默认变量值”设置为“否”。确保在“Variable HTML Value”中放置一些文本以便保存(没关系)。在“Variable Plain Value”中输入数字“0”。现在使用此代码和该自定义变量,您选择的商店将没有小数,但其他地方将默认为 2 位小数。