Skip to content

Commit

Permalink
Add “Syncing Disabled” alert
Browse files Browse the repository at this point in the history
  • Loading branch information
Tam committed Jun 24, 2019
1 parent c3156f6 commit 7773806
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.0.4 - 2019-06-24
### Added
- Added alert to the Mailchimp CP section telling the user that syncing is disabled (if it is).

## 1.0.3 - 2019-06-24
### Added
- Added `disableSyncing` setting to prevent all syncing to Mailchimp
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ether/mailchimp-commerce",
"description": "Mailchimp integration with Craft Commerce",
"version": "1.0.3",
"version": "1.0.4",
"type": "craft-plugin",
"keywords": [
"mailchimp",
Expand Down
20 changes: 19 additions & 1 deletion src/MailchimpCommerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
use craft\commerce\services\Addresses;
use craft\errors\ElementNotFoundException;
use craft\errors\SiteNotFoundException;
use craft\events\RegisterCpAlertsEvent;
use craft\events\RegisterUrlRulesEvent;
use craft\helpers\Cp;
use craft\helpers\UrlHelper;
use craft\web\UrlManager;
use ether\mc\jobs\SyncOrders;
Expand Down Expand Up @@ -95,6 +97,12 @@ public function init ()
[$this, 'onAfterSaveAddress']
);

Event::on(
Cp::class,
Cp::EVENT_REGISTER_ALERTS,
[$this, 'onRegisterAlerts']
);

// Events: Products
// ---------------------------------------------------------------------

Expand Down Expand Up @@ -239,6 +247,16 @@ public function onRegisterCpUrlRules (RegisterUrlRulesEvent $event)
}
}

public function onRegisterAlerts (RegisterCpAlertsEvent $event)
{
if (
strpos(Craft::$app->getRequest()->getFullPath(), 'mailchimp-commerce') === false ||
!$this->getSettings()->disableSyncing
) return;

$event->alerts[] = self::t('Mailchimp syncing is disabled.');
}

// Events: Commerce
// -------------------------------------------------------------------------

Expand Down Expand Up @@ -387,4 +405,4 @@ public static function t ($message, $params = [])
return Craft::t('mailchimp-commerce', $message, $params);
}

}
}
3 changes: 2 additions & 1 deletion src/translations/en/mailchimp-commerce.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
'Mailchimp Commerce' => 'Mailchimp Commerce',
'Never' => 'Never',
'Last Synced to Mailchimp' => 'Last Synced to Mailchimp',
'Mailchimp syncing is disabled.' => 'Mailchimp syncing is disabled.',

// Settings
// =========================================================================
Expand Down Expand Up @@ -86,4 +87,4 @@
'{synced} of {total, plural, =1{1 promo} other{# promos}} have been synced.' => '{synced} of {total, plural, =1{1 promo} other{# promos}} have been synced.',
'Sync All Promos' => 'Sync All Promos',

];
];

0 comments on commit 7773806

Please sign in to comment.