views:

42

answers:

2

Hi guys!

I have created a new menu in my backend, and added some children. One of these children named "Manage Pages" must retrieve all the products that correspond to the attribute sets that begin with "CMS_" and should not have a price column.

I have done this so far:

app/code/community/Mycompany/Content/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_Content>
            <version>0.1.0</version>
        </Mycompany_Content>
    </modules>
    <adminhtml>
        <menu>
            <newmenu translate="title">
                <title>Content</title>
                <sort_order>31</sort_order>
                <action>adminhtml/newmenu/</action>
                <children>
                    <newchildmenu translate="title">
                        <title>Manage Pages</title>
                        <action>adminhtml/newmenu/</action>
                    </newchildmenu>
                    <newchildmenu1 translate="title">
                        <title>Manage Attributes</title>
                        <action>adminhtml/catalog_product_attribute</action>
                    </newchildmenu1>
                    <newchildmenu2 translate="title">
                        <title>Manage Categories</title>
                        <action>adminhtml/catalog_category/</action>
                    </newchildmenu2>                                        
                </children>
             </newmenu>
        </menu>
    </adminhtml>
</config> 

app/etc/modules/Mycompany_Content.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Mycompany_Content>
            <active>true</active>
            <codePool>community</codePool>
        </Mycompany_Content>
    </modules>
</config> 

Once again, this is what I want: - when I press “Manage Pages”, I want to be sent to a “Manage Products” page filtered on a certain set of atrributes - sets of attributes that have names begining with “CMS_”, and without the price column.

How do I do that?

Thanks in advance! HT

A: 

Ok, maybe I can try dissecting the problem.

How do I create a copy of "Manage Products" page in the backend which is filtered on a certain attribute set?

HTaina
+1  A: 

As Alan rightly points out this site isn't here to do anyone's work for them but if you are willing to help yourself then the community can provide clues. To that end here is a general method to learn what to do.

  • Start with looking at the existing Manage Products, the URL shows the path begins with "/admin/catalog_product/index/". URLs use a route/controller/action format so we can deduce that the class responsible will be Mage_Adminhtml_Catalog_ProductController and the method is indexAction.
    ("admin" routes to "Adminhtml", "catalog_product" becomes the "Catalog" folder and "ProductController" file)

  • The method indexAction contains calls to loadLayout() and renderLayout() which is a sure sign that a layout file is being used. Our next clue is in "app/design/adminhtml/default/layout/catalog.xml".

  • The first section of catalog.xml is <adminhtml_catalog_product_index> which luckily matches the path from before. In it's "content" it creates a block with type "adminhtml/catalog_product", this resolves to Mage_Adminhtml_Block_Catalog_Product.

  • On inspection it has a _prepareLayout() method, as with all blocks it is called before the page is output. This method adds an "Add Product" button and a block from "adminhtml/catalog_product_grid".

  • You can see from looking at the page that the grid is of the same form as all other grids in admin. The class Mage_Adminhtml_Block_Catalog_Product_Grid extends Mage_Adminhtml_Block_Widget_Grid which does all the hard work to make a grid. Only some small changes are needed to make it work.

  • The significant methods here are _prepareCollection() and _prepareColumns(). There is also _prepareMassaction() which defines the actions drop-down box that show in the top right of grids.

Nearly all admin pages work in the same way as this. To make your own you will need to;

  1. Register a controller for your module. Here is a guide on overloading controllers.
  2. Give your controller an action to render the layout.
  3. Create a layout file in the "app/design/adminhtml/default/layout" directory and register it in your "config.xml" so that it is respected. It must have a section that matches your route, controller and action.
  4. Add a block to display a grid widget. The example creates this programmatically but it can also be done in the layout file.
  5. Extend Mage_Adminhtml_Block_Widget_Grid to make your own block.
  6. Add a _prepareColumns() and a _prepareCollection() method which is where you will do the database access and filter the results as per your requirements.

Another relevant guide can be found here. In fact, look through the Magento wiki and knowledgebase for more information. The above is not a complete set of instructions and there is still much to learn thereafter.

clockworkgeek
Thank you very much! I'll be giving a try, and I'll let you know what I've managed to do.
HTaina
I'll also be displaying the code as soon as I get it to work! Thanks again!
HTaina
i'm clearly doing something very wrong...
HTaina
can someone point out to me, what's wrong with this code? http://www.magentocommerce.com/boards/viewthread/208244/
HTaina
+1 for an exhaustive introduction to a complex topic. @HTaina, I suggest that you check out the ModuleCreator extension that will create a lot of the Adminhtml boilerplate for you
Jonathan Day
re your forum code, I would be suspecting case-sensitivity issues. Also, have a look at the TBT Enhanced Grid extension, it does exactly what you are trying to and it is FOSS.
Jonathan Day
Johnathan, thank you for reminding me of ModuleCreator, I had a feeling I'd seen something like that before but was looking for it in the wiki. Still, I'm happy to offer the above as a generic discovery method which works for more than just admin pages. Perhaps I should be wiki-ing that.
clockworkgeek