Magento - 访问客户的愿望清单

时间:2012-04-04 05:07:51

标签: magento

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

我正在使用:

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

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

还有其他办法吗?

5 个答案:

答案 0 :(得分: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();
    }
}

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

希望它有所帮助。

答案 1 :(得分:7)

您的代码是正确的。可能有客户未加载。这是代码。

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

foreach ($wishListItemCollection as $item)
{
   // do things
}

答案 2 :(得分:5)

在任何模板中,使用magento 1.8,都可以使用

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

// Items
$this->helper('wishlist')->getWishlist()->getItemCollection();

答案 3 :(得分:2)

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

foreach ($wishListItemCollection as $item)
{
    //do your thing e.g. echo $item->getName();
}

答案 4 :(得分:2)

尝试使用产品所有细节,如名称,图像等......

<?php
 $customer = Mage::getSingleton('customer/session')->getCustomer();
 if($customer->getId())
{
     $wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer, true);
     $wishListItemCollection = $wishlist->getItemCollection();
     foreach ($wishListItemCollection as $item)
     {
           echo $item->getName()."</br>";
           echo $item->getId()."</br>";
           echo $item->getPrice()."</br>";
           echo $item->getQty()."</br>";  
           $item = Mage::getModel('catalog/product')->setStoreId($item->getStoreId())->load($item->getProductId());
          if ($item->getId()) :
?>
<img src="<?php echo Mage::helper('catalog/image')->init($item, 'small_image')->resize(113, 113); ?>" width="113" height="113" />
<?php endif; } } ?>