2

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();
                    }
                }
            }
  • Please check my answer and let me know if still not solve. – Rohan Hapani Oct 16 '18 at 6:26
0

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;
    }
}
| improve this answer | |
0

Try to use this below code :

$customer = Mage::getSingleton('customer/session')->getCustomer();
if($customer->getId()){
$wishList = Mage::getSingleton('wishlist/wishlist')->loadByCustomer($customer,true);
$wishListItemCollection = $wishList->getItemCollection();

if (count($wishListItemCollection)) {
    $arrProductIds = array();

    foreach ($wishListItemCollection as $item) {
        /* @var $product Mage_Catalog_Model_Product */
        $product = $item->getProduct();
        $arrProductIds[] = $product->getId();
    }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.