Skip to content

Commit

Permalink
Merge pull request #745 from mailchimp/addFilterToMap-issue744
Browse files Browse the repository at this point in the history
Add filter to map (issue744) and remove resend configs when reset store. (issue741)
  • Loading branch information
Santiagoebizmarts authored Jun 28, 2018
2 parents 2d00e38 + 0be95f4 commit c6bf504
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public function render(Varien_Object $row)
$storeId = $row->getStoreId();
$orderId = $row->getEntityId();
$helper = $this->makeHelper();
$isReset = $helper->getIsReset($storeId);
if ($helper->isEcomSyncDataEnabled($storeId)) {
$mailchimpStoreId = $helper->getMCStoreId($storeId);
$resultArray = $this->makeApiOrders()->getSyncedOrder($orderId, $mailchimpStoreId);
Expand All @@ -29,9 +28,9 @@ public function render(Varien_Object $row)

if ($status == self::SYNCED) {
$result = '<div style ="color:green">' . $helper->__("Yes") . '</div>';
} elseif ($status === null && $id !== null && !$isReset)
} elseif ($status === null && $id !== null)
$result = '<div style ="color:#ed6502">' . $helper->__("Processing") . '</div>';
elseif ($status === null || $isReset) {
elseif ($status === null) {
$result = '<div style ="color:mediumblue">' . $helper->__("In queue") . '</div>';
} else {
$result = '<div style ="color:red">' . $helper->__("No") . '</div>';
Expand Down
21 changes: 7 additions & 14 deletions app/code/community/Ebizmarts/MailChimp/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -324,9 +324,15 @@ public function deleteLocalMCStoreData($mailchimpStoreId, $scopeId, $scope = nul
$config = $this->getConfig();
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID, $scope, $scopeId);
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING, $scope, $scopeId);
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTORE_RESETED, $scope, $scopeId);
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_ECOMMMINSYNCDATEFLAG, $scope, $scopeId);
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_MC_JS_URL, $scope, $scopeId);
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_CUSTOMER_LAST_ID, $scope, $scopeId);
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_PRODUCT_LAST_ID, $scope, $scopeId);
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_ORDER_LAST_ID, $scope, $scopeId);
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_CART_LAST_ID, $scope, $scopeId);
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_PCD_LAST_ID, $scope, $scopeId);
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_RESEND_ENABLED, $scope, $scopeId);
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_RESEND_TURN, $scope, $scopeId);
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_SYNC_DATE . "_$mailchimpStoreId", 'default', 0);
$config->cleanCache();
}
Expand Down Expand Up @@ -379,18 +385,6 @@ public function getCustomMergeFieldsSerialized($scopeId, $scope = null)
return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_CUSTOM_MAP_FIELDS, $scopeId, $scope);
}

/**
* Get if store has been reset for given scope.
*
* @param $scopeId
* @param null $scope
* @return mixed
*/
public function getIsReset($scopeId, $scope = null)
{
return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTORE_RESETED, $scopeId, $scope);
}

