2011-06-03 30 views
15

我有3個選項可配置產品的實際價格價格差異,見下圖:替換在Magento配置的產品選項

enter image description here

我想更換+£24.00,並與在+£75.00產品的實際價格。

因此,而是會說:£69.00£和120.00

我已經找到了代碼被JS /瓦瑞恩/ product.js

我花了一點時間變化無常代碼,但不能完全解讀需要更改的內容。此文件中的第240行向下處理可配置產品的JavaScript事件。

我很感謝這裏的任何幫助。

回答

20

這是由javascript執行的。您需要修改js/varien/configurable.js中的方法getOptionLabel(這是Magento 1.5.1.0,您的milage可能會因您使用的版本而異)。

此方法收到選項和價格區別要應用。如果您只想顯示不同選項的絕對價格,則需要使用可配置產品的絕對基準值和選項的絕對差值自行計算。

方法的前幾行是這樣的:

getOptionLabel: function(option, price){ 
    var price = parseFloat(price); 

變化是讓您得到絕對的基準價和期權的絕對差值。然後將它們加在一起得到選項的最終絕對價格。像這樣:

getOptionLabel: function(option, price){ 
    var basePrice = parseFloat(this.config.basePrice); 
    // 'price' as passed is the RELATIVE DIFFERENCE. We won't use it. 
    // The ABSOLUTE DIFFERENCE is in option.price (and option.oldPrice) 
    var absoluteDifference = parseFloat(option.price); 
    var absoluteFinalPrice = basePrice + absoluteDifference; 
    // var price = parseFloat(price); 
    var price = absoluteFinalPrice; 

然後,你需要擺脫選項中的+和 - 符號。稍後在相同的方法中,當您調用this.formatPrice時,只需在每次調用中將第二個參數更改爲false即可。在JS /瓦瑞恩/ product.js創建

你會發現另一個叫Product.Config相同的對象:

if(price){ 
     if (this.taxConfig.showBothPrices) { 
      str+= ' ' + this.formatPrice(excl, false) + ' (' + this.formatPrice(price, false) + ' ' + this.taxConfig.inclTaxTitle + ')'; 
     } else { 
      str+= ' ' + this.formatPrice(price, false); 
     } 

這個一些更多的注意事項。據我所知,這完全沒有,因爲它被替換爲js/varien/configurable.js。

此外,如果只是更改js/varien/configurable.js,下次您升級Magento時,您可能會失去更改。最好創建另一個文件,如js/varien/my_configurable.js或其他,並在配置文件(產品)中調用它。xml)爲您使用的任何主題。

+1

+1。多謝。對於1個屬性選擇是很好的,但是當有兩個時,第二個屬性的價格顯示是錯誤的。 – 2013-01-22 00:13:41

+1

這對我來說並不適用於1.7 – 2013-06-25 04:07:24

+1

在Magento 1.7.2上試過這個如何使這項工作的任何提示。難以理解configurable.js – Josh 2013-08-13 02:59:09

4

這個擴展可能是有益的,我已經在過去使用它(這似乎是維持):

http://www.magentocommerce.com/magento-connect/Matt+Dean/extension/596/simple-configurable-products

+0

是的,1.4版本的任何線索都可以在1.7版本上正常工作? – Mike 2012-10-18 22:03:17

+1

找到了一個:https://github.com/organicinternet/magento-configurable-simple它的版本更新爲1.7,但需要手動安裝(下載然後上載),而不是使用Magento連接。 – Mike 2012-10-22 18:25:25

+0

github的1.9以及 – Mike 2014-09-17 21:15:29

0

編輯文件js/varien/product.js,看着行號691

如果我們要從產品詳細信息頁面更改屬性價格,觸發器將在此處觸發。只需檢查alert(price);,你可以得到可變的價格。

0

1.7(不知道這是什麼時候改變了)事情發生了變化。結果是價格字符串在PHP中,當從法師/目錄/塊/產品/視圖/選項/類型/選擇調用時,_formatPrice函數中的Mage/Catalog/Block/Product/View/Options/Abstract.php內部.PHP

注意,改變任何的2類是要去招惹通過該網站的變化,不只是在特定組合

0

我在如何Magento默認情況下可以使用這樣一個奇怪的邏輯驚訝。

應該可以看到每種變體的不同價格,甚至可以使用默認值。

Prestashop可以做到這一點,甚至可以在選擇每個變體時自動切換圖像!

4

在magento 1.9中,.js方法似乎不再適用。

取而代之,我更新了Abstract.php(/app/code/core/Mage/Catalog/Block/Product/View/Options/Abstract.php),將此文件複製到/ app/code/local/Mage/Catalog /塊/產品/查看/選項/ Abstract.php。上線128,改變$ _priceInclTax和$ _priceExclTax變量如下:

$_priceInclTax = $this->getPrice($sign.$value['pricing_value'], true)+$this->getProduct()->getFinalPrice(); 

$_priceExclTax = $this->getPrice($sign.$value['pricing_value'])+$this->getProduct()->getFinalPrice(); 

我見過類似的解決方案,但是這是唯一的辦法,以確保它也與事作品如負的產品選擇和特殊價格折扣。

+0

這在Magento 1.9.1.0中可以工作,但如果您有多個選項集合,則會帶來麻煩。無論如何它在我的情況下工作,所以我添加+1。 – 2015-11-26 19:07:26

1

找到一個解決方案here在Magento 1.9上工作,但它覆蓋了核心代碼,它應該這樣做,以便它不會覆蓋核心。

我在一個新的js文件中試過類似的東西,但不知怎的,核心configurable.js搞砸了,也許有人可以想出一種方式,使id沒有。

Product.Config.prototype.getOptionLabel = Product.Config.prototype.getOptionLabel.wrap(function(parentMethod){ 
// BEGIN:: custom price display update 
var basePrice = parseFloat(this.config.basePrice); 
// 'price' as passed is the RELATIVE DIFFERENCE. We won't use it. 
// The ABSOLUTE DIFFERENCE is in option.price (and option.oldPrice) 
var absoluteDifference = parseFloat(option.price); 
// var price = parseFloat(price); 
if(absoluteDifference){ 
    // console.log(option); 
    price = basePrice + absoluteDifference; 
} else { 
    price = absoluteDifference; 
} 
// END:: custom price display update 

if (this.taxConfig.includeTax) { 
    var tax = price/(100 + this.taxConfig.defaultTax) * this.taxConfig.defaultTax; 
    var excl = price - tax; 
    var incl = excl*(1+(this.taxConfig.currentTax/100)); 
} else { 
    var tax = price * (this.taxConfig.currentTax/100); 
    var excl = price; 
    var incl = excl + tax; 
} 

if (this.taxConfig.showIncludeTax || this.taxConfig.showBothPrices) { 
    price = incl; 
} else { 
    price = excl; 
} 

var str = option.label; 
if(price){ 
    if (this.taxConfig.showBothPrices) { 
     // BEGIN:: custom price display update 
     // NOTE:: 'true' was changed to 'false' in 3 places. 
     str+= ' ' + this.formatPrice(excl, false) + ' (' + this.formatPrice(price, false) + ' ' + this.taxConfig.inclTaxTitle + ')'; 
    } else { 
     str+= ' ' + this.formatPrice(price, false); 
     // END:: custom price display update 
    } 
} 
return str; 

});

0
在Magento 1.9

根據需要 開放JS /瓦瑞恩/ configurable.js 轉到功能getOptionLabel

修改該功能碼。

相關問題