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?
-
your question is unable to understand please specify in detail.– Denish VachhaniCommented Jan 4, 2016 at 7:29
-
is there any way to get wishlist id according to the product id?– Sumit AggarwalCommented Jan 4, 2016 at 8:35
-
Give you update.– Denish VachhaniCommented Jan 4, 2016 at 8:46
-
Get by customer?– Denish VachhaniCommented Jan 4, 2016 at 8:47
-
no get by product_id– Sumit AggarwalCommented Jan 4, 2016 at 8:50
2 Answers
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();
}
-
i am already using this is there any way to get wishlist id without using foreach Commented Jan 4, 2016 at 9:17
-
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();
-
-
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
-
-
-
first ite give me wishlist ids for corresponding that product id? Commented Jan 4, 2016 at 9:20