Remove default fields from Product Collection

by Matthew   Last Updated June 13, 2019 09:09 AM

I have a product collection object (Mage_Catalog_Model_Resource_Product_Collection). I am adding various attributes to the select via addAttributeToSelect().

How do I remove the default attributes e.g entity_id, created_at etc, from the collection?

I have tried removeAttributeToSelect(), but i believe this only removes attributes that have been added by addAttributetoSelect().



Answers 2


Sorry, I am the original poster. I thought it would use my other stackexchange account.

I have solved this by using unsetData($key) on the product object, rather than the collection. Unfortunately, this means looping through all the products, so it is rather slow.

And removeAttributeToSelect() does exist....http://doc4dev.net/doc/Magento/1/source-class-Mage_Eav_Model_Entity_Collection_Abstract.html#822-836

EquinoxMatt
EquinoxMatt
October 15, 2015 10:08 AM

If it helps someone, there is a method removeAllFieldsFromSelect. It works well for me. Then you can add only the attributes you need with addFieldToSelect.

$orderCollection->removeAllFieldsFromSelect()
    ->addFieldToSelect('increment_id')
;

Important notice: field entity_id will be present anyway, removeAllFieldsFromSelect doesn't remove it.

Tymofii Maksymenko
Tymofii Maksymenko
June 13, 2019 08:37 AM

Related Questions


Updated July 14, 2015 13:04 PM

Updated August 11, 2015 17:04 PM

Updated April 28, 2015 21:04 PM

Updated June 13, 2017 18:09 PM

Updated March 07, 2018 08:09 AM