【发布时间】:2015-02-13 12:42:14
【问题描述】:
我在我的 Magento 商店中为我的产品创建了一些自定义选项。这些自定义选项的定价取决于一些 CSV 电子表格,这些电子表格以自定义表格的形式插入到 Magento 数据库中。 我已经设法改变了前端的价格(使用 Javascript),但是当我点击 BUY 按钮时,Magento 的价格会覆盖我的价格。
如何告诉 Magento 根据自定义选项使用我的价格而不使用默认选项?下面是我的 Javascript 代码。 我找到了控制前端价格的文件 options.html,至少在继续购物车步骤之前是这样。在代码结束之前可以找到我对文件的补充。
Product.Options = Class.create();
Product.Options.prototype = {
initialize : function(config) {
this.config = config;
this.reloadPrice();
document.observe("dom:loaded", this.reloadPrice.bind(this));
},
reloadPrice : function() { var myprice = 0;
var config = this.config;
var skipIds = [];
$$('body .product-custom-option').each(function(element){
var optionId = 0;
element.name.sub(/[0-9]+/, function(match){
optionId = parseInt(match[0], 10);
});
if (config[optionId]) {
var configOptions = config[optionId];
var curConfig = {price: 0};
if (element.type == 'checkbox' || element.type == 'radio') {
if (element.checked) {
if (typeof configOptions[element.getValue()] != 'undefined') {
curConfig = configOptions[element.getValue()];
}
}
} else if(element.hasClassName('datetime-picker') && !skipIds.include(optionId)) {
dateSelected = true;
$$('.product-custom-option[id^="options_' + optionId + '"]').each(function(dt){
if (dt.getValue() == '') {
dateSelected = false;
}
});
if (dateSelected) {
curConfig = configOptions;
skipIds[optionId] = optionId;
}
} else if(element.type == 'select-one' || element.type == 'select-multiple') {
if ('options' in element) {
$A(element.options).each(function(selectOption){
if ('selected' in selectOption && selectOption.selected) {
if (typeof(configOptions[selectOption.value]) != 'undefined') {
/* csv pricing */
curConfig = configOptions[selectOption.value];
curConfig1 = configOptions[selectOption.value];
//console.log(curConfig1);
if(curConfig1.type !='fixed')
{
current = nextbitscustomprice.getCurrentPrice();
currentPercent = curConfig1.priceValue;
if(current !='undefined'){
now = current*currentPercent /100;
curConfig.price =now;
curConfig.excludeTax =now;
curConfig.includeTax =now;
myprice = current;
console.log('first'+curConfig);
}
}
/* csv pricing */
}
}
});
}
} else {
if (element.getValue().strip() != '') {
curConfig = configOptions;
}
}
if(element.type == 'select-multiple' && ('options' in element)) {
$A(element.options).each(function(selectOption) {
if (('selected' in selectOption) && typeof(configOptions[selectOption.value]) != 'undefined') {
if (selectOption.selected) {
curConfig = configOptions[selectOption.value];
} else {
curConfig = {price: 0};
}
/* csv pricing */
if(element.type == 'select-multiple' && selectOption.selected){
curConfig1 = configOptions[selectOption.value];
//console.log(curConfig1);
if(curConfig1.type !='fixed')
{
current = nextbitscustomprice.getCurrentPrice();
currentPercent = curConfig1.priceValue;
if(current !='undefined'){
now = current*currentPercent /100;
curConfig.price =now;
curConfig.excludeTax =now;
curConfig.includeTax =now;
myprice = current;
console.log('second'+curConfig);
}
}
}
/* csv pricing */
optionsPrice.addCustomPrices(optionId + '-' + selectOption.value, curConfig);
optionsPrice.reload();
}
});
} else {
if (element.type == 'checkbox' || element.type == 'radio' ) {
if (element.checked) {
if (typeof configOptions[element.getValue()] != 'undefined') {
curConfig1 =configOptions[element.getValue()];
//console.log(curConfig1);
if(curConfig1.type !='fixed')
{
current = nextbitscustomprice.getCurrentPrice();
currentPercent = curConfig1.priceValue;
if(current !='undefined'){
now = current*currentPercent /100;
curConfig.price =now;
curConfig.excludeTax =now;
curConfig.includeTax =now;
myprice = current;
console.log('third'+curConfig);
}
}
}
}
}
optionsPrice.addCustomPrices(element.id || optionId, curConfig);
optionsPrice.reload();
}
}
//Global Javascript object
var addedPriceFromMyTableInDB = 12;
optionsPrice['productPrice'] += addedPriceFromMyTableInDB;
var myPrice = optionsPrice['productPrice'] + addedPriceFromMyTableInDB;
console.log('price '+myPrice);
jQuery('span.price').text(myPrice+',00 €');
});
}
}
【问题讨论】:
标签: javascript php magento