如何检查产品是否在 magento 比较列表中
您可以添加产品进行比较。如果尚未添加产品,我必须显示“添加到比较”链接,否则显示“比较”。我必须检查该产品是否在比较列表中。
我有 list.phtml
文件。
我尝试过这个,但这给出了比较列表中添加的所有产品。
$_productCollection = Mage::helper('catalog/product_compare')->getItemCollection()
我可以循环访问返回的产品,并可以检查该产品是否在此集合中,但我正在寻找一个获取产品 id
或 sku
并返回 true
或 false
相应地。
我也像这样添加了过滤器,但不起作用
$_productCollection = Mage::helper('catalog/product_compare')->getItemCollection()
->addAttributeToFilter('sku', $item->getSku());
You can add product to compare. I have to show the link "Add to Compare" if the product is not added already otherwise show "Compare". I have to check if the product is in comparison list.
I have list.phtml
file.
I tried this but this gives all the products added in comparison list.
$_productCollection = Mage::helper('catalog/product_compare')->getItemCollection()
I can loop through the returned products and can check if the product is in this collection but I am looking for a single call which take the product id
or sku
and return true
or false
accordingly.
I also added the filter like this but does not work
$_productCollection = Mage::helper('catalog/product_compare')->getItemCollection()
->addAttributeToFilter('sku', $item->getSku());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
及其方法:
像这样:
为什么助手不起作用?因为集合已经在那里加载:
v 1.6
因此您可以按模型加载集合并在模板或您自己的自定义帮助程序 - 模型中过滤本身。
Try to use
and its method:
Like this:
Why helper didn't worked? Because collection is already loaded there:
v 1.6
So you can load collection by model and filter itself in template or in your own custom helper - model.