/**
* Get if Abandoned Cart module is enabled.
*
Expand Down Expand Up @@ -808,7 +802,6 @@ public function createStore($listId, $scopeId, $scope)
array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID, $mailchimpStoreId),
array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING, 1),
array(Ebizmarts_MailChimp_Model_Config::GENERAL_ECOMMMINSYNCDATEFLAG, Varien_Date::now()),
array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTORE_RESETED, 1)
);
if (isset($response['connected_site']['site_script']['url'])) {
$configValues[] = array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_MC_JS_URL, $response['connected_site']['site_script']['url']);
Expand Down
4 changes: 0 additions & 4 deletions app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,6 @@ public function _sendEcommerceBatch($magentoStoreId)
if (!$batchJson || $batchJson == '') {
$helper->logRequest('An empty operation was detected');
} else {
if (!$helper->getIsReset($magentoStoreId)) {
$batchResponse = $mailchimpApi->getBatchOperation()->add($batchJson);
$helper->logRequest($batchJson, $batchResponse['id']);
//save batch id to db
Expand All @@ -324,7 +323,6 @@ public function _sendEcommerceBatch($magentoStoreId)
->setStatus($batchResponse['status']);
$batch->save();
$this->markItemsAsSent($batchResponse['id'], $mailchimpStoreId);
}
}
}

Expand Down Expand Up @@ -664,7 +662,6 @@ public function replaceAllOrders($initialTime, $magentoStoreId)
if (!$batchJson || $batchJson == '') {
$helper->logRequest('An empty operation was detected');
} else {
if (!$helper->getIsReset($magentoStoreId)) {
$batchResponse = $mailchimpApi->batchOperation->add($batchJson);
$helper->logRequest($batchJson, $batchResponse['id']);
//save batch id to db
Expand All @@ -673,7 +670,6 @@ public function replaceAllOrders($initialTime, $magentoStoreId)
->setBatchId($batchResponse['id'])
->setStatus($batchResponse['status']);
$batch->save();
}
}
}

Expand Down
1 change: 0 additions & 1 deletion app/code/community/Ebizmarts/MailChimp/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ class Ebizmarts_MailChimp_Model_Config
const GENERAL_MCISSYNCING = 'mailchimp/general/is_syicing';
const GENERAL_ECOMMMINSYNCDATEFLAG = 'mailchimp/general/mcminsyncdateflag';
const GENERAL_SUBMINSYNCDATEFLAG = 'mailchimp/general/subminsyncdateflag';
const GENERAL_MCSTORE_RESETED = 'mailchimp/general/mcstore_reset';
const GENERAL_TWO_WAY_SYNC = 'mailchimp/general/webhook_active';
const GENERAL_UNSUBSCRIBE = 'mailchimp/general/webhook_delete';
const GENERAL_WEBHOOK_ID = 'mailchimp/general/webhook_id';
Expand Down
1 change: 0 additions & 1 deletion app/code/community/Ebizmarts/MailChimp/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,6 @@ public function addColumnToSalesOrderGridCollection(Varien_Event_Observer $obser
$ecommEnabledAnyScope = $helper->isEcomSyncDataEnabledInAnyScope();
if ($ecommEnabledAnyScope && $addColumnConfig) {
$collection = $observer->getOrderGridCollection();
$collection->addFilterToMap('store_id', 'main_table.store_id');
$select = $collection->getSelect();
$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'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,12 @@ public function testRender($syncedData)
$mailchimpStoreId = '5axx998994cxxxx47e6b3b5dxxxx26e2';
$storeId = 1;
$status = $syncedData['synced_status'];
$isReset = 0;

if ($status){
$assertStatus = '<div style ="color:green">Yes</div>';
} elseif ($orderId && $status === null && !$isReset){
} elseif ($orderId && $status === null){
$assertStatus = '<div style ="color:#ed6502">Processing</div>';
} elseif ($status === null || $isReset){
} elseif ($status === null){
$assertStatus = '<div style ="color:mediumblue">In queue</div>';
} else {
$assertStatus = '<div style ="color:red">No</div>';
Expand All @@ -64,7 +63,7 @@ public function testRender($syncedData)

$helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
->disableOriginalConstructor()
->setMethods(array('getMCStoreId', 'isEcomSyncDataEnabled', 'getIsReset'))
->setMethods(array('getMCStoreId', 'isEcomSyncDataEnabled'))
->getMock();

$modelMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Api_Orders::class)
Expand All @@ -79,7 +78,6 @@ public function testRender($syncedData)
$orderMock->expects($this->once())->method('getEntityId')->willReturn($orderId);

$helperMock->expects($this->once())->method('getMCStoreId')->with($storeId)->willReturn($mailchimpStoreId);
$helperMock->expects($this->once())->method('getIsReset')->with($storeId)->willReturn($isReset);
$helperMock->expects($this->once())->method('isEcomSyncDataEnabled')->with($storeId)->willReturn(true);

$modelMock->expects($this->once())->method('getSyncedOrder')->with($orderId, $mailchimpStoreId)->willReturn($syncedData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,18 +182,19 @@ public function testDeleteLocalMCStoreData()
$helperMock->expects($this->once())->method('getConfig')->willReturn($configMock);

$param1 = array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID, $scope, $scopeId);

$param2 = array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING, $scope, $scopeId);

$param3 = array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTORE_RESETED, $scope, $scopeId);

$param4 = array(Ebizmarts_MailChimp_Model_Config::GENERAL_ECOMMMINSYNCDATEFLAG, $scope, $scopeId);

$param5 = array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_MC_JS_URL, $scope, $scopeId);

$param6 = array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_SYNC_DATE . "_$mailchimpStoreId", 'default', 0);

$configMock->expects($this->exactly(6))->method('deleteConfig')->withConsecutive($param1, $param2, $param3, $param4, $param5, $param6);
$param3 = array(Ebizmarts_MailChimp_Model_Config::GENERAL_ECOMMMINSYNCDATEFLAG, $scope, $scopeId);
$param4 = array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_MC_JS_URL, $scope, $scopeId);
$param5 = array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_CUSTOMER_LAST_ID, $scope, $scopeId);
$param6 = array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_PRODUCT_LAST_ID, $scope, $scopeId);
$param7 = array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_ORDER_LAST_ID, $scope, $scopeId);
$param8 = array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_CART_LAST_ID, $scope, $scopeId);
$param9 = array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_PCD_LAST_ID, $scope, $scopeId);
$param10 = array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_RESEND_ENABLED, $scope, $scopeId);
$param11 = array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_RESEND_TURN, $scope, $scopeId);
$param12 = array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_SYNC_DATE . "_$mailchimpStoreId", 'default', 0);

$configMock->expects($this->exactly(12))->method('deleteConfig')->withConsecutive($param1, $param2, $param3, $param4, $param5, $param6, $param7, $param8, $param9, $param10, $param11, $param12);
$configMock->expects($this->once())->method('cleanCache');

$helperMock->deleteLocalMCStoreData($mailchimpStoreId, $scopeId, $scope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ public function testSendEcommerceBatch()

$helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
->disableOriginalConstructor()
->setMethods(array('getMCStoreId', 'getEcommMinSyncDateFlag', 'isEcomSyncDataEnabled', 'getApi', 'getIsReset',
->setMethods(array('getMCStoreId', 'getEcommMinSyncDateFlag', 'isEcomSyncDataEnabled', 'getApi',
'getMCIsSyncing', 'logRequest', 'validateDate', 'saveMailchimpConfig'))
->getMock();

Expand Down Expand Up @@ -333,8 +333,6 @@ public function testSendEcommerceBatch()

$helperMock->expects($this->once())->method('getApi')->with($magentoStoreId)->willReturn($apiMock);

$helperMock->expects($this->once())->method('getIsReset')->with($magentoStoreId)->willReturn(false);

$apiMock->expects($this->once())->method('getBatchOperation')->willReturn($apiBatchOperationMock);
$apiBatchOperationMock->expects($this->once())->method('add')->with($batchJson)->willReturn($batchResponse);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,6 @@ public function testAddColumnToSalesOrderGridCollection()
{
$addColumnConfig = 1;
$scopeId = 0;
$orderTableName = 'sales_flat_order';
$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 @@ -592,7 +591,7 @@ public function testAddColumnToSalesOrderGridCollection()

$orderGridCollectionMock = $this->getMockBuilder(Mage_Sales_Model_Resource_Order_Grid_Collection::class)
->disableOriginalConstructor()
->setMethods(array('addFilterToMap', 'getSelect', 'getTable', 'addOrder'))
->setMethods(array('getSelect', 'getTable', 'addOrder'))
->getMock();

$selectMock = $this->getMockBuilder(Varien_Db_Select::class)
Expand All @@ -617,7 +616,6 @@ public function testAddColumnToSalesOrderGridCollection()

$eventObserverMock->expects($this->once())->method('getOrderGridCollection')->willReturn($orderGridCollectionMock);

$orderGridCollectionMock->expects($this->once())->method('addFilterToMap')->with('store_id', 'main_table.store_id');
$orderGridCollectionMock->expects($this->once())->method('getSelect')->willReturn($selectMock);
$orderGridCollectionMock->expects($this->once())->method('getTable')->with('mailchimp/ecommercesyncdata')->willReturn($mcTableName);

Expand Down

0 comments on commit c6bf504

Please sign in to comment.