Skip to content

Commit

Permalink
Merge pull request #655 from mailchimp/fix-promo-rules
Browse files Browse the repository at this point in the history
Fix promo rules
  • Loading branch information
Santiagoebizmarts authored Mar 6, 2018
2 parents f5723cc + d4fdca3 commit 7c883a8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
8 changes: 6 additions & 2 deletions app/code/community/Ebizmarts/MailChimp/Model/Api/Batches.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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()
Expand Down

0 comments on commit 7c883a8

Please sign in to comment.