Created
August 23, 2013 17:55
-
-
Save bahoo/6322125 to your computer and use it in GitHub Desktop.
Smarter way to add fields to order grid.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
Summoned with: | |
<config> | |
<global> | |
<events> | |
<sales_order_resource_init_virtual_grid_columns> | |
<observers> | |
<capture_order_grid_fields> | |
<class>Company_Module_Model_Observer</class> | |
<method>captureOrderGridFields</method> | |
</capture_order_grid_fields> | |
</observers> | |
</sales_order_resource_init_virtual_grid_columns> | |
</events> | |
... | |
</global> | |
</config> */ | |
class Company_Module_Model_Observer{ | |
// only runs when saving or updating a single order record. | |
public function captureOrderGridFields($observer){ | |
$event = $observer->getEvent(); | |
$resource = $event->getResource(); | |
$adapter = $resource->getReadConnection(); | |
$concatCityState = $adapter->getConcatSql(array('{{table}}.city', $adapter->quote(', '), '{{table}}.region')); | |
$resource->addVirtualGridColumn( | |
'shipping_city_state', | |
'sales/order_address', | |
array('shipping_address_id' => 'entity_id'), | |
$concatCityState | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment