【问题标题】:Magento add to cart issueMagento 添加到购物车问题
【发布时间】:2015-04-21 17:10:36
【问题描述】:

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

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

【问题讨论】:

  • 您是否检查了对 var/session 文件夹的权限?
  • 是的,我尝试将 777 设置为 var 和 var/session 文件夹,但没有成功。
  • 这种情况很多,所以需要检查所有扩展,尝试一个一个禁用它们并检查,还要检查从管理员设置的cookie生命时间
  • 检查您如何创建销售报价。是没有登录还是登录?清除缓存?
  • 这意味着每次报价都已创建。检查会话和 cookie 在 admn 设置

标签: php magento session cookies


【解决方案1】:

你可以在这个函数中调试

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

希望对你有帮助!!!

【讨论】:

  • echo($this->getQuote()->getId());exit;通过点击添加到购物车按钮价值增加一
  • 如何设置适用于整个网站的报价 ID 自定义?
  • echo($this->getQuote()->getId());exit;通过单击添加到购物车按钮,价值增加一.. 这意味着每次都会重新生成会话.. 知道如何阻止会话重新生成
  • 问题出在这个函数上: public function getQuote() { if (!$this->hasData('quote')) { /// this retrun false so it set new,,, $ this->setData('quote', $this->getCheckoutSession()->getQuote()); } return $this->_getData('quote');似乎有些地方价值未设置,,,
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-09
  • 1970-01-01
  • 1970-01-01
  • 2011-08-21
  • 2015-12-13
  • 1970-01-01
相关资源
最近更新 更多