I needed a custom button to call a url. I wanted this button to appear above my grid in Admin>Sales>Orders.
This proved to be simple once I learned how the Admin grid pages are organized. There are two elements to each page: the container for the grid and the grid itself. In my other post about adding a “Download” status, I had to add “Download” to the drop-down menu in the grid itself. For this button at the top of the page, I needed to find the container for the Order Grid.
This code adds a button which says “Download” to the right of the + Create New Order button. When clicked, the Download button calls a URL (which in my case triggers a php script to do some database operations.)
Find this file:
/app/code/core/Mage/Adminhtml/Block/Sales/Order.php
This is the container for the grid which shows the order.
Copy that file and place it here:
/app/code/local/Mage/Adminhtml/Block/Sales/Order.php
This will override the original without changing the original. (You don’t want to change the original files, but override them with custom files.)
Now, open the custom file you just placed in your custom directory, and edit it so that there is new code for the button inside the __construct() function. Here is an example of the whole function with the new button code:
This proved to be simple once I learned how the Admin grid pages are organized. There are two elements to each page: the container for the grid and the grid itself. In my other post about adding a “Download” status, I had to add “Download” to the drop-down menu in the grid itself. For this button at the top of the page, I needed to find the container for the Order Grid.
This code adds a button which says “Download” to the right of the + Create New Order button. When clicked, the Download button calls a URL (which in my case triggers a php script to do some database operations.)
Find this file:
/app/code/core/Mage/Adminhtml/Block/Sales/Order.php
This is the container for the grid which shows the order.
Copy that file and place it here:
/app/code/local/Mage/Adminhtml/Block/Sales/Order.php
This will override the original without changing the original. (You don’t want to change the original files, but override them with custom files.)
Now, open the custom file you just placed in your custom directory, and edit it so that there is new code for the button inside the __construct() function. Here is an example of the whole function with the new button code:
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
| public function __construct() { $this ->_controller = 'sales_order' ; $this ->_headerText = Mage::helper( 'sales' )->__( 'Orders' ); $this ->_addButtonLabel = Mage::helper( 'sales' )->__( 'Create New Order' ); ///////CUSTOM code for new button: $data = array ( 'label' => 'Download to Mas' , 'onclick' => "setLocation('" . $this ->getUrl('downloadtomas ')."' )" ); ///////The
URL I am using is a custom module that I set up earlier, Magento parses
it to <MySite.com/shop/index.php/downloadtomas>, which then runs
the script I have in the IndexController.php file Mage_Adminhtml_Block_Widget_Container::addButton( 'download_to_mas' , $data , 0, 100, 'header' , 'header' ); ///////End CUSTOM code parent::__construct(); if (!Mage::getSingleton( 'admin/session' )->isAllowed( 'sales/order/actions/create' )) { $this ->_removeButton( 'add' ); } } |
No comments:
Post a Comment