是否在Magento中获取至少包含一个类别的产品?
我目前有分类的产品,也有不属于任何类别的产品。这段代码将为我提供Magento中最近添加的所有产品:是否在Magento中获取至少包含一个类别的产品?,magento,Magento,我目前有分类的产品,也有不属于任何类别的产品。这段代码将为我提供Magento中最近添加的所有产品: $_productCollection = Mage::getResourceModel('catalog/product_collection') ->addAttributeToSelect('*') ->addAttributeToFilter($preorderAttribute, array(
$_productCollection = Mage::getResourceModel('catalog/product_collection')
->addAttributeToSelect('*')
->addAttributeToFilter($preorderAttribute, array(
'eq' => Mage::getResourceModel('catalog/product')
->getAttribute($preorderAttribute)
->getSource()
->getOptionId($preorderValue)
))
->setVisibility(array(2,3,4))
->setOrder('created_at', 'desc')
->setPage(1, 12);
但它也提供了不属于任何类别的产品。我只想要属于一个或多个类别的产品,而不想要不属于任何类别的产品
如何使用上面的代码实现这一点?下面的代码只适用于显示特定的两类产品
$_productCollection = Mage::getModel('catalog/product')
->getCollection()
->joinField('category_id', 'catalog/category_product', 'category_id', 'product_id = entity_id', null, 'left')
->addAttributeToSelect('*')
->addAttributeToFilter('category_id', array(
array('finset' => '7'),
array('finset' => '8'))
)
->addAttributeToSort('created_at', 'desc');
foreach($_productCollection as $_testproduct){
echo $_testproduct->getId()."<br/>";
};
$\u productCollection=Mage::getModel('目录/产品')
->getCollection()
->joinField('category\u id','category/category\u product','category\u id','product\u id=entity\u id',null,'left')
->addAttributeToSelect(“*”)
->addAttributeToFilter('category_id',数组(
数组('finset'=>'7'),
数组('finset'=>'8'))
)
->addAttributeToSort('created_at','desc');
foreach($\u productCollection作为$\u testproduct){
echo$_testproduct->getId()“
”;
};
您找到解决方案了吗?如果你找到任何解决方案,你可以分享它。