Я создал собственный скрипт для добавления и удаления элементов в список желаний с помощью 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, я получаю следующую ошибку:
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", но я не могу понять, что это такое.