我正在尝试获取所有启用和禁用的产品,并且我正在使用此代码:
/*$categoryId = 3; // a category id that you can get from admin
    $category = Mage::getModel('catalog/category')->load($categoryId);
    $collection = Mage::getModel('catalog/product')
                    ->getCollection()
                   ->addCategoryFilter($category)
                    ->addAttributeToSelect('*')
                    ->addAttributeToFilter('status', array('gt' => 0))
                    ->load();
$categoryId = 3; // a category id that you can get from admin
    $category = Mage::getModel('catalog/category')->load($categoryId);*/
以上代码仅带来启用的产品。
通过评论状态过滤器,它仍然会带来相同的结果,即仅启用产品。
    /*$collection = Mage::getModel('catalog/product')
                    ->getCollection()
                   ->addCategoryFilter($category)
                    ->addAttributeToSelect('*')
                    //->addAttributeToFilter('status', array('gt' => 0))
                    ->load();*/
它仍然只带来已启用的产品。但是当我评论类别检查时,它会带来所有产品:(有人可以帮忙吗?
笔记:
对于那些不清楚这个查询的人,让我告诉你Status Enabled = 1和Status Disabled = 2。
所以大于零的状态应该给我带来启用和禁用的产品,但它没有这样做。所以有什么想法吗???
我编辑代码和它
$collection = Mage::getModel('catalog/category')->load(3)
                    ->getProductCollection()
                    ->addAttributeToSelect('*')
                    ->addAttributeToSort('entity_id', 'ASC');
die((string) $collection->getSelect());
这带来了这个查询:
SELECT `e`.*, `cat_index`.`position` AS `cat_index_position` FROM `catalog_product_entity` AS `e` INNER JOIN `catalog_category_product_index` AS `cat_index` ON cat_index.product_id=e.entity_id AND cat_index.store_id=1 AND cat_index.category_id='3' ORDER BY `e`.`entity_id` ASC