2013-07-28 85 views
2

這裏有幾個資源涵蓋了如何在Magento或整個網站中去除特定貨幣的小數點,但沒有包括如何去做某些商店。Magento如何從一個商店的價格中去掉小數點

背景:每貨幣

價格格式的管轄/lib/Zend/Currency.php(http://mrtony.org/2013/01/removing-decimals-in-currency-for-magento/),所以你可以重寫貨幣小數有使用數字格式。此文件不可覆蓋,其中的更改會影響整個網站。

如果你想從核心向前邁進了一步,並逐漸步入顯示的代碼是重寫你可以亂用代碼/核心/法師/目錄/型號/ Currency.php(http://magentocoders.blogspot.com.au/2011/10/how-to-remove-decimal-price-in-magento.html

隨着兩者的以上如果你只想做一家商店?

回答

3

嘗試這種情況:

應用的/ etc /模塊/ 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); 
    } 
} 

?> 

應用程序/代碼/本地/麥迪遜/重寫/型號/ 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.然後保存並返回。將「存儲視圖」更改爲您的特定商店,並將「使用默認變量值」設置爲「否」。請務必在「變量HTML值」中加入一些文本,以便保存(不重要)。在「變量平原值」中輸入數字「0」。現在使用此代碼和該自定義變量,您所選商店中將不會有小數點,但其他地方將默認爲2位小數。