Magento - 访问客户的愿望清单



我希望能够加载客户的愿望列表,并返回列表中产品的产品id

我正在使用:

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

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

有别的办法吗?

你离目标很近了。

$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的列表。

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

$customer = Mage::getSingleton('customer/session')->getCustomer();
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customer, true);
$wishListItemCollection = $wishlist->getItemCollection();
foreach ($wishListItemCollection as $item)
{
   // do things
}

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

Total: <?php echo $this->helper('wishlist')->getItemCount() ?>
// Items
$this->helper('wishlist')->getWishlist()->getItemCollection();
$wishList = Mage::getSingleton('wishlist/wishlist')->loadByCustomer($customer);
$wishListItemCollection = $wishList->getItemCollection();
foreach ($wishListItemCollection as $item)
{
    //do your thing e.g. echo $item->getName();
}

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

<?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; } } ?> 

最新更新