Magento - 访问客户的愿望清单

Mat*_*man 9 magento

我希望能够加载客户的心愿单并返回列表中产品的产品ID

我在用:

$wishList = Mage::getSingleton('wishlist/wishlist')->loadByCustomer($customer);
$wishListItemCollection = $wishList->getItemCollection();
Run Code Online (Sandbox Code Playgroud)

问题是Item Collection中的数组受到保护,我找不到任何提取数据的方法.

还有另一种方法吗?

Kno*_*ing 17

你非常接近你的目标.

$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();
    }
}
Run Code Online (Sandbox Code Playgroud)

数组变量$arrProductIds现在将包含该特定客户所希望列出的所有产品ID的列表.

希望能帮助到你.

  • 你也可以简单地使用$ item-> getProductId(); - 无需加载整个产品. (2认同)

Ami*_*nki 7

你的代码是正确的.可能有客户未加载.这是代码.

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

foreach ($wishListItemCollection as $item)
{
   // do things
}
Run Code Online (Sandbox Code Playgroud)


Ign*_*ual 5

在任何模板中,使用magento 1.8,这都有效

Total: <?php echo $this->helper('wishlist')->getItemCount() ?>

// Items
$this->helper('wishlist')->getWishlist()->getItemCollection();
Run Code Online (Sandbox Code Playgroud)