diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php index 2d640397e..018df7094 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php @@ -568,6 +568,7 @@ public function getBatchResponse($batchId, $magentoStoreId) */ protected function processEachResponseFile($files, $batchId, $mailchimpStoreId) { + $helper = $this->getHelper(); foreach ($files as $file) { $items = json_decode(file_get_contents($file)); foreach ($items as $item) { @@ -623,9 +624,12 @@ protected function processEachResponseFile($files, $batchId, $mailchimpStoreId) } $mailchimpErrors->save(); - $this->getHelper()->logError($error); + $helper->logError($error); } else { - $this->saveSyncData($id, $type, $mailchimpStoreId, null, null, 0, null, null, 1, true); + $syncDataItem = $helper->getEcommerceSyncDataItem($id, $type, $mailchimpStoreId); + if (!$syncDataItem->getMailchimpSyncModified()) { + $this->saveSyncData($id, $type, $mailchimpStoreId, null, null, 0, null, null, 1, true); + } } } diff --git a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php index 5c575d0df..7a480735f 100644 --- a/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php +++ b/app/code/community/Ebizmarts/MailChimp/Model/Api/PromoRules.php @@ -74,7 +74,7 @@ public function getNewPromoRule($ruleId, $batchId, $mailchimpStoreId, $magentoSt if (!empty($ruleData)) { $promoData['method'] = "POST"; $promoData['path'] = '/ecommerce/stores/' . $mailchimpStoreId . '/promo-rules'; - $promoData['operation_id'] = $batchId . '_' . Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE . '_' . $ruleId; + $promoData['operation_id'] = 'storeid-' . $magentoStoreId . '_' . Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE . '_' . $helper->getDateMicrotime() . '_' . $ruleId; $promoData['body'] = $promoRuleJson; //update promo rule delta $this->_updateSyncData($ruleId, $mailchimpStoreId, Varien_Date::now()); diff --git a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php index 998351b5d..442ddcdae 100644 --- a/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php +++ b/dev/tests/mailchimp/tests/app/Ebizmarts/MailChimp/Model/Api/PromoRulesTest.php @@ -66,6 +66,13 @@ public function testGetNewPromoRule() ->disableOriginalConstructor() ->getMock(); + $mailChimpHelperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class) + ->setMethods(array('getDateMicrotime')) + ->disableOriginalConstructor() + ->getMock(); + + $promoRulesApiMock->expects($this->once())->method('getMailChimpHelper')->willReturn($mailChimpHelperMock); + $mailChimpHelperMock->expects($this->once())->method('getDateMicrotime')->willReturn('2017-05-18-14-45-54-38849500'); $promoRulesApiMock->expects($this->once())->method('getPromoRule')->with(self::PROMORULE_ID)->willReturn($promoRuleMock); $promoRulesApiMock->expects($this->once())->method('generateRuleData')->with($promoRuleMock)->willReturn($promoRuleData); @@ -78,7 +85,7 @@ public function testGetNewPromoRule() $this->assertArrayHasKey("body", $return); $this->assertEquals("POST", $return["method"]); $this->assertRegExp("/\/ecommerce\/stores\/(.*)\/promo-rules/", $return["path"]); - $this->assertEquals(self::BATCH_ID . "_" . Ebizmarts_MailChimp_Model_Config::IS_PROMO_RULE . '_' . self::PROMORULE_ID, $return["operation_id"]); + $this->assertEquals(self::BATCH_ID . '_' . self::PROMORULE_ID, $return["operation_id"]); } public function testMakePromoRulesCollection()