__()
translation method: To get a translation of a specific module, you should useMage::helper('module-alias')->__('string to be translated')
. This happens implicitly if you use$this->__(...)
within a template or block and if you use thetranslate="..."
attribute in XML filesMage::helper('core')
methods: localized date, price and currency formating, escaping and encoding dataMage::helper('tax')
methods to get information from the tax configuration and calculate prices based on thatMage::helper('catalog/image')
provides an interface to create cached and resized catalog images and retrieve their URLMage::helper('catalog/product_url_rewrite')->joinTableToSelect()
joins the URL rewrite table to a product collection query.
But as always Magento breaks its own unwritten rules and should not be taken as an example. A "good" example how to not use helpers is Mage_Catalog_Helper_Product_Compare
which has an $_itemCollection
property that can only be initialized once and a $_customerId
property that can be changed with a setter. You will find a few more helpers related to the catalog with attached collections. Writing tests for code that uses them or re-use them in different context is not fun, so please don't do that at home.
The catalog/image
helper mentioned above is another example of a helper that really should not be a helper. You need to pass a product with init()
first which resets its current state, then you set various parameters (like resize()
, setQuality()
) and in the end you can get the URL with its __toString()
method. That looks nice when used in a template but the code is a huge mess and it doesn't make sense as a singleton.