【问题标题】:Price not updating in cart when the store is switched to another store当商店切换到另一家商店时,购物车中的价格未更新
【发布时间】:2015-05-05 12:37:37
【问题描述】:

我们已经安装了 magento1.9。在此站点中,我们提供具有多种选择的产品。我们为选项添加了自定义价格,并且效果很好。可以将具有自定义选项和总价的产品添加到购物车中。使用代码设置自定义价格

$quote_item->setOriginalCustomPrice($new_price['price'])

我的 magento 是具有不同货币的多语言商店。基准价格以英镑为单位。当我们将其切换到不同的商店时,购物车货币会更新但价格保持不变,它不会分别相对于商店货币减少或增加。

【问题讨论】:

    标签: magento


    【解决方案1】:

    您好,在 Magento 版本上遇到了同样的问题。 1.9.3.3。 为了解决,我在 controller_action_predispatch 上创建了一个观察者

    <frontend>
        <events>
            <controller_action_predispatch>
                <observers>
                    <updatecartonstorechange>
                        <type>singleton</type>
                        <class>megaobserver/Observer</class>
                        <method>updateCartOnStoreChange</method>
                    </updatecartonstorechange>                  
                </observers>
            </controller_action_predispatch>
        </events>
    </frontend>
    

    在方法中我检查了是否调用了商店更改,并强制更新了购物车:

    public function updateCartOnStoreChange(Varien_Event_Observer $observer)
    {
        $store = Mage::app()->getRequest()->getParam('___store', false);
        if(!($store===false)){
            $currentQuote = Mage::getSingleton('checkout/session')->getQuote();
            $items = $currentQuote->getAllVisibleItems();
            $cartData = Array();
            foreach ($items as $key =>$value) {
                $cartData[$value->getItemId()] = ['qty'=>$value->getQty()];
            }
            if(!empty($cartData)){
                $this->_updateShoppingCart($cartData);
            }
    
        }
    }
    

    【讨论】:

      【解决方案2】:

      Magento 中的价格是每个网站或全球的,而不是每个商店(视图)。但是,我认为这不是您的问题,我认为您的问题只是模板中用于在前端实际呈现价格的错误代码。

      您能否从您看到错误价格的页面的模板(.phtml 文件)中提供相应的代码?

      【讨论】:

        【解决方案3】:

        我遇到了同样的问题。添加自定义价格之前是根据高度和宽度设置的,并且在购物车中显示正确。但是在更改货币时,项目价格并没有改变。我正在使用checkout_cart_product_add_after 这个事件。我的代码就像

         public function updateProductCartPrice($observer, $new_price){
             $quote_item = $observer->getQuoteItem();
             $quote_item  = ( $quote_item->getParentItem() ? $quote_item ->getParentItem() : $quote_item  );
        
            if($new_price):
        
                $quote_item ->setCustomPrice($new_price);
                $quote_item ->setOriginalCustomPrice($new_price);
                $quote_item ->getProduct()->setIsSuperMode(true);
        
            endif;
        
          }
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2011-12-04
          • 1970-01-01
          • 2020-08-18
          • 2021-11-21
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多