Skip to content

Commit

Permalink
Merge pull request #653 from mailchimp/make-order-columns-sortable
Browse files Browse the repository at this point in the history
Make order columns sortable
  • Loading branch information
Santiagoebizmarts authored Mar 6, 2018
2 parents bcdb400 + 802ab8c commit f5723cc
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 15 deletions.
12 changes: 7 additions & 5 deletions app/code/community/Ebizmarts/MailChimp/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,14 @@ public function getStoreRelation()
$stores = $this->getMageApp()->getStores();
$storeRelation = array();
foreach ($stores as $storeId => $store) {
$mcStoreId = $this->getMCStoreId($storeId);
if ($mcStoreId) {
if (!array_key_exists($mcStoreId, $storeRelation)) {
$storeRelation[$mcStoreId] = array();
if ($this->isEcomSyncDataEnabled($storeId)) {
$mcStoreId = $this->getMCStoreId($storeId);
if ($mcStoreId) {
if (!array_key_exists($mcStoreId, $storeRelation)) {
$storeRelation[$mcStoreId] = array();
}
$storeRelation[$mcStoreId][] = $storeId;
}
$storeRelation[$mcStoreId][] = $storeId;
}
}
return $storeRelation;
Expand Down
45 changes: 37 additions & 8 deletions app/code/community/Ebizmarts/MailChimp/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function saveConfig(Varien_Event_Observer $observer)
$helper = $this->makeHelper();
$scopeArray = $helper->getCurrentScope();

if (isset($post['groups']['general']['fields']['list']['inherit']) && $this->makeHelper()->getIfConfigExistsForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID, $scopeArray[1], $scopeArray[0])) {
if (isset($post['groups']['general']['fields']['list']['inherit']) && $this->makeHelper()->getIfConfigExistsForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID, $scopeArray['scope_id'], $scopeArray['scope'])) {
$helper->removeEcommerceSyncData($scopeArray['scope_id'], $scopeArray['scope']);
$helper->resetCampaign($scopeArray['scope_id'], $scopeArray['scope']);
$helper->clearErrorGrid($scopeArray['scope_id'], $scopeArray['scope'], true);
Expand Down Expand Up @@ -448,35 +448,65 @@ public function addColumnToSalesOrderGrid(Varien_Event_Observer $observer)
) {
if ($addColumnConfig == Ebizmarts_MailChimp_Model_Config::ADD_MAILCHIMP_LOGO_TO_GRID || $addColumnConfig == Ebizmarts_MailChimp_Model_Config::ADD_BOTH_TO_GRID) {
$block->addColumnAfter(
'mailchimp_flag', array(
'mailchimp_campaign_id', array(
'header' => $helper->__('MailChimp'),
'index' => 'mailchimp_flag',
'index' => 'mailchimp_campaign_id',
'align' => 'center',
'filter' => false,
'renderer' => 'mailchimp/adminhtml_sales_order_grid_renderer_mailchimp',
'sortable' => false,
'sortable' => true,
'width' => 70
), 'created_at'
);
}
if ($addColumnConfig == Ebizmarts_MailChimp_Model_Config::ADD_SYNC_STATUS_TO_GRID || $addColumnConfig == Ebizmarts_MailChimp_Model_Config::ADD_BOTH_TO_GRID) {
$block->addColumnAfter(
'mailchimp_order_flag', array(
'mailchimp_synced_flag', array(
'header' => $helper->__('Synced to MailChimp'),
'index' => 'mailchimp_order_flag',
'index' => 'mailchimp_synced_flag',
'align' => 'center',
'filter' => false,
'renderer' => 'mailchimp/adminhtml_sales_order_grid_renderer_mailchimpOrder',
'sortable' => false,
'sortable' => true,
'width' => 70
), 'created_at'
);

$columnId = $block->getParam($block->getVarNameSort());
$direction = $block->getParam($block->getVarNameDir());
if ($columnId == 'mailchimp_synced_flag') {
Mage::register('sort_column_dir', $direction);
}
}
}

return $observer;
}



public function addColumnToSalesOrderGridCollection(Varien_Event_Observer $observer)
{

$helper = $this->makeHelper();
$addColumnConfig = $helper->getMonkeyInGrid(0);
$ecommEnabledAnyScope = $helper->isEcomSyncDataEnabledInAnyScope();
if ($ecommEnabledAnyScope && $addColumnConfig) {
$collection = $observer->getOrderGridCollection();
$collection->addFilterToMap('store_id', 'main_table.store_id');
$select = $collection->getSelect();
$select->joinLeft(array('oe' => $collection->getTable('sales/order')), 'oe.entity_id=main_table.entity_id', array('oe.mailchimp_campaign_id'));
$adapter = $this->getCoreResource()->getConnection('core_write');
$select->joinLeft(array('mc' => $collection->getTable('mailchimp/ecommercesyncdata')), $adapter->quoteInto('mc.related_id=main_table.entity_id AND type = ?', Ebizmarts_MailChimp_Model_Config::IS_ORDER), array('mc.mailchimp_synced_flag', 'mc.id'));
$select->group("main_table.entity_id");
$direction = Mage::registry('sort_column_dir');
if ($direction) {
$collection->addOrder('mc.id', $direction);
Mage::unregister('sort_column_dir');
}
}
}

/**
* Add customer to the cart if it placed the email address in the popup or footer subscription form.
*
Expand All @@ -485,7 +515,6 @@ public function addColumnToSalesOrderGrid(Varien_Event_Observer $observer)
*/
public function loadCustomerToQuote(Varien_Event_Observer $observer)
{

$quote = $observer->getEvent()->getQuote();
$storeId = $quote->getStoreId();
$helper = $this->makeHelper();
Expand Down
13 changes: 11 additions & 2 deletions app/code/community/Ebizmarts/MailChimp/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,22 @@
</core_block_abstract_to_html_after>
<core_block_abstract_to_html_before>
<observers>
<mailchimp_add_synced_to_grid_order>
<mailchimp_add_synced_to_order_grid>
<type>model</type>
<class>mailchimp/observer</class>
<method>addColumnToSalesOrderGrid</method>
</mailchimp_add_synced_to_grid_order>
</mailchimp_add_synced_to_order_grid>
</observers>
</core_block_abstract_to_html_before>
<sales_order_grid_collection_load_before>
<observers>
<mailchimp_add_synced_to_order_grid_collection>
<type>model</type>
<class>mailchimp/observer</class>
<method>addColumnToSalesOrderGridCollection</method>
</mailchimp_add_synced_to_order_grid_collection>
</observers>
</sales_order_grid_collection_load_before>
<admin_system_config_changed_section_mailchimp>
<observers>
<mailchimp_save_config>
Expand Down

0 comments on commit f5723cc

Please sign in to comment.