I am learning magento and I have some doubts about how it works, could someone help me with it or can suggest some tutorial from where I can learn more about magento. In


file there is a piece of code


I know this function can be found in


But there is no such function, I also looked in the parent class and there also I could not find this function.

I found another function in


Below is the function

protected function _getProductCollection()
    switch ($this->getDisplayType()) {
        case self::DISPLAY_TYPE_NEW_PRODUCTS:
            $collection = parent::_getProductCollection();
            $collection = $this->_getRecentlyAddedProductsCollection();
    return $collection;

and I know this function is called but my question is why and how? These two have different names then how they can be same. Do it means that "_" is only used if a function is protected and it does not have to do anything with the function name.

And also when I echoed


then I got 'new_products' but if you see in this function then magento is using self::DISPLAY_TYPE_NEW_PRODUCTS in case then how these two cases or strings are similar.

Also please explain this line


do it means call _getProductCollection() from parent class and if yes then where this is specified in magento.

1 Answer 1


1) Regarding: $this->getProductCollection() method:

Check file:


This is having _beforeToHtml() method at line no.127(Line number can be different for different version of Magento).

 * Prepare collection with new products
 * @return Mage_Core_Block_Abstract
protected function _beforeToHtml()
    return parent::_beforeToHtml();

Above method sets product collection before html render.

Note: getProductCollection() and _getProductCollection() are not same. Both are completely different method.

2) $this->getDisplayType()

Any constant variable can be defined using const statement.

const DISPLAY_TYPE_NEW_PRODUCTS = 'new_products';

and that variable can be used as:


So, self::DISPLAY_TYPE_NEW_PRODUCTS will return new_products.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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