Skip to content

Commit

Permalink
Merge pull request #950 from mailchimp/pre-release/1.1.16
Browse files Browse the repository at this point in the history
Patch for store configuration
  • Loading branch information
Santiagoebizmarts authored Apr 30, 2019
2 parents c5f0a30 + a2114c2 commit 8e5fdee
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 30 deletions.
34 changes: 24 additions & 10 deletions app/code/community/Ebizmarts/MailChimp/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,16 +347,15 @@ public function getMCStoreId($scopeId, $scope = null)
* @param $scopeId
* @param string $scope
*/
public function deleteConfiguredMCStoreLocalData($mailchimpStoreId, $scopeId, $scope = 'stores')
public function deletePreviousConfiguredMCStoreLocalData($mailchimpStoreId, $scopeId, $scope = 'stores')
{
$configValues = array(array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_ACTIVE, 0));
$this->saveMailchimpConfig($configValues, $scopeId, $scope, false);
$config = $this->getConfig();
foreach ($this->getAllStoresForScope($scopeId, $scope) as $storeId) {
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING . "_$mailchimpStoreId", 'stores', $storeId);
if ($mailchimpStoreId !== null && $mailchimpStoreId !== '') {
foreach ($this->getAllStoresForScope($scopeId, $scope) as $storeId) {
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING . "_$mailchimpStoreId", 'stores', $storeId);
}
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING . "_$mailchimpStoreId", $scope, $scopeId);
}
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING . "_$mailchimpStoreId", $scope, $scopeId);
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID, $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);
Expand All @@ -373,6 +372,21 @@ public function deleteConfiguredMCStoreLocalData($mailchimpStoreId, $scopeId, $s
$connection->update($tableName, array('status' => 'canceled'), $where);
}

/**
* Delete all data related to the configured store in a given scope.
*
* @param $scopeId
* @param string $scope
*/
public function deleteAllConfiguredMCStoreLocalData($mailchimpStoreId, $scopeId, $scope = 'stores')
{
$configValues = array(array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_ACTIVE, 0));
$this->saveMailchimpConfig($configValues, $scopeId, $scope, false);
$config = $this->getConfig();
$config->deleteConfig(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID, $scope, $scopeId);
$this->deletePreviousConfiguredMCStoreLocalData($mailchimpStoreId, $scopeId, $scope = 'stores');
}

/**
* @return Ebizmarts_MailChimp_Model_Mysql4_SynchBatches
*/
Expand All @@ -394,9 +408,9 @@ public function deleteAllMCStoreData($mailchimpStoreId)
$this->clearErrorGridByMCStore($mailchimpStoreId);

