diff --git a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php index 62aeee184..997753e57 100755 --- a/app/code/community/Ebizmarts/MailChimp/Helper/Data.php +++ b/app/code/community/Ebizmarts/MailChimp/Helper/Data.php @@ -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); @@ -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 */ @@ -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']); } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Backend/Store.php b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Backend/Store.php index 1e77b7575..29823831b 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Backend/Store.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Backend/Store.php @@ -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); } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Account.php b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Account.php index 09e7cfa6c..9cba7cc15 100755 --- a/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Account.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Account.php @@ -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) ) ); } diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php index fb7c645d2..49b506fa8 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Helper/DataTest.php @@ -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'; @@ -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); @@ -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()