Skip to content

Commit

Permalink
Avoid creating mc alias if already exists. resolves #725
Browse files Browse the repository at this point in the history
  • Loading branch information
Santiagoebizmarts committed Jul 17, 2018
1 parent c6bf504 commit 3b6190d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/code/community/Ebizmarts/MailChimp/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,12 @@ public function addColumnToSalesOrderGridCollection(Varien_Event_Observer $obser
if ($ecommEnabledAnyScope && $addColumnConfig) {
$collection = $observer->getOrderGridCollection();
$select = $collection->getSelect();
$p = $select->getPart(Zend_Db_Select::FROM);
if (array_key_exists('mc', $p))
{
return;
}

$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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,6 +570,14 @@ public function testAddColumnToSalesOrderGridCollection()
{
$addColumnConfig = 1;
$scopeId = 0;
$fromCond = array(
'main_table' => array(
'joinType' => 'from',
'schema' => '',
'tableName' => 'sales_flat_order_grid',
'joinCondition' => ''
)
);
$mcTableName = 'mailchimp_ecommerce_sync_data';
$condition = 'mc.related_id=main_table.entity_id AND type = '.Ebizmarts_MailChimp_Model_Config::IS_ORDER;
$direction = 'ASC';
Expand All @@ -596,7 +604,7 @@ public function testAddColumnToSalesOrderGridCollection()

$selectMock = $this->getMockBuilder(Varien_Db_Select::class)
->disableOriginalConstructor()
->setMethods(array('joinLeft', 'group'))
->setMethods(array('joinLeft', 'group', 'getPart'))
->getMock();

$coreResourceMock = $this->getMockBuilder(Mage_Core_Model_Resource::class)
Expand All @@ -617,6 +625,9 @@ public function testAddColumnToSalesOrderGridCollection()
$eventObserverMock->expects($this->once())->method('getOrderGridCollection')->willReturn($orderGridCollectionMock);

$orderGridCollectionMock->expects($this->once())->method('getSelect')->willReturn($selectMock);

$selectMock->expects($this->once())->method('getPart')->with(Zend_Db_Select::FROM)->willReturn($fromCond);

$orderGridCollectionMock->expects($this->once())->method('getTable')->with('mailchimp/ecommercesyncdata')->willReturn($mcTableName);

$selectMock->expects($this->once())->method('joinLeft')->with(array('mc' => $mcTableName), $condition, array('mc.mailchimp_synced_flag', 'mc.id'));
Expand Down

0 comments on commit 3b6190d

Please sign in to comment.