0

I'm trying to get the multiple wishlist by customer_id, but not work

protected $wishlistCollectionFactory;

--constructor

    \Magento\Wishlist\Model\ResourceModel\Wishlist\CollectionFactory $wishlistCollectionFactory

.......

$this->wishlistCollectionFactory = $wishlistCollectionFactory;

actual code in controller

if ($action == "wishlist") {

            $customer_id = $this->customerSession->getCustomer()->getId();
            //var_dump($customer_id);
            $wishlistCollection = $this->wishlistCollectionFactory->create()->addFieldToFilter('customer_id', $customerId);;
            var_dump(json_encode($wishlistCollection));
            $result->setData(['error' => 0,
                    'message' => __('Operation Success'),
                    'wishlistCollection' => json_encode($wishlistCollection)
                ]
            );
            return $result;
        }

the output of wishlist is null, anyone know how to get the wishlist collection in commerce edition?

i want to get the all wishlist names.

1 Answer 1

0

changed to use

    \Magento\Wishlist\Model\Wishlist $wishlistModel

....

        $wishlist = $this->wishlistModel->getCollection()->addFieldToFilter('customer_id', $customer_id);
        //var_dump($wishlist);
        foreach ($wishlist as $list) {
            echo $list->getId().'__'.$list->getName()."<br>";
        }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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