Magento 1.9 – How to Get Wishlist Collection Using Customer ID

magento-1.9wishlist

I am trying to get the wish list products in Magento 1.9, I am facing some problem. Based on customer id am fetching customer details, Unable to fetch the wishlist product collections.

$customer_id= 4;
            $customer = Mage::getSingleton('customer/customer')->load($customer_id);
            if($customer){
                $wishList = Mage::getSingleton('wishlist/wishlist')->loadByCustomer($customer);
                print_r($wishList);
                $wishListItemCollection = $wishList->getItemCollection();
                if (count($wishListItemCollection)) {
                    $arrProductIds = array();
                    foreach ($wishListItemCollection as $item) {
                        $product = $item->getProduct();
                        $arrProductIds[] = $product->getId();
                    }
                }
            }

Best Answer

I assume that the customer ID is 1 and you want tot get the wishlsit items of the customer having the customer ID 1.

Please use the code like below:

<?php

class Stack_Wishlistitems_IndexController extends Mage_Core_Controller_Front_Action {

    public function indexAction() {
        $customerId = 4;
        $customer = Mage::getSingleton('customer/customer')->load($customerId);

        $wishlistItems = Mage::getModel('wishlist/item')->getCollection()
                ->setWebsiteId($customer->getWebsiteId())
                ->setCustomerGroupId($customer->getGroupId());
        echo "<pre>";print_r($wishlistItems->getData());exit;
    }
}
Related Topic