Guest User

Untitled

a guest
Jul 19th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. $_product = ...; // some product object you already have
  2.  
  3. $_productCollection = Mage::helper('wishlist')->getProductCollection()
  4. ->addFieldToFilter('sku', $_product->getSku());
  5.  
  6. if($_productCollection->count() > 0) {
  7. // User already has item in wishlist.
  8. }
  9.  
  10. public function isInWishlist($item)
  11. {
  12.  
  13. $_productCollection = Mage::helper('wishlist')->getProductCollection()
  14. ->addFieldToFilter('sku', $item->getSku());
  15.  
  16. if($_productCollection->count()) {
  17. return true;
  18. }
  19.  
  20. return false;
  21. }
  22.  
  23. if ($this->helper('wishlist')->isInWishlist($_product)) :
  24.  
  25. function checkInWishilist($_product){
  26.  
  27.  
  28. Mage::getSingleton('customer/session')->isLoggedIn();
  29. $session = Mage::getSingleton('customer/session');
  30. $cidData = $session->isLoggedIn();
  31. $customer_id = $session->getId();
  32.  
  33. if($customer_id){
  34. $wishlist = Mage::getModel('wishlist/item')->getCollection();
  35. $wishlist->getSelect()
  36. ->join(array('t2' => 'wishlist'),
  37. 'main_table.wishlist_id = t2.wishlist_id',
  38. array('wishlist_id','customer_id'))
  39. ->where('main_table.product_id = '.$_product->getId().' AND t2.customer_id='.$customer_id);
  40.  
  41. $count = $wishlist->count();
  42.  
  43. $wishlist = Mage::getModel('wishlist/item')->getCollection();
  44. }
  45. else{
  46. $count="0";
  47. }
  48.  
  49. if($count) :
  50. return true;
  51. else:
  52. return false;
  53. endif;
  54.  
  55. }
  56.  
  57. <?php $wishlist = Mage::getModel('wishlist/item')->load($_product->getId(),'product_id');
  58. if($wishlist->getId())
  59. //product is added
  60. echo "Added! - Product is in the wishlist!";
  61. else
  62. //add product to wishlist
  63. echo "<a href='".$this->helper('wishlist')->getAddUrl($_product) ."'>Add This?</a>";
  64. ;?>
Add Comment
Please, Sign In to add comment