使用 Magento opConfig.reloadPrice() 和 jQuery 和 Custom 选项


Use Magento opConfig.reloadPrice() with jQuery and Custom options

我正在尝试将Magento reloadPrice()与jQuery一起使用来刷新价格。我有一个带有自定义选项的可配置产品。如果没有 jQuery,该选项的SELECT代码是:

<select id="select_281" class=" required-entry product-custom-option" title="" name="options[281]" onchange="opConfig.reloadPrice()">
<option value="0"></option>
<option rel="1" price="0" value="275"></option>
<option rel="2" price="0" value="276"></option>
</select>

使用jQuery,我删除了原型onchange代码,并尝试计算我的选项的价格(例如50美元):

jQuery('#select_281').removeAttr('onchange').change(function(){
//Price of the option to add to a basic price of the conf product
price = 50;
optionsPrice.changePrice('opConfig', price);
optionsPrice.reload();
});

可配置产品的价格: $150 .

添加一个选项(SELECT):我们添加$50

新的价格$200显示在产品页面中,但不显示在购物车页面中:购物车页面仅显示 150 美元,这是不正确的。

有人可以帮忙吗?

此致敬意.COM。

reloadPrice() 不能更改任何服务器端的价格。因此,我们通过使用 2 个观察器解决了这个问题:checkout_cart_product_add_after观察者在第一次将产品添加到购物车时更改价格,checkout_cart_update_items_after观察者更改购物车中每件商品的价格(当用户单击购物车页面上的"修改购物车"按钮时)。

此处的代码测试了具有 2 个自定义选项颜色编号和雕刻类型的可配置产品。对于每对颜色/雕刻类型,我们将分层价格存储在特殊的MySQL表中,我们可能会使用自定义价格更改价格。每个简单的产品都有其层价格。

<code>//checkout_cart_product_add_after observer
   public function modifyPrice(Varien_Event_Observer $observer)
    {
        $item = $observer->getQuoteItem();
        $item = ( $item->getParentItem() ? $item->getParentItem() : $item );
        $productType = $product->getTypeID();
        $price = 100;//Unit price of product without engraving, 100 for example
        //Unit price with engraving, depending of 2 custom options of configurable product
        if($productType == 'configurable'){
            //get custom options of config here
            .
            .
            $engravingPrice = 1.2;//Get unit price with engraving from a special MySQL table
            $finalUnitPrice = $price + $engravingPrice;//Final custom price
            //Modify the price
            $item->setCustomPrice($finalUnitPrice);
            $item->setOriginalCustomPrice($finalUnitPrice);
            $item->getProduct()->setIsSuperMode(true);
        }
    }
    //checkout_cart_update_items_after observer
    public function modifyCartItems(Varien_Event_Observer $observer)
    {
        foreach ($observer->getCart()->getQuote()->getAllVisibleItems() as $item ) {
            if ($item->getParentItem()) {$item = $item->getParentItem();}
            $productType = $product->getTypeID();
            $productType = $product->getTypeID();
            $price = 100;//Unit price of product without engraving
            //Unit price with engraving, depending of 2 custom options of configurable product
            if($productType == 'configurable'){
                .
                .
                $engravingPrice = 1.2;//Get unit price with engraving from a special MySQL table
                $finalUnitPrice = $price + $engravingPrice;//Final custom price
                //Modify the price for the item
                $item->setCustomPrice($finalUnitPrice);
                $item->setOriginalCustomPrice($finalUnitPrice);
                $item->getProduct()->setIsSuperMode(true);
            }
        }
    }</code>

但。。。。。一个问题仍然存在:在购物车页面上,当用户单击"编辑"链接以编辑产品页面中的产品时,他可以更改数量,...并点击"更新购物车"按钮,此更新按钮不会读取刷新价格checkout_cart_product_add_after。

不知道如何强制此"更新购物车"操作来处理checkout_cart_product_add_after观察器中的代码?此代码是否仅在产品首次添加到购物车时执行?

谢谢。

.COM