Magento的愿望清单-删除项目 [英] Magento Wishlist - Remove item
问题描述
我已经构建了一个自定义脚本,可以使用AJAX向希望清单中添加和删除商品.添加产品不是问题,但我不知道如何删除商品.Magento 版本是 1.5.1.0
.
I've built a custom script to add and remove items to the wishlist using AJAX. Adding products is not a problem but I can't figure out how to remove an item. The Magento version is 1.5.1.0
.
该脚本位于/scripts/
中,如下所示:
The script is in /scripts/
and looks like this:
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);
}
因此,当我请求脚本"remove"为 $ type
且愿望清单项ID为$ id时,会出现以下错误:
So when I request the script with "remove" as $type
and the wishlist item id as $id I get the following error:
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
当我查看/app/code/core/Mage/Wishlist/Model/Wishlist.php
中的函数 updateItem()
时,它会期望"buyRequest",但我不知道那是什么.
When I look at the function updateItem()
in /app/code/core/Mage/Wishlist/Model/Wishlist.php
it expects a "buyRequest", but I can't figure out what that is.
推荐答案
我没有时间调试您的代码中出现的任何问题,但是使用删除实体的常规约定应该可以:
I have no time to debug whatever goes wrong with your code, but using the normal convention of deleting entities should work:
Mage::getModel('wishlist/item')->load($id)->delete();
这篇关于Magento的愿望清单-删除项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!