简体   繁体   English

Magento添加到购物车问题

[英]Magento add to cart issue

I am facing problem in magento. 我在magento中面临问题。 When adding products to cart, it successfully adds one item but when I try to add another item it removes the previous item and adds the new item. 将产品添加到购物车时,它会成功添加一个项目,但是当我尝试添加另一个项目时,它将删除前一个项目并添加新项目。 This is because the quote id changes every time, with closing browser or anything else. 这是因为在关闭浏览器或其他任何操作时,引用ID每次都会更改。

Any idea how to resolve this issue? 任何想法如何解决这个问题?

you can debug in this function 您可以在此功能中调试

app\\code\\core\\Mage\\Checkout\\Model\\Cart.php app \\ code \\ core \\ Mage \\ Checkout \\ Model \\ Cart.php

and find this function 并找到这个功能

 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;
}

you can debug here. 您可以在这里进行调试。 hope this will help you. 希望这会帮助你。

I have edit this code for custom price 我已将此代码修改为自定义价格

      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;
                }

hope it will help you !!! 希望对你有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM