马真托添加到购物车问题



我在洋红色中遇到了问题。将产品添加到购物车时,它成功添加了一个项目,但是当我尝试添加另一个项目时,它会删除前一个项目并添加新项目。这是因为报价 ID 每次都会更改,关闭浏览器或其他任何内容。

知道如何解决这个问题吗?

你可以在这个函数中调试

app\code\core\mage\checkout\model\Cart.php

并找到此函数

 public function save()
{
    Mage::dispatchEvent('checkout_cart_save_before', array('cart'=>$this));
    $this->getQuote()->getBillingAddress();
    $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
    $this->getQuote()->collectTotals();
    $this->getQuote()->save();
    $this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());
    /**
     * Cart save usually called after changes with cart items.
     */
    Mage::dispatchEvent('checkout_cart_save_after', array('cart'=>$this));
    return $this;
}

您可以在此处进行调试。 希望这对你有帮助。

我已经为自定义价格编辑了此代码

      public function save()
                          {
            Mage::dispatchEvent('checkout_cart_save_before', array('cart'=>$this));
        $this->getQuote()->getBillingAddress();
                    $this->getQuote()->getShippingAddress()->setCollectShippingRates(true);
                    $this->getQuote()->collectTotals();
                   // $this->getQuote()->save();
                    if(isset($_POST['product']))
                    $pid=$_POST['product'];
                    if(isset($_POST['npn']))
                    $new_price=$_POST['npn'];
                    foreach($this->getQuote()->getAllItems() as $item) {    
                        $productId = $item->getProductId();     
                        $product = Mage::getModel('catalog/product')->load($productId);
                        if(isset($pid))
                        {
                        if($productId==$pid)
                        {
                        if(isset($_POST['npn']) && $_POST['npn']!='')
                        {
                        $price = $_POST['npn'];
                        $item->setCustomPrice($price);
                        // we need this since Magento 1.4
                        $item->setOriginalCustomPrice($price);
                        }
                        }
                        }
                    }  
                    $this->getQuote()->save();
                    $this->getCheckoutSession()->setQuoteId($this->getQuote()->getId());
                    /**
                     * Cart save usually called after changes with cart items.
                     */
                    Mage::dispatchEvent('checkout_cart_save_after', array('cart'=>$this));
                    return $this;
                }

希望对您有所帮助!!

最新更新