Skip to content

Commit d38bafa

Browse files
committed
Disable newsletter signup
0 parents  commit d38bafa

File tree

11 files changed

+458
-0
lines changed

11 files changed

+458
-0
lines changed
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<?php
2+
/**
3+
* Copyright © MagePal LLC. All rights reserved.
4+
* See COPYING.txt for license details.
5+
* http://www.magepal.com | [email protected]
6+
*/
7+
8+
namespace MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Composer;
9+
10+
class Version extends \Magento\Config\Block\System\Config\Form\Field
11+
{
12+
13+
/**
14+
* @var \Magento\Framework\App\DeploymentConfig
15+
*/
16+
protected $deploymentConfig;
17+
18+
/**
19+
* @var \Magento\Framework\Component\ComponentRegistrarInterface
20+
*/
21+
protected $componentRegistrar;
22+
23+
/**
24+
* @var \Magento\Framework\Filesystem\Directory\ReadFactory
25+
*/
26+
protected $readFactory;
27+
28+
/**
29+
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
30+
* @param \Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar
31+
* @param \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory
32+
*/
33+
public function __construct(
34+
\Magento\Backend\Block\Template\Context $context,
35+
\Magento\Framework\App\DeploymentConfig $deploymentConfig,
36+
\Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar,
37+
\Magento\Framework\Filesystem\Directory\ReadFactory $readFactory,
38+
array $data = []
39+
) {
40+
$this->deploymentConfig = $deploymentConfig;
41+
$this->componentRegistrar = $componentRegistrar;
42+
$this->readFactory = $readFactory;
43+
parent::__construct($context, $data);
44+
}
45+
46+
/**
47+
* Render button
48+
*
49+
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
50+
* @return string
51+
* @throws \Magento\Framework\Exception\LocalizedException
52+
*/
53+
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
54+
{
55+
// Remove scope label
56+
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
57+
return parent::render($element);
58+
}
59+
60+
/**
61+
* Return element html
62+
*
63+
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
64+
* @return string
65+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
66+
*/
67+
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
68+
{
69+
return 'v' . $this->getVersion();
70+
}
71+
72+
/**
73+
* Get Module version number
74+
*
75+
* @return string
76+
*/
77+
public function getVersion()
78+
{
79+
return $this->getComposerVersion($this->getModuleName());
80+
}
81+
82+
/**
83+
* @return string
84+
*/
85+
public function getModuleName()
86+
{
87+
$classArray = explode('\\', get_class($this));
88+
89+
return count($classArray) > 2 ? "{$classArray[0]}_{$classArray[1]}" : '';
90+
}
91+
92+
/**
93+
* Get module composer version
94+
*
95+
* @param $moduleName
96+
* @return \Magento\Framework\Phrase|string|void
97+
*/
98+
public function getComposerVersion($moduleName)
99+
{
100+
$path = $this->componentRegistrar->getPath(
101+
\Magento\Framework\Component\ComponentRegistrar::MODULE,
102+
$moduleName
103+
);
104+
105+
try {
106+
$directoryRead = $this->readFactory->create($path);
107+
$composerJsonData = $directoryRead->readFile('composer.json');
108+
109+
if ($composerJsonData) {
110+
$data = json_decode($composerJsonData);
111+
return !empty($data->version) ? $data->version : __('Unknown');
112+
}
113+
} catch (\Exception $e) {
114+
//
115+
}
116+
117+
return 'Unknown';
118+
}
119+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Copyright © MagePal LLC. All rights reserved.
4+
* See COPYING.txt for license details.
5+
* http://www.magepal.com | [email protected]
6+
*/
7+
8+
namespace MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Module;
9+
10+
class Version extends \Magento\Config\Block\System\Config\Form\Field
11+
{
12+
13+
/**
14+
* @var \Magento\Framework\Module\ModuleListInterface
15+
*/
16+
protected $_moduleList;
17+
18+
/**
19+
* @param \Magento\Backend\Block\Template\Context $context
20+
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
21+
* @param array $data
22+
*/
23+
public function __construct(
24+
\Magento\Backend\Block\Template\Context $context,
25+
\Magento\Framework\Module\ModuleListInterface $moduleList,
26+
array $data = []
27+
) {
28+
parent::__construct($context, $data);
29+
$this->_moduleList = $moduleList;
30+
}
31+
32+
/**
33+
* Render button
34+
*
35+
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
36+
* @return string
37+
* @throws \Magento\Framework\Exception\LocalizedException
38+
*/
39+
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
40+
{
41+
// Remove scope label
42+
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
43+
return parent::render($element);
44+
}
45+
46+
/**
47+
* Return element html
48+
*
49+
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
50+
* @return string
51+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
52+
*/
53+
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
54+
{
55+
return 'v' . $this->getVersion();
56+
}
57+
58+
/**
59+
* Get Module version number
60+
*
61+
* @return string
62+
*/
63+
public function getVersion()
64+
{
65+
$moduleInfo = $this->_moduleList->getOne($this->getModuleName());
66+
return $moduleInfo['setup_version'];
67+
}
68+
69+
/**
70+
* @return string
71+
*/
72+
public function getModuleName()
73+
{
74+
$classArray = explode('\\', get_class($this));
75+
76+
return count($classArray) > 2 ? "{$classArray[0]}_{$classArray[1]}" : '';
77+
}
78+
}

Helper/Data.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
/**
3+
* Copyright © MagePal LLC. All rights reserved.
4+
* See COPYING.txt for license details.
5+
* http://www.magepal.com | [email protected]
6+
*/
7+
8+
namespace MagePal\NewsletterSignupEmail\Helper;
9+
10+
class Data extends \Magento\Framework\App\Helper\AbstractHelper
11+
{
12+
const XML_PATH_ACTIVE = 'newsletter_signup_email/general/active';
13+
14+
/**
15+
* If enabled
16+
*
17+
* @return bool
18+
*/
19+
public function isEnabled()
20+
{
21+
return !$this->scopeConfig->isSetFlag(
22+
self::XML_PATH_ACTIVE,
23+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
24+
);
25+
}
26+
}

Plugin/Model/SubscriberPlugin.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php
2+
/**
3+
* Copyright © MagePal LLC. All rights reserved.
4+
* See COPYING.txt for license details.
5+
* http://www.magepal.com | [email protected]
6+
*/
7+
namespace MagePal\NewsletterSignupEmail\Plugin\Model;
8+
9+
class SubscriberPlugin
10+
{
11+
12+
/** @var \MagePal\NewsletterSignupEmail\Helper\Data */
13+
protected $helper;
14+
15+
public function __construct(
16+
\MagePal\NewsletterSignupEmail\Helper\Data $helper
17+
) {
18+
$this->helper = $helper;
19+
}
20+
21+
/**
22+
* @param \Magento\Newsletter\Model\Subscriber $subject
23+
* @param callable $proceed
24+
*/
25+
public function aroundSendUnsubscriptionEmail(\Magento\Newsletter\Model\Subscriber $subject, callable $proceed)
26+
{
27+
if($this->helper->isEnabled()){
28+
$proceed();
29+
}
30+
}
31+
32+
/**
33+
* @param \Magento\Newsletter\Model\Subscriber $subject
34+
* @param callable $proceed
35+
*/
36+
public function aroundSendConfirmationRequestEmail(\Magento\Newsletter\Model\Subscriber $subject, callable $proceed)
37+
{
38+
if($this->helper->isEnabled()){
39+
$proceed();
40+
}
41+
}
42+
43+
/**
44+
* @param \Magento\Newsletter\Model\Subscriber $subject
45+
* @param callable $proceed
46+
*/
47+
public function aroundSendConfirmationSuccessEmail(\Magento\Newsletter\Model\Subscriber $subject, callable $proceed)
48+
{
49+
if($this->helper->isEnabled()){
50+
$proceed();
51+
}
52+
}
53+
}

README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<a href="http://www.magepal.com" title="Top Magento 2 Extension Provider" ><img src="https://image.ibb.co/dHBkYH/Magepal_logo.png" width="100" align="right" alt="Magento Extension Provider" /></a>
2+
3+
## Enable/Disable Newsletter Signup Email by MagePal
4+
5+
6+
Quickly disable unwanted newsletter signup and unsubscribe emails.
7+
8+
9+
#### Step 1
10+
##### Using Composer (recommended)
11+
```
12+
composer require magepal/magento2-newsletter-signup-email
13+
```
14+
15+
##### Manually (not recommended)
16+
* Download the extension
17+
* Unzip the file
18+
* Create a folder {Magento 2 root}/app/code/MagePal/NewsletterSignupEmail
19+
* Copy the content from the unzip folder
20+
21+
22+
#### Step 2 - Enable extension ("cd" to {Magento root} folder)
23+
```
24+
php -f bin/magento module:enable --clear-static-content MagePal_GeoIp
25+
php -f bin/magento setup:upgrade
26+
```
27+
28+
29+
Contribution
30+
---
31+
Want to contribute to this extension? The quickest way is to open a [pull request on GitHub](https://help.github.com/articles/using-pull-requests).
32+
33+
34+
Support
35+
---
36+
If you encounter any problems or bugs, please open an issue on [GitHub](https://github.com/magepal/magento2-newsletter-signup-email/issues).
37+
38+
Need help setting up or want to customize this extension to meet your business needs? Please email [email protected] and if we like your idea we will add this feature for free or at a discounted rate.
39+
40+
Magento 2 Plugins
41+
---
42+
[Custom SMTP](https://www.magepal.com/magento2/extensions/custom-smtp.html) | [Google Tag Manager](https://www.magepal.com/magento2/extensions/google-tag-manager.html) | [Enhanced E-commerce](https://www.magepal.com/magento2/extensions/enhanced-ecommerce-for-google-tag-manager.html) | [Reindex](https://www.magepal.com/magento2/extensions/reindex.html) | [Custom Shipping Method](https://www.magepal.com/magento2/extensions/custom-shipping-rates-for-magento-2.html) | [Preview Order Confirmation](https://www.magepal.com/magento2/extensions/preview-order-confirmation-page-for-magento-2.html) | [Guest to Customer](https://www.magepal.com/magento2/extensions/guest-to-customer.html) | [Admin Form Fields Manager](https://www.magepal.com/magento2/extensions/admin-form-fields-manager-for-magento-2.html) | [Customer Dashboard Links Manager](https://www.magepal.com/magento2/extensions/customer-dashboard-links-manager-for-magento-2.html) | [Lazy Loader](https://www.magepal.com/magento2/extensions/lazy-load.html) | [Order Confirmation Page Miscellaneous Scripts](https://www.magepal.com/magento2/extensions/order-confirmation-miscellaneous-scripts-for-magento-2.html)
43+
44+
© MagePal LLC. | [www.magepal.com](http:/www.magepal.com)

composer.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "magepal/magento2-newsletter-signup-email",
3+
"description": "Enable/Disable Newsletter Signup Email",
4+
"keywords": [
5+
"magento 2",
6+
"newsletter",
7+
"magento2 newsletter"
8+
],
9+
"license": [
10+
"proprietary"
11+
],
12+
"homepage": "http://www.magepal.com/",
13+
"support": {
14+
"email": "[email protected]",
15+
"issues": "https://github.com/magepal/magento2-google-tag-manager/issues/"
16+
},
17+
"authors": [
18+
{
19+
"name": "Renon Stewart",
20+
"email": "[email protected]",
21+
"homepage": "http://www.magepal.com/",
22+
"role": "Leader"
23+
}
24+
],
25+
"require": {
26+
"php": "~5.6.0|7.0.2|7.0.4|~7.0.6|~7.1.0",
27+
"magento/module-backend": "100.0.*|100.1.*|100.2.*",
28+
"magento/framework": "100.0.*|100.1.*|101.0.*",
29+
"magento/module-newsletter": "*"
30+
},
31+
"type": "magento2-module",
32+
"version": "1.1.0",
33+
"autoload": {
34+
"files": [
35+
"registration.php"
36+
],
37+
"psr-4": {
38+
"MagePal\\NewsletterSignupEmail\\": ""
39+
}
40+
}
41+
}

etc/acl.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © MagePal LLC. All rights reserved.
5+
* See COPYING.txt for license details.
6+
* http://www.magepal.com | [email protected]
7+
*/
8+
-->
9+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
10+
<acl>
11+
<resources>
12+
<resource id="Magento_Backend::admin">
13+
<resource id="Magento_Backend::stores">
14+
<resource id="Magento_Backend::stores_settings">
15+
<resource id="Magento_Config::config">
16+
<resource id="MagePal_NewsletterSignupEmail::magepal_newsletter_signup_email" title="Newsletter Signup Email" />
17+
</resource>
18+
</resource>
19+
</resource>
20+
</resource>
21+
</resources>
22+
</acl>
23+
</config>

0 commit comments

Comments
 (0)