嘗試下面的代碼。我已經在magento 1.9下測試過,像魅力一樣工作
<?php
// result buffer
$result = array();
// init magento
require_once('app/Mage.php');
umask(0);
Mage::app('default');
// init session
Mage::getSingleton('core/session', array('name'=>'frontend'));
$session = Mage::getSingleton('customer/session', array('name'=>'frontend'));
// get wishlist if logged in
if ($session->isLoggedIn()) {
$wishList = Mage::getSingleton('wishlist/wishlist')->loadByCustomer($session->getCustomer());
$wishListItemCollection = $wishList->getItemCollection();
foreach ($wishListItemCollection as $item)
{
$result[] = array(
'name' => $item->getName(),
'id' => $item->getId(),
'price' => $item->getPrice(),
'qty' => $item->getQty()
);
}
}
// return
header('Cache-Control: no-cache, must-revalidate');
header('Expires: Mon, 26 Jul 1997 05:00:00 GMT');
header('Content-Type: application/json');
echo json_encode($result);