Can I check if a product is in my wishlist? If yes, how?
Best Answer
Option one. Seams cleaner.
$productId = 1;
$product = Mage::getModel('catalog/product')->setStoreId(Mage::app()->getStore()->getId())->load($productId)
$customerId = Mage::getSingleton('customer/session')->getCustomerId();
$wishlist = Mage::getModel('wishlist/wishlist')->loadByCustomer($customerId, true);
$hasProduct = false;
foreach ($wishlist->getItemCollection() as $_item) {
if ($_item->representProduct($product)) {
$hasProduct = true;
break;
}
}
//$hasProduct tells you if the product is in the wishlist
One way to do this would be to create your own controller and action that will take the same information add to the wishlist but simply return a json response with success or a failure message.
In this way you can skip all the redirect stuff and work with a simply ajax action.
Another approach in order to retrieve wishlist or custumer related information, is to use localStorage combined with Ajax request if the localstorage is empty.
Best Answer
Option one. Seams cleaner.
//Option 2. Seams faster