Skip to content

Commit

Permalink
Hard disable popup if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
firstred committed Apr 18, 2018
1 parent 87f9c2c commit aec76b3
Showing 1 changed file with 41 additions and 3 deletions.
44 changes: 41 additions & 3 deletions mailchimp.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class MailChimp extends Module

const GDPR = 'MAILCHIMP_GDPR';
const EXPORT_COUNTRY = 'MAILCHIMP_EXPORT_COUNTRY';
const DISABLE_POPUP = 'MAILCHIMP_DISABLE_POPUP';

/** @var string $baseUrl */
public $baseUrl;
Expand Down Expand Up @@ -328,7 +329,7 @@ public function hookDisplayHeader()
$cookie->write();
}

if (static::getApiKey() && static::$uuid) {
if (static::getApiKey() && static::$uuid && !Configuration::get(static::DISABLE_POPUP)) {
$shop = MailChimpShop::getByShopId($this->context->shop->id);
if (!Validate::isLoadedObject($shop)) {
return '';
Expand Down Expand Up @@ -1154,6 +1155,7 @@ protected function postProcess()
&& Configuration::updateValue(static::EXPORT_OPT_IN, $importOptedIn, false, 0, 0)
&& Configuration::updateValue(static::GDPR, (bool) Tools::getvalue(static::GDPR, false), false, 0 ,0)
&& Configuration::updateValue(static::EXPORT_COUNTRY, (bool) Tools::getvalue(static::EXPORT_COUNTRY), false, 0, 0)
&& Configuration::updateValue(static::DISABLE_POPUP, (bool) Tools::getvalue(static::DISABLE_POPUP), false, 0, 0)
) {
$this->addConfirmation($this->l('Settings updated.'));
} else {
Expand Down Expand Up @@ -1551,7 +1553,7 @@ protected function displayApiForm()
],
];

$fieldsForm2 = [
$fields[] = [
'form' => [
'legend' => [
'title' => $this->l('Export Settings'),
Expand All @@ -1566,7 +1568,40 @@ protected function displayApiForm()
],
];

$fields[] = $fieldsForm2;
$fields[] = [
'form' => [
'legend' => [
'title' => $this->l('Miscellaneous'),
'icon' => 'icon-cogs',
],
'input' => [
[
'type' => 'switch',
'label' => $this->l('Disable MailChimp popup'),
'name' => static::DISABLE_POPUP,
'desc' => $this->l('For privacy purposes you can prevent the popup script from loading'),
'id' => 'importOptedIn',
'values' => [
[
'id' => static::DISABLE_POPUP.'_on',
'value' => 1,
'label' => $this->l('Enabled'),
],
[
'id' => static::DISABLE_POPUP.'_off',
'value' => 0,
'label' => $this->l('Disabled'),
],
],
],
],
'submit' => [
'title' => $this->l('Save'),
'class' => 'btn btn-default pull-right',
'name' => 'submitSettings',
],
],
];
}

$helper = new HelperForm();
Expand Down Expand Up @@ -1729,6 +1764,7 @@ protected function displayCronForm()
*
* @since 1.0.0
* @throws PrestaShopException
* @throws Adapter_Exception
*/
protected function getConfigFieldsValues()
{
Expand All @@ -1739,6 +1775,7 @@ protected function getConfigFieldsValues()
static::DATE_CUTOFF => date('Y-m-d', strtotime(static::getOrderDateCutoff())),
static::GDPR => (bool) Configuration::get(static::GDPR, false, 0, 0),
static::EXPORT_COUNTRY => (bool) Configuration::get(static::EXPORT_COUNTRY, false, 0, 0),
static::DISABLE_POPUP => (bool) Configuration::get(static::DISABLE_POPUP, false, 0, 0),
];

$paidStatuses = [];
Expand Down Expand Up @@ -2239,6 +2276,7 @@ protected function loadTabs()
*
* @return bool Indicates whether the API key is valid
* @throws PrestaShopException
* @throws Adapter_Exception
*/
protected function checkApiKey()
{
Expand Down

0 comments on commit aec76b3

Please sign in to comment.