问题描述
我有一个带有3个选项的可配置产品,请参见下文:
I have a configurable product with 3 options, see below:
我想用产品的实际价格代替+24.00英镑和+75.00英镑.
I want to replace the +£24.00 and the +£75.00 with the actual prices of the products.
因此,它会说:69.00英镑和120.00英镑
So instead it would say: £69.00 and £120.00
我在 js/varien/product.js
我花了一些时间来修改代码,但无法完全理解需要更改的内容.该文件中向下的第240行处理可配置产品的JavaScript事件.
I've spent a bit of time chopping and changing the code, but can't quite decipher what needs to change. Line 240 downwards in this file handles the JavaScript events for configurable products.
在此感谢您的帮助.
推荐答案
这是由javascript执行的.您需要修改js/varien/configurable.js中的getOptionLabel方法(这是Magento 1.5.1.0,里程数可能会因所使用的版本而异).
This is performed by javascript. You need to modify the method getOptionLabel in js/varien/configurable.js (this is Magento 1.5.1.0, your milage may vary depending on the version you're using).
此方法接收期权和要应用的价格差异.如果您只想显示不同期权的绝对价格,则需要使用可配置产品的绝对基值和期权的绝对差来自己计算它们.
This method receives the option and the price difference to be applied. If you want to just show the absolute price of the different options, you need to calculate them yourself, using the absolute base value of the configurable product and the absolute difference of the option.
该方法的前几行如下:
getOptionLabel: function(option, price){
var price = parseFloat(price);
进行更改,以获得绝对基准价格和期权的绝对差额.然后将它们加在一起以获得期权的最终绝对价格.像这样:
Change that so you get the absolute base price and the absolute difference of the option. Then add them together to get the final absolute price of the option. Like this:
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.
Then you need to get rid of the + and - symbols in the options. Later on in the same method, when you call this.formatPrice, just change the second paramter to false in each call.
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/product.js中找到另一个名为Product.Config的相同对象.据我所知,这绝对不起作用,因为它已被js/varien/configurable.js取代.
You will find another identical object called Product.Config being created in js/varien/product.js. As far as I can tell, this does absolutely nothing as it is replaced by js/varien/configurable.js.
此外,如果仅更改js/varien/configurable.js,则下次升级Magento时,您可能会丢失所做的更改.最好创建另一个文件,例如js/varien/my_configurable.js或其他文件,然后在配置文件(product.xml)中针对您使用的任何主题对其进行调用.
Also, if just change js/varien/configurable.js, the next time you upgrade Magento you will probably lose your changes. Better to create another file like js/varien/my_configurable.js or whatever, and call it in the config file (product.xml) for whatever theme you are using.
这篇关于用Magento可配置产品选项中的实际价格替换价格差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!