我在magento面临问题。将产品添加到购物车时,它会成功添加一个项目,但是当我尝试添加另一个项目时,它会删除上一个项目并添加新项目。这是因为引号ID每次都会更改,关闭浏览器或其他任何内容。
知道如何解决此问题吗?
答案 0 :(得分:0)
你可以在这个函数中调试
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;
}
希望它会帮助你!!!