|
Hi, here is my own experience based on these two tutorials ([tutorial1] and [tutorial2]) and php|architect’s Guide to Programming with Magento.
First of all, you’ll need a working magento setup.
Now, we’ve got two solutions for customizing Magento’s code :
The bad one : Editing and changing Magento’s core files
The clean one : Creating a package of your own and telling Magento you’ll replace core files with your files.
NB : In this document, I’ll suppose you are using a *nix system and your magento’s installation leaves in
/var/www/html/magento
1 - Prepare your package’s location
mkdir -p /var/www/html/magento/app/code/local/AsRenzoCorp
You need to create your own package where all your customizations will be placed. In this example my package will be named AsRenzoCorp.
2 - Find the file you need to customize
The core file we need to change to add customer groups to orders list is
/var/www/html/magento/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php
3 - Create your package’s path
mkdir -p /var/www/html/magento/app/code/local/AsRenzoCorp/Adminhtml/Block/Sales/Order
4 - Copy original file to your custom location
cd /var/www/html/magento/app/code/local/AsRenzoCorp/Adminhtml/Block/Sales/Order cp /var/www/html/magento/app/code/core/Mage/Adminhtml/Block/Sales/Order/Grid.php ./
5 - Edit your own Grid.php
vi /var/www/html/magento/app/code/local/AsRenzoCorp/Adminhtml/Block/Sales/Order/Grid.php
6 - Replace class definition
Change
class Mage_Adminhtml_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Widget_Grid
With
class AsRenzoCorp_Adminhtml_Block_Sales_Order_Grid extends Mage_Adminhtml_Block_Sales_Order_Grid
Namings are case sensitive and must reflect your system path
7 - Add your column declaration to the _prepareColumns() function
$this->addColumn('customer_group_id', array( 'header'=> Mage::helper('customer')->__('Group'), 'width' => '80px', 'index' => 'customer_group_id', 'renderer' => new AsRenzoCorp_Adminhtml_Block_Sales_Order_Renderer_CustomerGroup(), 'type' => 'options', 'options' => AsRenzoCorp_Adminhtml_Block_Sales_Order_Renderer_CustomerGroup::getCustomerGroupsArray(), ));
8 - Create the renderer defined in the above code
mkdir -p /var/www/html/magento/app/code/local/AsRenzoCorp/Adminhtml/Block/Sales/Order/Renderer
Edit a new CustomerGroup.php file and paste the code below
vi /var/www/html/magento/app/code/local/AsRenzoCorp/Adminhtml/Block/Sales/Order/Renderer/CustomerGroup.php
<?php class AsRenzoCorp_Adminhtml_Block_Sales_Order_Renderer_CustomerGroup extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
// Holds an associative array with customer_group_id and the associated label private static $_customerGroups = array(); // "singleton"
public static function getCustomerGroupsArray() { // Make sure the static property is only populated once if (count(self::$_customerGroups) == 0) { $customer_group = new Mage_Customer_Model_Group(); $customer_groups = $customer_group->getCollection()->toOptionHash(); self::$_customerGroups = $customer_groups; }
return self::$_customerGroups; }
// Transforms the customer_group_id into corresponding label public function render(Varien_Object $row) { $val = $this->_getValue($row); $customer_groups = self::getCustomerGroupsArray(); return isset($customer_groups[$val]) ? $customer_groups[$val] : false; }
}
9 - Tell Magento there is a new module available
Edit the local.xml file and add the declaration below into the <global> node
vi /var/www/html/magento/app/etc/local.xml
<modules> <AsRenzoCorp_Adminhtml> <active>true</active> <codePool>local</codePool> </AsRenzoCorp_Adminhtml> </modules>
10 - Tell Magento to use your file instead of its own
Edit the local.xml file and add the declaration below into the <global> node
vi /var/www/html/magento/app/etc/local.xml
<blocks> <adminhtml> <rewrite> <sales_order_grid>AsRenzoCorp_Adminhtml_Block_Sales_Order_Grid</sales_order_grid> </rewrite> </adminhtml> </blocks>
And you should see a new column in your orders grid view.
PS : You may need to clean the cache system before being able to see changes.
Laurent
|