9

顧客のウィッシュリストを読み込んで、リスト内の製品の製品 ID を返すことができるようにしたいと考えています

私は使っている:

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

問題は、アイテム コレクション内の配列が保護されており、データを抽出する方法が見つからないことです。

これを行う別の方法はありますか?

4

5 に答える 5

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 のリストが含まれます。

于 2012-04-04T06:54:06.680 に答える
2
$wishList = Mage::getSingleton('wishlist/wishlist')->loadByCustomer($customer);
$wishListItemCollection = $wishList->getItemCollection();

foreach ($wishListItemCollection as $item)
{
    //do your thing e.g. echo $item->getName();
}
于 2012-04-04T06:54:18.957 に答える
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; } } ?> 
于 2014-03-22T06:54:13.853 に答える