2012-03-08 78 views
1

在Magento的PHP控制器,我怎麼能得到包含在登錄用戶的(即當前的用戶)收藏所列產品中的產品系列。Magento的 - 產品系列與當前用戶的收藏

我正在使用的心願:

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

,這包含的項目數正確。

但我想要一個產品集合。我曾嘗試:

$productCollection = $wishList->getProductCollection(); 

$productCollection = $wishList->getProductCollection()->addAttributeToSelect('id')->load(); 

但產品系列,我得到具有0

的長度如何獲得的產品系列?

+0

我使用的Magento 1.6 – mas 2012-03-08 18:54:23

回答

3

您可以使用getWishlistItemCollection(見鏈接瞭解詳細信息)關閉心願助手返回項目的集合,那麼你需要從該項目獲得的產品。

我一直在使用下面的代碼來創建產品,然後我用它來確定,如果我在列表頁顯示產品是在心願的關聯數組...希望這將有助於:

public function getWishList() { 
    $_itemCollection = Mage::helper('wishlist')->getWishlistItemCollection(); 
    $_itemsInWishList = array(); 

    foreach ($_itemCollection as $_item) { 
     $_product = $_item->getProduct(); 

     $_itemsInWishList[$_product->getId()] = $_item; 
    } 

    return $_itemsInWishList; 
} 
3

與產品試試這個名字像所有的細節,圖像等...

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

$客戶=法師:: getSingleton( '客戶/會話') - > GETCUSTOMER();

$心願=法師:: getModel( '心願/願望清單') - > loadByCustomer($顧客,TRUE);

$ wishListItemCollection = $ wishlist-> getItemCollection();

的foreach($ wishListItemCollection爲$項目) {// 做事 }

相關問題