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. Commented Jan 4, 2016 at 7:29
  • is there any way to get wishlist id according to the product id? Commented Jan 4, 2016 at 8:35
  • Give you update. Commented Jan 4, 2016 at 8:46
  • Get by customer? Commented Jan 4, 2016 at 8:47
  • no get by product_id Commented Jan 4, 2016 at 8:50

2 Answers 2

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 Commented Jan 4, 2016 at 9:17
  • update ans pls check now
    – Abdul
    Commented Jan 4, 2016 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 Commented Jan 4, 2016 at 9:14
  • I am using this $wishlist_id=Mage::getModel('wishlist/item')->getCollection()->addFieldToSelect('*')->addFieldToFilter('product_id',$collection1['entity_id']); Commented Jan 4, 2016 at 9:15
  • And i want wishist id Commented Jan 4, 2016 at 9:15
  • add a ->getFirstItem()at the end of you collection Commented Jan 4, 2016 at 9:18
  • first ite give me wishlist ids for corresponding that product id? Commented Jan 4, 2016 at 9:20

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.