Skip to content

Commit

Permalink
Merge pull request #408 from mailchimp/webhook-error-fix
Browse files Browse the repository at this point in the history
Webhook error fix
  • Loading branch information
Santiagoebizmarts authored Jul 27, 2017
2 parents 27df18f + cdf991c commit 3d5f070
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 9 deletions.
20 changes: 13 additions & 7 deletions app/code/community/Ebizmarts/MailChimp/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ public function createStore($listId, $scopeId, $scope)
$mailchimpStoreId = md5($this->getMCStoreName($scopeId, $scope) . '_' . $date);
//create store in mailchimp
try {
$response = Mage::getModel('mailchimp/api_stores')->createMailChimpStore($mailchimpStoreId, $listId, $scopeId, $scope);
$response = $this->getApiStores()->createMailChimpStore($mailchimpStoreId, $listId, $scopeId, $scope);
//save in config
$configValues = array(
array(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID, $mailchimpStoreId),
Expand Down Expand Up @@ -648,13 +648,14 @@ public function deleteStore($scopeId, $scope)
$mailchimpStoreId = $this->getMCStoreId($scopeId, $scope);
if (!empty($mailchimpStoreId)) {
try {
Mage::getModel('mailchimp/api_stores')->deleteMailChimpStore($mailchimpStoreId, $scopeId, $scope);
$this->getApiStores()->deleteMailChimpStore($mailchimpStoreId, $scopeId, $scope);
} catch (MailChimp_Error $e) {
Mage::helper('mailchimp')->logError($e->getFriendlyMessage(), $scopeId, $scope);
$this->logError($e->getFriendlyMessage(), $scopeId, $scope);
}

//delete configured webhook
$this->deleteCurrentWebhook($scopeId, $scope);
$listId = $this->getGeneralList($scopeId, $scope);
$this->deleteCurrentWebhook($scopeId, $scope, $listId);
//clear store config values
$this->deleteLocalMCStoreData($scopeId, $scope);
}
Expand Down Expand Up @@ -781,7 +782,7 @@ public function changeName($name, $scopeId, $scope)
{
if ($this->getMCStoreId($scopeId, $scope) && $this->getIfConfigExistsForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_MCSTOREID, $scopeId, $scope)) {
try {
Mage::getModel('mailchimp/api_stores')->modifyName($name, $scopeId, $scope);
$this->getApiStores()->modifyName($name, $scopeId, $scope);
} catch (MailChimp_Error $e) {
Mage::helper('mailchimp')->logError($e->getFriendlyMessage(), $scopeId, $scope);
}
Expand Down Expand Up @@ -1062,7 +1063,7 @@ public function getMCJs()
if ($this->isEcomSyncDataEnabled($storeId)) {
$url = $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::ECOMMERCE_MC_JS_URL, $storeId);
if (!$url) {
$url = Mage::getModel('mailchimp/api_stores')->getMCJsUrl($storeId, 'stores');
$url = $this->getApiStores()->getMCJsUrl($storeId, 'stores');
}
$script = '<script type="text/javascript" src="' . $url . '"></script>';
}
Expand Down Expand Up @@ -1448,7 +1449,7 @@ protected function _setIsSyncingInAllStores($syncValue)
$mailchimpApi = $this->getApi($storeId);
$mailchimpStoreId = $this->getMCStoreId($storeId);
if ($mailchimpStoreId) {
Mage::getModel('mailchimp/api_stores')->editIsSyncing($mailchimpApi, $syncValue, $mailchimpStoreId, $storeId);
$this->getApiStores()->editIsSyncing($mailchimpApi, $syncValue, $mailchimpStoreId, $storeId);
}
}
}
Expand Down Expand Up @@ -1867,6 +1868,11 @@ public function addEntriesToArray($batchArray, $productData, $counter)
return array($batchArray, $counter);
}

protected function getApiStores()
{
return Mage::getModel('mailchimp/api_stores');
}

public function getCheckoutSubscribeValue($scopeId, $scope = 'stores')
{
return $this->getConfigValueForScope(Ebizmarts_MailChimp_Model_Config::GENERAL_CHECKOUT_SUBSCRIBE, $scopeId, $scope);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,25 @@ public function testIsCheckoutSubscribeEnabled()

$this->assertTrue($helperMock->isCheckoutSubscribeEnabled(1, "stores"));
}

public function testDeleteStore()
{
$scopeId = 1;
$scope = 'stores';
$helperMock = $this->getMockBuilder(Ebizmarts_MailChimp_Helper_Data::class)
->disableOriginalConstructor()
->setMethods(array('getMCStoreId', 'getApiStores', 'getGeneralList', 'deleteCurrentWebhook', 'deleteLocalMCStoreData'))
->getMock();
$apiStoresMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Api_Stores::class)
->disableOriginalConstructor()
->getMock();

$helperMock->expects($this->once())->method('getMCStoreId')->with($scopeId, $scope)->willReturn('a18a1a8a1aa7aja1a');
$helperMock->expects($this->once())->method('getApiStores')->willReturn($apiStoresMock);
$helperMock->expects($this->once())->method('getGeneralList')->with($scopeId, $scope)->willReturn('listId');
$helperMock->expects($this->once())->method('deleteCurrentWebhook')->with($scopeId, $scope, 'listId');
$helperMock->expects($this->once())->method('deleteLocalMCStoreData')->with($scopeId, $scope);

$helperMock->deleteStore($scopeId, $scope);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function testSendEcommerceBatch()

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

$apiCustomersMock = $this->getMockBuilder(Ebizmarts_MailChimp_Model_Api_Customers::class)
Expand Down Expand Up @@ -56,7 +56,7 @@ public function testSendEcommerceBatch()

$apiMock = $this->getMockBuilder(Ebizmarts_MailChimp::class)
->disableOriginalConstructor()
// ->setMethods(array(''))
// ->setMethods(array('edit'))
->getMock();

$apiBatchesMock->expects($this->once())->method('getHelper')->willReturn($helperMock);
Expand All @@ -69,6 +69,7 @@ public function testSendEcommerceBatch()
$helperMock->expects($this->once())->method('getMCStoreId')->with(1)->willReturn('b81c3085c51fa593e1d6b0cf59884f3e');
$helperMock->expects($this->once())->method('isMailChimpEnabled')->with(1)->willReturn(1);
$helperMock->expects($this->once())->method('isEcomSyncDataEnabled')->with(1)->willReturn(1);
$helperMock->expects($this->once())->method('getMCIsSyncing')->with(1)->willReturn(0);

$apiCustomersMock->expects($this->once())->method('createBatchJson')->with('b81c3085c51fa593e1d6b0cf59884f3e', 1);
$apiProductsMock->expects($this->once())->method('createBatchJson')->with('b81c3085c51fa593e1d6b0cf59884f3e', 1);
Expand Down

0 comments on commit 3d5f070

Please sign in to comment.