Php 如何检查产品是否在比较列表中
您可以添加要比较的产品。我必须显示链接“添加到比较”,如果产品尚未添加,否则显示“比较”。我得检查一下产品是否在对照表中Php 如何检查产品是否在比较列表中,php,magento,Php,Magento,您可以添加要比较的产品。我必须显示链接“添加到比较”,如果产品尚未添加,否则显示“比较”。我得检查一下产品是否在对照表中 $_productCollection = Mage::helper('catalog/product_compare')->getItemCollection() 我有list.phtml文件 我试过了,但这给出了比较列表中添加的所有产品 $_productCollection = Mage::helper('catalog/product_compare')-&g
$_productCollection = Mage::helper('catalog/product_compare')->getItemCollection()
我有list.phtml
文件
我试过了,但这给出了比较列表中添加的所有产品
$_productCollection = Mage::helper('catalog/product_compare')->getItemCollection()
我可以循环查看返回的产品,并可以检查该产品是否在此集合中,但我正在寻找一个调用,该调用获取产品id
或sku
,并相应地返回true
或false
我还添加了这样的过滤器,但不起作用
$_productCollection = Mage::helper('catalog/product_compare')->getItemCollection()
->addAttributeToFilter('sku', $item->getSku());
尝试使用
Mage_Catalog_Model_Product_Compare_List
及其方法:
getItemCollection
像这样:
$collection = Mage::getModel('catalog/product_compare_list')->getItemCollection();
$collection->.....Additional filters go here.
为什么助手不工作?因为集合已在那里加载:
v 1.6
所以,您可以按模型加载集合,并在模板或您自己的自定义帮助器模型中过滤自身