开发者

Magento > Backend > New Menu Item needs specific action -> How do I do it?

开发者 https://www.devze.com 2023-01-20 13:29 出处:网络
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 \"CM

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


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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消