Skip to content

Commit

Permalink
NAM-34725 add option to enable bee popup from the plugin settings (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
ronshenk authored Nov 13, 2024
1 parent 6ff7993 commit d940825
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 3 deletions.
9 changes: 9 additions & 0 deletions Block/Adminhtml/Settings/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function __construct(
$this->sms_consent_enabled = $configHelper->getValue(ConfigHelper::SMS_CONSENT_ENABLED);
$this->sms_consent_checkbox_position = $configHelper->getValue(ConfigHelper::SMS_CONSENT_CHECKBOX_POSITION);
$this->sms_consent_checkbox_lable_value = $configHelper->getValue(ConfigHelper::SMS_CONSENT_CHECKBOX_LABEL_VALUE);
$this->popup_enabled = $configHelper->getValue(ConfigHelper::POPUP_ENABLED);
$aw_service = $rewardPointsFactory->create();
if ($aw_service) {
$this->is_aw_points_plugin_exists = true;
Expand Down Expand Up @@ -194,4 +195,12 @@ public function getFormFieldPositions()
{
return range(0 , 1000, 10);
}

/**
* @return int|mixed
*/
public function getPopupEnabled()
{
return $this->popup_enabled;
}
}
16 changes: 15 additions & 1 deletion Block/Frontend/Tracking/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Magento\Store\Model\StoreManager;
use Magento\Framework\View\Element\Template\Context;
use \Remarkety\Mgconnector\Helper\ConfigHelper;
use \Remarkety\Mgconnector\Model\Webtracking;
use \Magento\Customer\Model\Session;

Expand All @@ -12,18 +13,21 @@ class Base extends \Magento\Framework\View\Element\Template
protected $_activeStore = null;
protected $_webtracking;
protected $_session;
protected $config_helper;

public function __construct(
Context $context,
array $data,
StoreManager $sManager,
Webtracking $webtracking,
Session $session
Session $session,
ConfigHelper $config_helper
) {
parent::__construct($context, $data);
$this->_activeStore = $sManager->getStore();
$this->_webtracking = $webtracking;
$this->_session = $session;
$this->config_helper = $config_helper;
}

public function isWebtrackingActivated()
Expand All @@ -50,4 +54,14 @@ public function getEmail()
$email = $this->_session->getSubscriberEmail();
return empty($email) ? false : $email;
}

private function getConfig($config)
{
return $this->config_helper->getValue($config);
}

public function isPopupEnabled()
{
return $this->config_helper->getValue(ConfigHelper::POPUP_ENABLED) == 1;
}
}
6 changes: 4 additions & 2 deletions Block/Frontend/Tracking/General.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use Magento\Store\Model\StoreManager;
use Magento\Framework\View\Element\Template\Context;
use \Remarkety\Mgconnector\Helper\ConfigHelper;
use \Remarkety\Mgconnector\Model\Webtracking;
use Magento\Customer\Model\Session;

Expand All @@ -13,9 +14,10 @@ public function __construct(
array $data,
StoreManager $sManager,
Webtracking $webtracking,
Session $session
Session $session,
ConfigHelper $configHelper
) {
parent::__construct($context, $data, $sManager, $webtracking, $session);
parent::__construct($context, $data, $sManager, $webtracking, $session, $configHelper);
$this->_isScopePrivate = true;
}
}
4 changes: 4 additions & 0 deletions Controller/Adminhtml/Settings/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,10 @@ private function saveSettings($data)
$this->configHelper->setValue(ConfigHelper::SMS_CONSENT_CHECKBOX_LABEL_VALUE, $data['sms_consent_checkbox_lable_value']);
}

if (isset($data['popup_enabled'])) {
$this->configHelper->setValue(ConfigHelper::POPUP_ENABLED, $data['popup_enabled']);
}

return true;
}
}
7 changes: 7 additions & 0 deletions Helper/ConfigHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class ConfigHelper
const SMS_CONSENT_ENABLED = 'remarkety/mgconnector/sms_consent_enabled';
const SMS_CONSENT_CHECKBOX_POSITION = 'remarkety/mgconnector/sms_consent_checkbox_position';
const SMS_CONSENT_CHECKBOX_LABEL_VALUE = 'remarkety/mgconnector/sms_consent_checkbox_lable_value';
const POPUP_ENABLED = 'remarkety/mgconnector/popup_enabled';

/**
* should we get marketing consent saved in shopper attribute, if set to 0 then we don't get the data
* added this setting just in case we see performance degradation in production stores
Expand Down Expand Up @@ -155,6 +157,11 @@ public function isEventCategoryViewEnabled()
return $category_view_code == 1;
}

public function isPopupEnabled()
{
return $this->_scopeConfig->getValue(self::POPUP_ENABLED) == 1;
}

/**
* @param string $code
*/
Expand Down
20 changes: 20 additions & 0 deletions view/adminhtml/templates/settings.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,26 @@
</div>
</fieldset>

<fieldset class="admin__fieldset">
<legend class="admin__legend">Popup</legend>
<div class="admin__field">
<label for="popup_enabled" class="admin__field-label">
<span><?php echo __('Popup Enabled') ?></span>
</label>

<div class="admin__field-control _with-tooltip">
<select id="popup_enabled" name="popup_enabled" class="admin__control-select">
<?php foreach ($this->getEnabledDisabledOptions() as $code => $name): ?>
<option
value="<?php echo $code; ?>"
<?php if ($code && $this->getPopupEnabled()) { echo 'selected="selected"'; } ?>
><?php echo $name; ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
</fieldset>

<fieldset class="admin__fieldset">
<legend class="admin__legend">Email Consent on Checkout Page</legend>
<div class="admin__field">
Expand Down
12 changes: 12 additions & 0 deletions view/frontend/templates/general.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,16 @@
g.src = 'https://d3ryumxhbd2uw7.cloudfront.net/webtracking/track.js';
s.parentNode.insertBefore(g, s);
}(document, 'script'));</script>
<?php if ($block->isPopupEnabled()): ?>
<script language="javascript">
var appId='<?php echo $block->getRemarketyPublicId(); ?>';
function loadScript(src, callback) {
var s,r,t;r = false;s = document.createElement('script');
s.type = 'text/javascript';s.src = src;
s.onload = s.onreadystatechange = function(){
if (!r && (!this.readyState || this.readyState == 'complete')){r = true;callback();}
};t = document.getElementsByTagName('script')[0];t.parentNode.insertBefore(s, t); }
loadScript("https://d3ryumxhbd2uw7.cloudfront.net/popup/bee_popup.js", function(){});
</script>
<?php endif; ?>
<?php endif; ?>

0 comments on commit d940825

Please sign in to comment.