//Delete particular scopes configuraion flags for this store
$scopeArratIfExist = $this->getScopeByMailChimpStoreId($mailchimpStoreId);
if ($scopeArratIfExist !== false) {
$this->deleteConfiguredMCStoreLocalData($mailchimpStoreId, $scopeArratIfExist['scope_id'], $scopeArratIfExist['scope']);
$scopeArrayIfExist = $this->getScopeByMailChimpStoreId($mailchimpStoreId);
if ($scopeArrayIfExist !== false) {
$this->deleteAllConfiguredMCStoreLocalData($mailchimpStoreId, $scopeArrayIfExist['scope_id'], $scopeArrayIfExist['scope']);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,19 @@ protected function _afterSave()
$scope = $this->getScope();
$groups = $this->getData('groups');

$mailchimpStoreId = (isset($groups['general']['fields']['storeid']['value'])) ? $groups['general']['fields']['storeid']['value'] : $helper->getMCStoreId($scopeId, $scope);
$isSyncing = $helper->getMCIsSyncing($mailchimpStoreId, $scopeId, $scope);
$ecommMinSyncDate = $helper->getEcommMinSyncDateFlag($mailchimpStoreId, $scopeId, $scope);
$newMailchimpStoreId = (isset($groups['general']['fields']['storeid']['value'])) ? $groups['general']['fields']['storeid']['value'] : null;
$oldMailchimpStoreId = $helper->getMCStoreId($scopeId, $scope);
$isSyncing = $helper->getMCIsSyncing($newMailchimpStoreId, $scopeId, $scope);
$ecommMinSyncDate = $helper->getEcommMinSyncDateFlag($newMailchimpStoreId, $scopeId, $scope);

if ($this->isValueChanged() && $this->getValue()) {
$helper->deleteConfiguredMCStoreLocalData($mailchimpStoreId, $scopeId, $scope);
$helper->deletePreviousConfiguredMCStoreLocalData($oldMailchimpStoreId, $scopeId, $scope);
if ($ecommMinSyncDate === null) {
$configValues = array(array(Ebizmarts_MailChimp_Model_Config::GENERAL_ECOMMMINSYNCDATEFLAG."_$mailchimpStoreId", Varien_Date::now()));
$configValues = array(array(Ebizmarts_MailChimp_Model_Config::GENERAL_ECOMMMINSYNCDATEFLAG."_$newMailchimpStoreId", Varien_Date::now()));
$helper->saveMailchimpConfig($configValues, 0, 'default');
}
if ($isSyncing === null) {
$configValues = array(array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING . "_$mailchimpStoreId", true));
$configValues = array(array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING . "_$newMailchimpStoreId", true));
$helper->saveMailchimpConfig($configValues, $scopeId, $scope);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,13 +179,11 @@ public function toOptionArray()
)
);
} elseif ($helper->isEcomSyncDataEnabled($scopeArray['scope_id'], $scopeArray['scope'], true)) {
$noStoreText = $helper->__('No MailChimp store was created for this scope, parent scopes might be sending data for this store anyways.');
$newStoreText = $helper->__('You can create a new MailChimp store for this scope by configuring a new list for this scope.');
$noStoreText = $helper->__('No MailChimp store was configured for this scope, parent scopes might be sending data for this store anyways.');
$returnArray = array_merge(
$returnArray,
array(
array('value' => self::NO_STORE_TEXT_KEY, 'label' => $noStoreText),
array('value' => self::NEW_STORE_TEXT_KEY, 'label' => $newStoreText)
array('value' => self::NO_STORE_TEXT_KEY, 'label' => $noStoreText)
)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ public function testHandleResendFinish()
$helperMock->handleResendFinish($scopeId, $scope);
}

public function testDeleteConfiguredMCStoreLocalData()
public function testDeleteAllConfiguredMCStoreLocalData()
{
$scope = 'default';
$scopeId = 0;
$scope = 'stores';
$scopeId = 1;
$mailchimpStoreId = 'a1s2d3f4g5h6j7k8l9n0';
$where = "status = 'pending' AND store_id = $mailchimpStoreId";
$tableName = 'mailchimp_sync_batches';
Expand Down Expand Up @@ -163,14 +163,14 @@ public function testDeleteConfiguredMCStoreLocalData()


$helperMock->expects($this->once())->method('saveMailchimpConfig')->with($configValues, $scopeId, $scope, false);
$helperMock->expects($this->once())->method('getConfig')->willReturn($configMock);
$helperMock->expects($this->exactly(2))->method('getConfig')->willReturn($configMock);
$helperMock->expects($this->once())->method('getAllStoresForScope')->with($scopeId, $scope)->willReturn($storeIdsArray);

$param1 = array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING. "_$mailchimpStoreId", 'stores', $storeIdOne);
$param2 = array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING. "_$mailchimpStoreId", 'stores', $storeIdTwo);
$param3 = array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING. "_$mailchimpStoreId", 'stores', $storeIdThree);
$param4 = array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING. "_$mailchimpStoreId", $scope, $scopeId);
$param5 = array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID, $scope, $scopeId);
$param2 = array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING. "_$mailchimpStoreId", 'stores', $storeIdOne);
$param3 = array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING. "_$mailchimpStoreId", 'stores', $storeIdTwo);
$param4 = array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING. "_$mailchimpStoreId", 'stores', $storeIdThree);
$param5 = array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCISSYNCING. "_$mailchimpStoreId", $scope, $scopeId);
$param1 = array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID, $scope, $scopeId);
$param6 = array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_CUSTOMER_LAST_ID, $scope, $scopeId);
$param7 = array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_PRODUCT_LAST_ID, $scope, $scopeId);
$param8 = array(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_ORDER_LAST_ID, $scope, $scopeId);
Expand All @@ -192,7 +192,7 @@ public function testDeleteConfiguredMCStoreLocalData()
$dbAdapterInterfaceMock->expects($this->once())->method('quoteInto')->with("status = 'pending' AND store_id = ?", $mailchimpStoreId)->willReturn($where);
$dbAdapterInterfaceMock->expects($this->once())->method('update')->with($tableName, array('status' => 'canceled'), $where);

$helperMock->deleteConfiguredMCStoreLocalData($mailchimpStoreId, $scopeId, $scope);
$helperMock->deleteAllConfiguredMCStoreLocalData($mailchimpStoreId, $scopeId, $scope);
}

public function testGetDateSyncFinishByStoreId()
Expand Down

0 comments on commit 8e5fdee

Please sign in to comment.