Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

Some Class Methods Not Defined (But Still Work in Magento?)
 
Sweet Tooth
Sr. Member
 
Avatar
Total Posts:  121
Joined:  2008-02-02
Canada
 

I’ve been working with magento for over a year now. Even so, I’m bedazzled by how some places in the application code methods are called for class objects that exists but have none of said methods defined in the files.

For example, in app/code/core/Mage/Sales/Block/Order/Recent.php, a Mage_Sales_Block_Order_Recent class that extends Mage_Core_Block_Template, you’ll notice this code:

if ($this->getOrders()->getSize() > 0{
            
return parent::_toHtml();
        
}

I have done a text search (grep) for the whole magento directory and the “$this->getOrders()” defined anywhere.

There are lots of places where this happens.

Am I missing something!?  I’m so confused!

 
Magento Community Magento Community
Magento Community
Magento Community
 
PandaWebStudio
Member
 
Avatar
Total Posts:  40
Joined:  2008-04-19
Amsterdam, Netherlands
 

Are you referring to the _toHtml() method?
This method is defined in Mage_Core_Block_Abstract.

I’ve used doxygen (http://www.stack.nl/~dimitri/doxygen/) to generate the phpDoc. Is much easier to find a method or a class this way.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mike222
Member
 
Total Posts:  41
Joined:  2008-04-07
Austria
 

Hi Nel,

welcome to the club. Although Magento is just php, Varien takes so much use of inheritance that it is nearly impossible to understand what magento is doing. I do not say that inheritance is a bad thing, just the lack of documentation or support is the bad thing.

Hope this helps you a bit:

Look at lib/Varien/Object.php. This is the base class of all other classes. There you can find a method __call($method, $args) which is a magic function in php (search php docu for further info). Each time a method cannot be found in the tree of inheritance this magic method will be called.

What Varien is doing here:
Assume for example a call of $this->getSomeObject(). They recognize that the method starts with “get”, convert the rest ("SomeObject") to “some_object” and check their data-array (member $_data) for an entry “some_object”. If this entry exists, Varien returns the value, if not they return null.

Thats their magic.

regards,

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top