0

I have a product id but i want to know the wishlist id according to that product id. Is there any way to find that wish list corresponding that productid?

6
  • your question is unable to understand please specify in detail. Jan 4 '16 at 7:29
  • is there any way to get wishlist id according to the product id? Jan 4 '16 at 8:35
  • Give you update. Jan 4 '16 at 8:46
  • Get by customer? Jan 4 '16 at 8:47
  • no get by product_id Jan 4 '16 at 8:50
1

Try this:

$productId =1;
$wishlistItem = Mage::getModel('wishlist/item')->getCollection()
    ->addFieldToFilter('product_id',$productId);
if(count($wishlistItem)) {
    $wishlistIds = $wishlistItem->getColumnValues('wishlist_id');
    print_r($wishlistIds);
}


//OR

if(count($wishlistItem)) {
    echo $wishlistId = $wishlistItem->getFirstItem()->getWishlistId();
}
2
  • i am already using this is there any way to get wishlist id without using foreach Jan 4 '16 at 9:17
  • update ans pls check now
    – Abdul
    Jan 4 '16 at 9:22
0

Not sure to fully understand the question but there is no function to get all wishlist IDs linked to a product.
The way to do that is make a query in wishlist_item table.
For example : SELECT wishlist_id FROM wishlist_item WHERE product_id = {your_product_id}
Or if you want in a Magento way :
$adapter = $this->_getReadAdapter(); $select = $adapter->select()->from($this->getTable('wishlist/item'), array('product_id'))->where('product_id=:product_id'); $bind = array( 'product_id' => $productId ); $data = $adapter->fetchRow($select, $bind);
Edit with you example : $wishlistIds = Mage::getModel('wishlist/item')->getCollection()->addFieldToFilter('product_id',$collection1['entity_id'])->getAllIds();

6
  • its not working for me Jan 4 '16 at 9:14
  • I am using this $wishlist_id=Mage::getModel('wishlist/item')->getCollection()->addFieldToSelect('*')->addFieldToFilter('product_id',$collection1['entity_id']); Jan 4 '16 at 9:15
  • And i want wishist id Jan 4 '16 at 9:15
  • add a ->getFirstItem()at the end of you collection Jan 4 '16 at 9:18
  • first ite give me wishlist ids for corresponding that product id? Jan 4 '16 at 9:20

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.