Most of the time during the customization, we need at one time to use a getData() on an object exemple $_item = $this->getItem(); to retrieve the datas and see if we have what we are looking for, except that sometimes we come across a large number of items So that it takes a long time to load and sometimes even go to the time out.

My question is: it is possible to add a limit on the getData() ? or if you have other tricks to get the datas of an object, that would be welcome.


To clarify better what i want, I know that I can filter by name like getData('attribute_name') but admit that I'm looking for 20 attributes, so to not mention them all one by one. I wanted to know if there was a way to limit theme per (100) for exemple.

How do you do when you want to know the data present in some object that you don't know what it contains ?


Not sure if this is what your looking for, but to get one data-field of a large collection you can use $collection->getColumnValues('attribute_code').


How do you do when you want to know the data present in some object that you don't know what it contains ?

When talking about debugging large objects you can also use this. It will leave out any recursive data - so you'll get no blank screen or empty log file for large objects ...

# if $item is some kind of Varien object
  • Look my update please – PЯINCƏ Jun 16 '17 at 8:37
  • @Prince please check update ... maybe its useful for your needs. – sv3n Jul 20 '17 at 21:51
  • ok, i'll check this tomorrow and i give you a feedback. – PЯINCƏ Jul 20 '17 at 22:07
  • Yes, it's not bad, the Julien Loizelet Mage::log(array_keys($item->getData())); solution is good too, the yours is better we have index and value together. But Why the getData() takes so much time and at the end bug and go to the timeout however the debug() does the job well. accepted plus +1 ;) – PЯINCƏ Jul 21 '17 at 9:59
  • @Prince Nice that it fits for you. Dont want to edit you question, but maybe change title to something more "suitable". Regards. – sv3n Jul 21 '17 at 19:08

when I am debugging and when a Mage::log($someObject->getData()) returns an error "max memory allowed exhausted", I start with Mage::log(array_keys($someObject->getData())); in order to know which keys will be usefull.

Then I can log using Mage::log($someObject->getData('name_of_a_key'));


I usually do this if I know what data I am expecting:

//$item is order item

This will give you only the name of the item.

  • Look my update please – PЯINCƏ Jun 16 '17 at 8:37

getData() feature is available in Magento in almost all kind of classes. It can be used against all flat model classes, eav model classes, model collection classes, block classes, helper classes and controller classes etc. There is no doubt developers use getData() function in order to dump all data related to the class and evaluate it.

You need to use different tricks for different kind of classes in order to limit the getData() output.

In case of collection classes, instead of loading all attribute data, you can load only those which is needed. ie instead of addAttributeToSelect('*'), you can use addAttributeToSelect(['id', 'name', 'your_required_fields']). This will eventually limit getData() output.

In case of model entity, you can use hasData('data_field_to_check) method in order to check the data. Or you can try getData('data_field_to_check'). If you are sure the data which you are enquiring is an array, then in order to get a particular value inside that array, you can try this: getData('array_field', 'key_value_to_retrieve')

Other than this, you cannot really limit the output of getData().

  • Look my update please – PЯINCƏ Jun 16 '17 at 8:37

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.