检查产品是否在愿望清单中 [英] Check whether a product is in the wishlist or not

查看:47
本文介绍了检查产品是否在愿望清单中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究Magento主题,我需要构建一个函数来检查是否已将产品添加到用户的愿望清单中.

I'm working on a Magento theme, and I need to build a function that can check to see whether or not a product has been added to the user's wishlist.

Magento有一个"Mage_Wishlist_Helper_Data"帮助器类,但是我不知道如何构建如果已在心愿单中检查"功能.基本上,我需要使用Magento的心愿单功能来建立收藏夹列表.如果特定产品已经添加到用户的收藏夹中,我想在添加到愿望清单"链接中添加一个特殊的类.

Magento has a "Mage_Wishlist_Helper_Data" helper class, but I have no idea how to build a check-if-already-in-wishlist function. Basically I need to use Magento's wishlist feature to build a favorites list. I want to add a special class to the "add to wishlist" link if the particular product was already added to the user's favorites.

推荐答案

 <?php $wishlist = Mage::getModel('wishlist/item')->load($_product->getId(),'product_id');
      if($wishlist->getId())
          //product is added
      echo "Added! - Product is in the wishlist!";
      else
          //add product to wishlist
      echo "<a href='".$this->helper('wishlist')->getAddUrl($_product) ."'>Add This?</a>";
  ;?>

这篇关于检查产品是否在愿望清单中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