问题遇到的现象和发生背景
用的magento的gifts插件
问题相关代码,请勿粘贴截图
class Belvg_Gifts_IndexController extends Mage_Core_Controller_Front_Action
{
public function addAction()
{
if ($this->getRequest()->isGet()) {
$gift_id = $this->getRequest()->getParam('gift', 0);
if ($gift_id) {
if (!Mage::helper('gifts')->isGiftUsed() && in_array($gift_id, Mage::helper('gifts')->getGiftsIds())) {
$quote = Mage::getSingleton('checkout/session')->getQuote();
$cart = Mage::getModel('checkout/cart');
$product = new Mage_Catalog_Model_Product();
$product->load($gift_id);
$cart->addProduct($product, 1);
$cart->save();
foreach ($quote->getAllItems() as $item) {
if ($item->getProductId() == $gift_id) {
$item->setCustomPrice(0);
$item->setOriginalCustomPrice(0);
}
}
$cart->init();
$cart->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
}
}
}
$this->_redirect('checkout/cart');
}
}