Changing the default grid per page view in Magento can indeed be tricky if you’re new to the platform’s layout system. The scattered documentation doesn’t help much either. Let me guide you through this process.
Understanding the Magento Layout System
Before diving into the code, let’s quickly recap how the Magento layout system works under the hood. It uses XML files (like your local.xml) to define the structure of a page and where different components should be placed. Each handle represents a specific page typeâcategory_catalog_default is for the default category view, while category_catalog_layered handles the layered navigation version.
Setting Up Your local.xml File
Assuming you already have your local.xml file located in app/etc and it includes the necessary Magento installation details, let’s proceed to modify the layout handles. You want to change the default grid per page for both regular and layered navigation category views.
<config>
<layout>
<updates>
<my_theme module="namespace_mymodule">
<file>namespace_mymodule.xml</file>
</my_theme>
</updates>
<!-- Add this handle to your local.xml -->
<handle>
<reference name="product_list_toolbar_pager">
<action method="setDefaultGridPerPage">
<limit>15</limit>
</action>
</reference>
</handle>
</layout>
</config>
Notice the addition of a new handle section. This is where you define your custom layout modifications.
Applying the Change to Specific Handles
You mentioned adding the reference to both category_catalog_default and category_catalog_layered handles, which is correct:
<reference name="category_catalog_default">
<reference name="product_list_toolbar_pager">
<action method="setDefaultGridPerPage">
<limit>15</limit>
</action>
</reference>
</reference>
<reference name="category_catalog_layered">
<reference name="product_list_toolbar_pager">
<action method="setDefaultGridPerPage">
<limit>15</limit>
</action>
</reference>
</reference>
This code instructs Magento to change the default grid per page limit to 15 for both regular and layered category views.
Ensuring Your Changes Take Effect
After adding these changes to your local.xml, remember to flush the cache:
php bin/magento cache:flush
Then refresh your website. The product grid should now display 15 items per page, perfectly aligning with your 5-column layout change.
Conclusion
Changing Magento’s default grid per page view isn’t as straightforward as it seems at first glance. It requires a solid understanding of the layout system and how handles work together to define different parts of the page.
Remember to always keep backups of your files before making significant changes, especially when dealing with core Magento XML files like local.xml.
If you’re looking for more in-depth guidance on customizing your Magento store or need help implementing other advanced features, feel free to reach out to our team at LaravelCompany. We have expertise in both Magento and Laravel development, so we can assist with any part of your e-commerce stack.