Tuesday, September 6, 2011

How do I find which file this function is referencing in magento?

          Let's say you have in a phtml file this line of code. $object->method(); ($object can be anything including $this). And you don't know what class file the current object is referencing. To find the class name of the object use the get_class() method. echo get_class($object);
          Clear the cache (contents of var/cache) and reload the page. You should see the name of the class. For example Mage_Catalog_Model_Category. now all you have to do is to find the file. Because Magento is based on Zend Framework it uses the the same convention for class naming.
           So class Abc_Def_Ghi will be in the file "Abc/Def/Ghi.php" (for the example above the file is "Mage/Catalog/Model/Category.php").

           All the classes are placed in "app/code/core" or "app/code/local/" or "app/code/community" or "lib/" and after that follow the path like explained above. If you don't find a method in that specific class look in one of the parents. Check the class that the current class extends.

           You will not find all the methods in Magento. For example some of the methods that start with get, set, has, uns is possible that the methods are missing. For this take a look in Varien_Object class (that is the base class for most of the objects) lib/Varien/Object.php file (remember the convention above?) and look in the 'magic' method __call().
Mage::getSingleton('checkout/session')->setData(cart_was_updated, false); 
So basically any method that starts with ‘set’ and it’s not found in any model is equivalent with setData(’lower_case_key’, $value);
It works the same for methods that start with ‘get’, ‘has’, ‘uns’ (from unset).

No comments:

Post a Comment