From 3b6190d2faf52890ffe2808af1ab7493837a3fe8 Mon Sep 17 00:00:00 2001 From: Santiago Date: Tue, 17 Jul 2018 17:58:11 -0300 Subject: [PATCH] Avoid creating mc alias if already exists. resolves #725 --- .../Ebizmarts/MailChimp/Model/Observer.php | 6 ++++++ .../app/Ebizmarts/MailChimp/Model/ObserverTest.php | 13 ++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Observer.php b/app/code/community/Ebizmarts/MailChimp/Model/Observer.php index 34b0c8b40..6f62973c7 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/Observer.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Observer.php @@ -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"); diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php index 0112b9fe3..ae926976e 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/ObserverTest.php @@ -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'; @@ -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) @@ -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'));