1

I am getting product collection without using addAttributeToFilter('status',array('eq'=>,1)),but still my collection has only active products.

Why it returns active products default?Is there any values set for this in admin?

My Full code is,

$products = Mage::getModel('catalog/product')->getCollection()
    ->addAttributeToSelect('*')->addCategoryFilter($category)
    ->addAttributeToFilter('entity_id',array('neq'=>$current->getId()))
    ->addAttributeToFilter('name',array('eq'=>$current->getName()))
    ->addAttributeToSort('price', 'asc')
    ->addFieldToFilter($attr_brand['code'], $attr_brand['val']);
  • 1
    show us full collection code that you have tried – Rajeev K Tomy Oct 14 '14 at 9:10
4

I have a hunch you have the flat products enabled.
The flat tables generated by the flat product indexer contain only active products.
This is for performance reasons. There is no need to index the disabled products since you are not going to use them on frontend. (and the flat tables are used only on frontend).

If you are trying to get your products in a custom script and you need to get the disabled ones also you can do this.

$collection = Mage::getResourceModel('catalog/product_collection')
    ->...add filters in here if needed.
  • But @Marius using getModel() is better than getResourceModel() right? – Manikandan Arunachalam Oct 14 '14 at 9:16
  • Where did you get that idea? – Marius Oct 14 '14 at 9:18
  • I am not sure..But getResourceModel() is an another layer in magento(in my mind).If I am wrong what is the difference? – Manikandan Arunachalam Oct 14 '14 at 9:21
  • 2
    @Manik. In most cases getModel('model')->getCollection() is the same thing as getResourceModel(model_collection). There is a difference only for categories and products. When the flat catalog is enabled they return different things depending if you are on frontend or backend. Calling getResourceModel bypasses this process and returns directly the resource you want. If you want to dig deeper and learn what happens you can add some logs in Mage_Core_Model_Abstract::getResourceCollection then work with flat catalog enabled and disabled and see the differences. – Marius Oct 14 '14 at 10:15
  • you are absolutely correct.I wondered The code i used produce different result when it is in adminhtml page.why this thing happens? – Manikandan Arunachalam Oct 14 '14 at 11:23
0

Flat Products only contains active products...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.