Skip to content

Commit

Permalink
closes #939 for magento 2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
gonzaloebiz committed Dec 27, 2019
1 parent 22ea314 commit 08ada7e
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
24 changes: 24 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,30 @@ public function loadStores()
}
}
}
public function saveJsUrl($storeId, $scope = null, $mailChimpStoreId = null)
{
if (!$scope) {
$scope = \Magento\Store\Model\ScopeInterface::SCOPE_STORES;
}
if ($this->getConfigValue(self::XML_PATH_ACTIVE, $storeId, $scope)) {
try {
$api = $this->getApi($storeId);
$storeData = $api->ecommerce->stores->get($mailChimpStoreId);
if (isset($storeData['connected_site']['site_script']['url'])) {
$url = $storeData['connected_site']['site_script']['url'];
$this->_config->saveConfig(
self::XML_MAILCHIMP_JS_URL,
$url,
$scope,
$storeId
);
}
} catch (\Mailchimp_Error $e) {
$this->log($e->getFriendlyMessage());
}
}

}
public function getJsUrl($storeId)
{
$url = $this->getConfigValue(self::XML_MAILCHIMP_JS_URL, $storeId);
Expand Down
12 changes: 7 additions & 5 deletions Model/Config/Backend/MonkeyStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,13 @@ public function beforeSave()
);

$createWebhook = true;
$this->_helper->deleteConfig(
\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_JS_URL,
$this->getScopeId(),
$this->getScope()
);
$this->_helper->saveJsUrl($this->getScopeId(),$this->getScope(),$this->getValue());

foreach ($this->_storeManager->getStores() as $storeId => $val) {
$mstoreId = $this->_helper->getConfigValue(
\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_STORE,
Expand All @@ -119,11 +126,6 @@ public function beforeSave()
if ($listId == $newListId) {
$createWebhook = false;
}
$this->_helper->deleteConfig(
\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_JS_URL,
$storeId,
\Magento\Store\Model\ScopeInterface::SCOPE_STORES
);
}
if ($found==1) {
$this->_helper->cancelAllPendingBatches($mailchimpStore);
Expand Down
2 changes: 1 addition & 1 deletion Observer/ConfigObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ public function execute(EventObserver $observer)
$oldListId = $this->_registry->registry('oldListId');
$apiKey = $this->_registry->registry('apiKey');
$mustDelete = true;

foreach ($this->_storeManager->getStores() as $storeId => $val) {
$listId = $this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_LIST, $storeId);
$this->_helper->deleteConfig(\Ebizmarts\MailChimp\Helper\Data::XML_MAILCHIMP_JS_URL, $storeId, 'stores');
if ($listId == $oldListId) {
$mustDelete = false;
}
Expand Down

0 comments on commit 08ada7e

Please sign in to comment.