我已經構建了一個自定義腳本,使用AJAX將項目添加到願望清單並將其刪除。添加產品不是問題,但我無法弄清楚如何刪除一個項目。 Magento版本是1.5.1.0
。Magento Wishlist - 刪除項目
腳本是/scripts/
,看起來像這樣:
include_once '../app/Mage.php';
Mage::app();
try{
$type = (!isset($_GET['type']))? 'add': $_GET['type'];
$id = (!isset($_GET['id']))? '': $_GET['id'];
$session = Mage::getSingleton('core/session', array('name'=>'frontend'));
$_customer = Mage::getSingleton('customer/session')->getCustomer();
if ($type != 'remove') $product = Mage::getModel('catalog/product')->load($id);
$wishlist = Mage::helper('wishlist')->getWishlist();
if ($id == '')
exit;
if ($type == 'add')
$wishlist->addNewItem($product);
elseif ($type == 'remove')
$wishlist->updateItem($id,null,array('qty' => 0));
$products = Mage::helper('wishlist')->getItemCount();
if ($type == 'add') $products++;
if ($type == 'remove') $products--;
$result = array(
'result' => 'success',
'type' => $type,
'products' => $products,
'id' => $id
);
echo json_encode($result);
}
catch (Exception $e)
{
$result = array(
'result' => 'error',
'message' => $e->getMessage()
);
echo json_encode($result);
}
所以,當我要求腳本「刪除」爲$type
和心願列表項ID爲$ ID,我得到以下錯誤:
Fatal error: Call to a member function getData() on a non-object in /[magento path]/app/code/core/Mage/Catalog/Helper/Product.php on line 389
當我看updateItem()
在/app/code/core/Mage/Wishlist/Model/Wishlist.php
功能,它期待一個「buyRequest」,但我不明白這是什麼。
要在Magento使用Ajax願望清單中移除的產品,我創建了一個自定義的function.For更多詳情,請參閱:http://prasadoturkar.blogspot.in/2013/06/addremove-product-from-wishlist- using.html –