Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #17 from mageplaza/2.4-develop
Browse files Browse the repository at this point in the history
Clean code
  • Loading branch information
haitv282 authored Nov 10, 2020
2 parents 869a710 + 84c740d commit 34dd4ad
Show file tree
Hide file tree
Showing 32 changed files with 954 additions and 959 deletions.
4 changes: 2 additions & 2 deletions Block/Adminhtml/System/Config/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ protected function _getElementHtml(AbstractElement $element)
$this->addData(
[
'button_label' => $originalData['button_label'],
'button_url' => $this->getUrl($originalData['button_url'], ['_current' => true]),
'html_id' => $element->getHtmlId(),
'button_url' => $this->getUrl($originalData['button_url'], ['_current' => true]),
'html_id' => $element->getHtmlId(),
]
);

Expand Down
56 changes: 28 additions & 28 deletions Block/Adminhtml/System/Config/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ public function __construct(
protected function _getElementHtml(AbstractElement $element)
{
$originalData = $element->getOriginalData();
$buttonLabel = !empty($originalData['button_label']) ? $originalData['button_label'] : '';
$buttonLabel = !empty($originalData['button_label']) ? $originalData['button_label'] : '';
$this->addData(
[
'button_label' => __($buttonLabel),
'html_id' => $element->getHtmlId(),
'mp_template' => $this->getOptionTemplate(),
'data_info' => json_encode($this->getOptionTemplate())
'html_id' => $element->getHtmlId(),
'mp_template' => $this->getOptionTemplate(),
'data_info' => json_encode($this->getOptionTemplate())
]
);

Expand All @@ -90,40 +90,40 @@ private function getOptionTemplate()
{
$options = [
[
'label' => __('Default Template'),
'popupHtml' => $this->_helperData->getDefaultTemplateHtml('template3/popup'),
'label' => __('Default Template'),
'popupHtml' => $this->_helperData->getDefaultTemplateHtml('template3/popup'),
'successHtml' => $this->_helperData->getDefaultTemplateHtml('success'),
'background' => '#3d9bc7',
'textColor' => '#000000',
'width' => '800',
'height' => '321'
'background' => '#3d9bc7',
'textColor' => '#000000',
'width' => '800',
'height' => '321'
],
[
'label' => __('Template 1'),
'popupHtml' => $this->_helperData->getDefaultTemplateHtml('template4/popup'),
'label' => __('Template 1'),
'popupHtml' => $this->_helperData->getDefaultTemplateHtml('template4/popup'),
'successHtml' => $this->_helperData->getDefaultTemplateHtml('success'),
'background' => '#fbf5ee',
'textColor' => '#000000',
'width' => '605',
'height' => '330'
'background' => '#fbf5ee',
'textColor' => '#000000',
'width' => '605',
'height' => '330'
],
[
'label' => __('Template 2'),
'popupHtml' => $this->_helperData->getDefaultTemplateHtml('template5/popup'),
'label' => __('Template 2'),
'popupHtml' => $this->_helperData->getDefaultTemplateHtml('template5/popup'),
'successHtml' => $this->_helperData->getDefaultTemplateHtml('success'),
'background' => '#31B0D5',
'textColor' => '#000000',
'width' => '359',
'height' => '260'
'background' => '#31B0D5',
'textColor' => '#000000',
'width' => '359',
'height' => '260'
],
[
'label' => __('Template 3'),
'popupHtml' => $this->_helperData->getDefaultTemplateHtml('template6/popup'),
'label' => __('Template 3'),
'popupHtml' => $this->_helperData->getDefaultTemplateHtml('template6/popup'),
'successHtml' => $this->_helperData->getDefaultTemplateHtml('success'),
'background' => '#31B0D5',
'textColor' => '#000000',
'width' => '800',
'height' => '250'
'background' => '#31B0D5',
'textColor' => '#000000',
'width' => '800',
'height' => '250'
]
];

Expand Down
2 changes: 1 addition & 1 deletion Block/Email/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class Template extends Subscriber
*/
public function getListEmailSubscriberWeek()
{
$listEmail = [];
$listEmail = [];
$subscribersCollection = $this->getSubscriberInWeek($this->_helperData->getStoreId());
foreach ($subscribersCollection as $item) {
$listEmail[] = $item->getData('subscriber_email');
Expand Down
50 changes: 25 additions & 25 deletions Block/Popup.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function __construct(
CollectionFactory $subscriberCollectionFactory,
array $data = []
) {
$this->_helperData = $helperData;
$this->_helperData = $helperData;
$this->_subscriberCollectionFactory = $subscriberCollectionFactory;

parent::__construct($context, $data);
Expand Down Expand Up @@ -114,7 +114,7 @@ public function getTextColor()
*/
public function isFullScreen()
{
return (int) $this->_helperData->getWhatToShowConfig('responsive') === Responsive::FULLSCREEN_POPUP;
return (int)$this->_helperData->getWhatToShowConfig('responsive') === Responsive::FULLSCREEN_POPUP;
}

/**
Expand Down Expand Up @@ -166,7 +166,7 @@ public function getFloatLabel()
*/
public function getPopupAppear()
{
return (int) $this->_helperData->getWhenToShowConfig('popup_appear');
return (int)$this->_helperData->getWhenToShowConfig('popup_appear');
}

/**
Expand Down Expand Up @@ -224,7 +224,7 @@ public function getPopupContent()
{
$htmlConfig = $this->_helperData->getWhatToShowConfig('html_content');

$search = [
$search = [
'{{form_url}}',
'{{url_loader}}',
'{{email_icon_url}}',
Expand Down Expand Up @@ -262,8 +262,8 @@ public function getPopupContent()
public function checkIncludePages()
{
$fullActionName = $this->getRequest()->getFullActionName();
$arrayPages = explode("\n", $this->_helperData->getWhereToShowConfig('include_pages'));
$includePages = array_map('trim', $arrayPages);
$arrayPages = explode("\n", $this->_helperData->getWhereToShowConfig('include_pages'));
$includePages = array_map('trim', $arrayPages);

return in_array($fullActionName, $includePages, true);
}
Expand All @@ -280,7 +280,7 @@ public function checkIncludePaths()

if ($pathsConfig) {
$arrayPaths = explode("\n", $pathsConfig);
$pathsUrl = array_map('trim', $arrayPaths);
$pathsUrl = array_map('trim', $arrayPaths);
foreach ($pathsUrl as $path) {
if ($path && strpos($currentPath, $path) !== false) {
return true;
Expand All @@ -299,8 +299,8 @@ public function checkIncludePaths()
public function checkExcludePages()
{
$fullActionName = $this->getRequest()->getFullActionName();
$arrayPages = explode("\n", $this->_helperData->getWhereToShowConfig('exclude_pages'));
$includePages = array_map('trim', $arrayPages);
$arrayPages = explode("\n", $this->_helperData->getWhereToShowConfig('exclude_pages'));
$includePages = array_map('trim', $arrayPages);

return !in_array($fullActionName, $includePages, true);
}
Expand All @@ -317,7 +317,7 @@ public function checkExcludePaths()

if ($pathsConfig) {
$arrayPaths = explode("\n", $pathsConfig);
$pathsUrl = array_map('trim', $arrayPaths);
$pathsUrl = array_map('trim', $arrayPaths);

foreach ($pathsUrl as $path) {
if (strpos($currentPath, $path) !== false) {
Expand Down Expand Up @@ -357,7 +357,7 @@ public function checkExclude()
public function isManuallyInsert()
{
return $this->_helperData->isEnabled()
&& (int) $this->_helperData->getWhereToShowConfig('which_page_to_show') === PageToShow::MANUALLY_INSERT
&& (int)$this->_helperData->getWhereToShowConfig('which_page_to_show') === PageToShow::MANUALLY_INSERT
&& $this->checkExclude();
}

Expand Down Expand Up @@ -392,24 +392,24 @@ public function checkPagesToShow()
public function getAjaxData()
{
$params = [
'url' => $this->getUrl('betterpopup/ajax/success'),
'isScroll' => $this->getPopupAppear() === Appear::AFTER_SCROLL_DOWN,
'afterSeconds' => [
'url' => $this->getUrl('betterpopup/ajax/success'),
'isScroll' => $this->getPopupAppear() === Appear::AFTER_SCROLL_DOWN,
'afterSeconds' => [
'isAfterSeconds' => $this->getPopupAppear() === Appear::AFTER_X_SECONDS,
'delay' => $this->getDelayConfig()
'delay' => $this->getDelayConfig()
],
'percentage' => $this->getPercentageScroll(),
'fullScreen' => [
'percentage' => $this->getPercentageScroll(),
'fullScreen' => [
'isFullScreen' => $this->isFullScreen(),
'bgColor' => $this->getBackGroundColor()
'bgColor' => $this->getBackGroundColor()
],
'isExitIntent' => $this->isExitIntent(),
'isShowFireworks' => $this->isShowFireworks(),
'popupConfig' => [
'width' => $this->getWidthPopup(),
'height' => $this->getHeightPopup(),
'cookieExp' => $this->getCookieConfig(),
'delay' => $this->getDelayConfig(),
'isExitIntent' => $this->isExitIntent(),
'isShowFireworks' => $this->isShowFireworks(),
'popupConfig' => [
'width' => $this->getWidthPopup(),
'height' => $this->getHeightPopup(),
'cookieExp' => $this->getCookieConfig(),
'delay' => $this->getDelayConfig(),
'showOnDelay' => true,
],
'srcCloseIconWhite' => $this->getViewFileUrl('Mageplaza_BetterPopup::images/icon-close-white.png')
Expand Down
26 changes: 13 additions & 13 deletions Block/Subscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ public function __construct(
) {
parent::__construct($context, $data);

$this->_helperData = $helperData;
$this->_helperData = $helperData;
$this->_subscriberCollectionFactory = $subscriberCollectionFactory;
$this->_getDayDate = $getDayDate;
$this->_getDayDate = $getDayDate;
}

/**
Expand All @@ -94,8 +94,8 @@ public function getSubscriberCollection($from, $to, $storeId)
*/
public function getSubscriberToday()
{
$form = $this->_getDayDate->date(null, '0:0:0');
$to = $this->_getDayDate->date(null, '23:59:59');
$form = $this->_getDayDate->date(null, '0:0:0');
$to = $this->_getDayDate->date(null, '23:59:59');
$collection = $this->getSubscriberCollection($form, $to, $this->_helperData->getStoreId());

return $collection;
Expand All @@ -110,8 +110,8 @@ public function getSubscriberToday()
*/
public function getSubscriberInWeek($storeId = null)
{
$now = date('Y-m-d h:i:s');
$to = date('Y-m-d h:i:s', strtotime('+1 day'));
$now = date('Y-m-d h:i:s');
$to = date('Y-m-d h:i:s', strtotime('+1 day'));
$from = strtotime('-7 day', strtotime($now));
$from = date('Y-m-d h:i:s', $from);

Expand All @@ -125,10 +125,10 @@ public function getSubscriberInWeek($storeId = null)
*/
public function getSubscriberInMonth()
{
$now = date('Y-m-d h:i:s');
$to = date('Y-m-d h:i:s', strtotime('+1 day'));
$from = strtotime('-30 day', strtotime($now));
$from = date('Y-m-d h:i:s', $from);
$now = date('Y-m-d h:i:s');
$to = date('Y-m-d h:i:s', strtotime('+1 day'));
$from = strtotime('-30 day', strtotime($now));
$from = date('Y-m-d h:i:s', $from);
$collection = $this->getSubscriberCollection($from, $to, $this->_helperData->getStoreId());

return $collection;
Expand All @@ -143,9 +143,9 @@ public function getSubscriberInMonth()
*/
public function getUnSubscriberCollection($storeId)
{
$to = date('Y-m-d h:i:s');
$from = strtotime('-7 day', strtotime($to));
$from = date('Y-m-d h:i:s', $from);
$to = date('Y-m-d h:i:s');
$from = strtotime('-7 day', strtotime($to));
$from = date('Y-m-d h:i:s', $from);
$unSubscribersCollection = $this->_subscriberCollectionFactory->create()
->addFieldToFilter('subscriber_status', \Magento\Newsletter\Model\Subscriber::STATUS_UNSUBSCRIBED)
->addFieldToFilter('change_status_at', ['from' => $from, 'to' => $to])
Expand Down
2 changes: 1 addition & 1 deletion Block/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function getCouponCode()
return $couponCode;
}
$data = [
'rule_id' => $this->_helperData->getWhatToShowConfig('popup_success/rule_id'),
'rule_id' => $this->_helperData->getWhatToShowConfig('popup_success/rule_id'),
'coupon_pattern' => $this->_helperData->getWhatToShowConfig('popup_success/coupon_pattern'),
];

Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CHANGELOG: https://www.mageplaza.com/releases/better-popup/
CHANGELOG: https://www.mageplaza.com/releases/better-popup/
32 changes: 16 additions & 16 deletions Controller/Adminhtml/Send/Send.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ public function __construct(
) {
parent::__construct($context);

$this->_helperData = $helperData;
$this->_template = $template;
$this->_helperData = $helperData;
$this->_template = $template;
$this->_transportBuilder = $transportBuilder;
$this->_storeManager = $storeManager;
$this->logger = $logger;
$this->_storeManager = $storeManager;
$this->logger = $logger;
}

/**
Expand All @@ -99,26 +99,26 @@ public function __construct(
public function execute()
{
$result['status'] = false;
$toEmail = $this->_helperData->getToEmail();
$toEmail = $this->_helperData->getToEmail();

if ($toEmail) {
try {
foreach ($this->_storeManager->getStores() as $store) {
$isSendMail = $this->_helperData->getSendEmailConfig('isSendEmail', $store->getId());
$isEnable = $this->_helperData->isEnabled($store->getId());
$isEnable = $this->_helperData->isEnabled($store->getId());
if ($isEnable && $isSendMail) {
$this->sendMail($store);
}
}

$result['status'] = true;
$result['status'] = true;
$result['content'] = __('Sent successfully! Please check your email box.');
} catch (Exception $e) {
$result['content'] = __('There is an error occurred while sending email. Please try again later.');
$this->logger->critical($e);
}
} else {
$result['status'] = false;
$result['status'] = false;
$result['content'] = __('Please enter email and save config');
}

Expand All @@ -141,21 +141,21 @@ public function sendMail($store)
return null;
}

$subscriber = $this->_template->getSubscriberInWeek($store->getId())->getSize();
$subscriber = $this->_template->getSubscriberInWeek($store->getId())->getSize();
$unSubscriber = $this->_template->getunSubscriberCollection($store->getId())->getSize();
$currentTime = $this->_template->getCurrentTime();
$store_name = $store->getName();
$currentTime = $this->_template->getCurrentTime();
$store_name = $store->getName();

$vars = [
'mp_subscriber' => $subscriber,
$vars = [
'mp_subscriber' => $subscriber,
'mp_unSubscriber' => $unSubscriber,
'currentTime' => $currentTime,
'store_name' => $store_name
'currentTime' => $currentTime,
'store_name' => $store_name
];
$transport = $this->_transportBuilder
->setTemplateIdentifier('mageplaza_betterpopup_template')
->setTemplateOptions([
'area' => Area::AREA_FRONTEND,
'area' => Area::AREA_FRONTEND,
'store' => $store->getId()
])
->setFrom('general')
Expand Down
6 changes: 3 additions & 3 deletions Controller/Ajax/Success.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct(
LayoutFactory $resultLayoutFactory
) {
$this->resultLayoutFactory = $resultLayoutFactory;
$this->resultJsonFactory = $resultJsonFactory;
$this->resultJsonFactory = $resultJsonFactory;

parent::__construct($context);
}
Expand All @@ -68,9 +68,9 @@ public function __construct(
*/
public function execute()
{
$result = $this->resultJsonFactory->create();
$result = $this->resultJsonFactory->create();
$resultLayout = $this->resultLayoutFactory->create();
$blockHtml = $resultLayout->getLayout()
$blockHtml = $resultLayout->getLayout()
->createBlock(\Mageplaza\BetterPopup\Block\Success::class)
->toHtml();
$result->setData(['success' => $blockHtml]);
Expand Down
Loading

0 comments on commit 34dd4ad

Please sign in to comment.