[英]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.