我使用了这段代码: -
$category_id = 5;
$products = Mage::getModel('catalog/category')
->load($category_id)
->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('status',array(
'eq' => Mage_Catalog_Model_Product_Status::STATUS_DISABLED)
);
它不起作用。它显示空的结果。
请让我知道如何解决这个问题。
提前致谢。
答案 0 :(得分:1)
这是我的解决方案:
如果你想在magento之外运行脚本,这是一个工作示例:
require_once('app/Mage.php');
umask(0);
Mage::app();
// set category id
$categoryIds = [4]; // add child category id's if you want to support child categories also
$productCollection = Mage::getModel('catalog/product')->getCollection();
$productCollection->addAttributeToSelect('*');
$productCollection->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_DISABLED);
$productCollection->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
->addAttributeToFilter('category_id', array('in' => $categoryIds))
->addAttributeToSelect('*');
$filteredProducts = $productCollection->getItems();
foreach ($filteredProducts as $product) {
echo $product->getId() . PHP_EOL;
}
内部magento:
// set category id
$categoryIds = [4]; // add child category id's if you want to support child categories also
$productCollection = Mage::getModel('catalog/product')->getCollection();
$productCollection->addAttributeToSelect('*');
$productCollection->addAttributeToFilter('status', Mage_Catalog_Model_Product_Status::STATUS_DISABLED);
$productCollection->joinField('category_id','catalog/category_product','category_id','product_id=entity_id',null,'left')
->addAttributeToFilter('category_id', array('in' => $categoryIds))
->addAttributeToSelect('*');
$filteredProducts = $productCollection->getItems();
如果您想支持多个类别,只需将ID添加到数组$categoryIds
如果您有任何问题,请随时添加评论。如果你有它工作,请告诉我,并添加你magento版本。感谢