检查产品是否在愿望清单中
我正在开发 Magento 主题,我需要构建一个函数来检查产品是否已添加到用户的愿望清单中。
Magento 有一个“Mage_Wishlist_Helper_Data”帮助程序类,但我不知道如何构建一个检查是否已在愿望列表中的函数。基本上我需要使用 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 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
由于集合是延迟加载的,我假设您可以执行以下操作:
您可以对其他字段执行类似的过滤,但在这种情况下 SKU 应该足够了。
Since collections are lazy loaded, I am assuming you can do something such as:
You can do similar filtering on other fields, but SKU should be sufficient in this case.
我现在才回到这个项目,但我采纳了 Daniel Sloof 的建议,并且使用下面的函数完美地工作了:
这会检查产品是否已添加到当前用户的愿望清单中。我将其称为我的模板文件,如下所示:
I'm only getting back to this project now, but I took Daniel Sloof's suggestion, and it worked perfectly using the function below:
This checks to see whether or not a product has been added into the current user's Wishlist. I called it my template file like this:
我在检查 Mage::helper('wishlist')->getWishlistItemCollection() 的选择查询后找到了这个解决方案。我希望这个解决方案对某人有所帮助。
I found this solution after checked select query of Mage::helper('wishlist')->getWishlistItemCollection(). I hope this solution help to someone.
我通过下面的函数解决了这个问题。我希望这可以帮助某人。
I solved this by the below function. I Hope this may help some one.
由于 @alexadr.parhomenk 的解决方案会导致不良结果,因此这里有一个较小的方法可以解决这个问题:
Since @alexadr.parhomenk s' solution causes undesired results, here's a smaller method that does the trick: