Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Magento - Accessing a customer's wishlist

Tags:

magento

I would like to be able to load a customer's wishlist and return the product id's of the products within the list

I am using:

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

The problem is that the arrays in the Item Collection are protected and I can't find any methods to extract the data.

Is there another way to do this?

like image 486
Matthew Dolman Avatar asked Apr 04 '12 05:04

Matthew Dolman


People also ask

How do I get a customer order list in Magento 2?

The customer id is required to fetch the customer placed Order collection in Magento 2. Get Customer Order collection, We have to create a factory object of Magento\Sales\Model\ResourceModel\Order\Collection class. Instantiate the Factory object to the __consturct() method and apply condition with customer id.

How do I add a wishlist in Magento 2?

From the Admin panel, select System > Configuration. In the Configuration panel on the left, under Customers, select the Wishlist tab. Click to expand the General Options section and do one of the following: Set Enabled to Yes to display the Add to Wishlist link on category pages and product pages.

How do I find my Magento wishlist ID 2?

You can get wishlist collection of a customer by customer id. You can show detail of Customer Wishlist item in a store. Get Wishlist collection by calling Magento\Wishlist\Model\Wishlist Model file.


1 Answers

You're very close to your target.

$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();
    }
}

The array variable $arrProductIds will now contain the list of all Product IDs that have been wishlisted by that specific Customer.

like image 53
Knowledge Craving Avatar answered Oct 10 '22 10:10

Knowledge Craving