Magento: Customizing the Admin Sales Order Listing Table
As an experienced e-commerce developer, I understand your frustration when dealing with admin panel customizations in Magento. The sales order listing table is a critical component of the back-end experience, and modifying its appearance or data structure can be challenging.
Identifying the Controlling Template File
The formatting of the admin sales order table is primarily controlled by two template files located under app/design/adminhtml/default/default/template/sales/order/view.grid.phtml. This file contains the HTML structure for the grid (table), while the CSS styles are defined in skin/adminhtml/default/default/css/style.css.
However, directly editing these core files is not recommended as it can lead to issues during upgrades. Instead, let’s explore a more elegant solution using Magento’s theme inheritance and customization features.
Creating a Custom Theme for Admin
To avoid modifying the core files, we need to create a new admin theme that extends the default theme but allows us to override specific templates and styles. Here are the steps:
-
Navigate to
app/design/adminhtml/defaultand copy thedefaultfolder to create a new theme folder, e.g.,my_custom_admin. -
Inside the
my_custom_adminfolder, create the following directory structure:my_custom_admin âââ template âââ sales âââ order âââ view.grid.phtml -
Copy the
view.grid.phtmlfile from the default theme to your new theme:app/design/adminhtml/default/default/template/sales/order/view.grid.phtml -> app/design/adminhtml/my_custom_admin/template/sales/order/view.grid.phtml.
Customizing the Admin Grid
Now that we have a custom theme set up, let’s modify the grid template to add or edit columns.
-
Open
app/design/adminhtml/my_custom_admin/template/sales/order/view.grid.phtmlin your preferred text editor. -
To add a new column, you need to locate the
<tr>element that represents the main table row. This is usually found near line 70 of the file. -
Inside this
<tr>, locate the<th>elements representing the existing columns. You can add a new<th>element for your custom column with an appropriate header label, e.g.,My Custom Column.
<th class="col-company">
<span class="nobr"><?php echo $this->__('My Custom Column') ?></span>
</th>
-
Next, locate the
<tr>element that follows this (usually around line 75), which represents a sample row with data. -
Inside this
<tr>, add a new<td>element for your custom column after an existing one, e.g., right before thecol-entity_idcell:
<td class="data-grid-col">
<span class="nobr"><?php echo $this->__('Custom Value'); ?></span>
</td>
- Save and close the file.
Applying the Custom Theme
To apply your new custom admin theme, follow these steps:
-
Log in to the Magento admin interface.
-
Navigate to “System” > “Configuration”.
-
Click on “Advanced” (under the ‘Advanced’ group).
-
Under “Admin”, change “Admin Template” to
my_custom_admin. -
Change “Admin Skin” to
my_custom_admin. -
Click “Save Config”.
Conclusion
Customizing the admin sales order listing table in Magento requires careful handling of core files and a solid understanding of theme inheritance. By creating a custom admin theme, you can safely override the default template without risking conflicts during upgrades.
Remember, always make backups before performing any modifications to your codebase, especially in production environments. If you find yourself needing more advanced customizations or encountering complex issues, consider seeking professional support from experienced Magento developers at Laravel Company.
Happy coding!