[英]Magento add to cart issue
我在magento中面临问题。 将产品添加到购物车时,它会成功添加一个项目,但是当我尝试添加另一个项目时,它将删除前一个项目并添加新项目。 这是因为在关闭浏览器或其他任何操作时,引用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;
}
希望对你有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.