如果你想在Magento客户端获取可配置产品里被选中的简单产品,你有很多种不同的方法。 这里有一种简单的方法,不用代码修改,不要新的模版甚至模。值需要一个Java脚本和布局更新。 Product.Config.prototype.getIdOfSelectedProduct = function() { var existingProducts = new Object(); for(var i=this.settings.length-1;i>=0;i--) { var selected = this.settings[i].options[this.settings[i].selectedIndex]; if(selected.config) { for(var iproducts=0;iproducts<selected.config.products.length;iproducts++) { var usedAsKey = selected.config.products[iproducts]+""; if(existingProducts[usedAsKey]==undefined) { existingProducts[usedAsKey]=1; } else { existingProducts[usedAsKey]=existingProducts[usedAsKey]+1; } } } } for (var keyValue in existingProducts) { for ( var keyValueInner in existingProducts) { if(Number(existingProducts[keyValueInner])<Number(existingProducts[keyValue])) { delete existingProducts[keyValueInner]; } } } var sizeOfExistingProducts=0; var currentSimpleProductId = ""; for ( var keyValue in existingProducts) { currentSimpleProductId = keyValue; sizeOfExistingProducts=sizeOfExistingProducts+1 } if(sizeOfExistingProducts==1) { alert("Selected product is: "+currentSimpleProductId) } }(责任编辑:最模板) |