如何为属性获取产品-magento

如何为属性获取产品-magento,magento,attributes,Magento,Attributes,我已经创建了一个属性Fresh arrival,在下拉列表中有两个值yes或no,我正在创建一个从phtml文件读取的块。在phtml文件中保存产品时,如何获取所有新到货设置为“是”的产品。您可以从 $_productCollection = Mage::getModel('catalog/product')->getCollection(); $_productCollection->addAttributeToSelect('*') ->addAtt

我已经创建了一个属性Fresh arrival,在下拉列表中有两个值yes或no,我正在创建一个从phtml文件读取的块。在phtml文件中保存产品时,如何获取所有新到货设置为“是”的产品。

您可以从

$_productCollection = Mage::getModel('catalog/product')->getCollection();

$_productCollection->addAttributeToSelect('*')
           ->addAttributeToFilter($attributecode, 1);
$products = $_productCollection->getItems();
   foreach($products as $product)
   {
    echo $product->getName()
   }
$attributecode
是使用集合的属性代码

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('*');
$collection->addAttributeToFilter('attribute_code', true);
在$collection中,您将拥有一个包含所需产品的对象。你可以绕着它们转一圈,得到每一种产品

foreach ($collection as $_product){
    echo $_product->getId();
}

感谢$attribute_value将有是或否在我的情况下,我将不得不循环所有产品,并检查值是否设置为是,是否有办法在属性值设置为是的变量中获取所有产品?我认为您必须循环并设置条件如果您发现我的答案有帮助,请接受我的答案以帮助他人