我构建了一个自定义脚本,用于使用 AJAX 在愿望清单中添加和删除项目。添加产品不是问题,但我不知道如何删除项目。 Magento 版本是1.5.1.0
.
脚本位于/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()
in /app/code/core/Mage/Wishlist/Model/Wishlist.php
它需要一个“buyRequest”,但我不知道那是什么。
我没有时间调试代码中出现的任何问题,但是使用删除实体的正常约定应该可以:
Mage::getModel('wishlist/item')->load($id)->delete();
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)