How to Create a Filtered “Manage Pages” Menu Item in Magento
Introduction
In this post, we will guide you through creating a new menu item named “Manage Pages” that filters the backend’s “Manage Products” page based on specific attribute set criteria. This menu item should only display products with attribute sets starting with “CMS_” and without a price column.
Understanding the Base Configuration
You have already configured the basic structure of your menu in the app/code/community/Mycompany/Content/etc/config.xml file. Here’s the relevant excerpt:
<menu>
<newmenu translate="title">
...
<children>
<newchildmenu translate="title">
<title>Manage Pages</title>
<action>adminhtml/newmenu/</action>
</newchildmenu>
...
</children>
</newmenu>
</menu>
The newchildmenu tag represents your “Manage Pages” menu item. The action attribute currently points to a non-existent URL (adminhtml/newmenu/), which means it doesn’t direct anywhere yet.
Creating the Custom Controller
To achieve your goal, you need to create a custom controller that will handle this specific action and filter the product collection accordingly. Here’s how:
-
Create the controller file:
Navigate to
app/code/community/Mycompany/Content/controllers/adminhtml/NewmenuController.phpand create a new PHP file. -
Implement the necessary methods:
In your
NewmenuController.php, add the following code:
class Mycompany_Content_Adminhtml_NewmenuController extends Mage_Adminhtml_Controller_Action
{
public function indexAction()
{
$this->_title($this->__('Manage CMS Products'));
// Build the product collection
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToFilter('attribute_set', array('like' => 'CMS%')) // Filter by attribute set name
->addAttributeToFilter('price', array('null' => true)); // Exclude products with price
$this->_initAction()
->_addContent($this->getLayout()->createBlock('catalog/adminhtml_product_edit')->setData('collection', $collection));
$this->renderLayout();
}
}
This indexAction method filters the product collection based on your specified criteria (attribute set starting with “CMS_” and no price).
-
Update the config.xml
Now, update your
app/code/community/Mycompany/Content/etc/config.xmlfile to point the “Manage Pages” action to this new controller:
<menu>
<newmenu translate="title">
...
<children>
<newchildmenu translate="title">
<title>Manage Pages</title>
<action>adminhtml/newmenu/index/</action>
</newchildmenu>
...
</children>
</newmenu>
</menu>
Conclusion
By following these steps, you should now have a functional “Manage Pages” menu item in your Magento backend. When clicked, it will redirect to the “Manage Products” page with your desired product filters applied.
Remember that this is a community extension example; for production code, you would want to ensure proper module versioning, file structure organization, and security practices are followed.
For more advanced customizations or if you need help implementing similar features in your Magento setup, don’t hesitate to reach out to us at Laravel Company. Our team of experienced Magento developers is always ready to assist you with your e-commerce needs!