我成功地使用此jQuery脚本更改此页面上"price"类的值:
jQuery("#options_46_2").click(function(){
var priceOldValue = parseInt(jQuery('.product-options-bottom .price-box .price').text().replace(/[^0-9.]/g, ""));
if (this.checked) {
var selectedWeight = jQuery("#select_32 option:selected").text();
selectedWeight = parseFloat(selectedWeight);
var priceNewValue = priceOldValue + 50 * selectedWeight;
jQuery(".product-options-bottom .price-box .price").html("Rs" + priceNewValue + ".00");
}
else {
jQuery(".product-options-bottom .price-box .price").html("Rs" + priceOldValue + ".00");
}
});
现在,我希望此更改的值是用户单击"添加到购物车"按钮时产品价格的实际值。我应该怎么做?
另外,对于其他产品,还有什么更优雅的方法可以做到这一点吗?
[编辑]
然后,您可以使用观察者创建一个模块并在产品添加到购物车后在此事件触发sales_quote_add_item
添加事件来实现此目的
在您的观察器中,您可以获取产品价格并选中选项是否选中,如果选项被选中,然后您可以使用
$quote_item->setOriginalCustomPrice($Custom price)