Magento themes and extensions

Display Categories and SubCategories in Magento

Posted on October 31st, 2012 | Posted by admin

The majority of  Magento websites out there list their top level categories as well as the current categories sub-categories. This feature is commonly requested on forums so I decided to write a small post about it.

Rather than just write out the code, I will show you a few variations so that you can get the right one for you.

All of the following code samples can be copy and pasted into ANY template file and will function correctly.

Display Top Level Categories Only

<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php if (count($_categories) > 0): ?>
<?php foreach($_categories as $_category): ?>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
<?php endforeach; ?>
<?php endif; ?>

Executing cron tasks manually in Magento

Posted on October 30th, 2012 | Posted by admin

Usually I’ve been asked about how to run a cron task manually. A cron task defined in Magento is not anything else than a function that belongs to a model that is loaded and executed.

For example, we have this cron task on a config.xml file of a specific module:

<cron_expr>*/15 * * * *</cron_expr>

Magento Observers, Layout Handles, & Frontend Page Views

Posted on October 29th, 2012 | Posted by admin

A lot of times when working with Magento, you will need to create a page layout or template that is unique to a particular section based on either a specific group of products or attributes or some other business logic.

Although the Magento category manager gives you the ability to add layout updates, it might seem cumbersome to have to apply the same layout update to many categories. It makes it easier for product managers if they don’t have to remember to add this layout update whenever new categories are created.

It’s easy to update unique page layouts by utilizing Magento’s built in ability to insert additional layout handles using an Observer. Then with a bit of CSS/JS/HTML we can create a whole new view.

Create your own Magento log files with Mage::log()

Posted on October 29th, 2012 | Posted by admin

Magento comes with a built-in logging facility which can be enabled and configured in the back-end under System > Configuration > Developer. Alternatively you can enable the Developer Mode for the site to enable the log (on how to do this have a look at the index.php file). The exception log is always on.

Mage::log('My log entry');
Mage::log('My log message: '.$myVariable);

By default all log entries are appended to the var/log/system.log file and the exceptions are logged to var/log/exception.log. Objects and Arrays are automatically written via a print_r() directive. Watch out when using objects since these can get substantial in size. If you are in Developer Mode you can try if the object supports debug output via $object->debug().

Inline editing in Magento backend grids

Posted on October 28th, 2012 | Posted by admin

Backend grids in Magento are very convenient, featuring filtering and pagination using AJAX by default. However, when you want to edit some field or record, you have to create a form. I’d like to describe the way of implementing inline field editing for a field.

A text field renderer class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Input has already implemented in Magento which allows us to have field’s value in the text input. Lets extend it by adding update button after the input element. For this you need to create Module_NameSpace_Block_Adminhtml_Widget_Grid_Column_Renderer_Inline class extending the original class and override its render() method:

Page 1 of 712345»...Last »