如何使用magento中的产品检索用户心愿单

时间:2014-04-25 13:28:41

标签: php magento

我正在使用magento编写REST API,以检索用户的愿望清单及产品详细信息。下面的代码写了null结果。任何人都可以提出什么问题?

$customer = Mage::getSingleton('customer/session')->getCustomer();
$wishList = Mage::getSingleton('wishlist/wishlist')->loadByCustomer($customer);
$wishListItemCollection = $wishList->getItemCollection();

if (count($wishListItemCollection)) 
{
$arrProductIds = array();

foreach ($wishListItemCollection as $item) {
    /* @var $product Mage_Catalog_Model_Product */
    $product = $item->getProduct();
    $arrProductIds[] = $product->getId();
}

}

1 个答案:

答案 0 :(得分:1)

试试此代码

$customer = Mage::getModel('customer/customer')->getCollection()->addAttributeToSelect('*');
$wishList = Mage::getSingleton('wishlist/wishlist')->loadByCustomer($customer);
$wishListItemCollection = $wishList->getItemCollection();

if (count($wishListItemCollection)) {
    $arrProductIds = array();

    foreach ($wishListItemCollection as $item) {
        /* @var $product Mage_Catalog_Model_Product */
        $product = $item->getProduct();
        $arrProductIds[] = $product->getId();
    }
}