Skip to content

Commit

Permalink
Disable newsletter signup
Browse files Browse the repository at this point in the history
  • Loading branch information
srenon committed Oct 16, 2018
0 parents commit d38bafa
Show file tree
Hide file tree
Showing 11 changed files with 458 additions and 0 deletions.
119 changes: 119 additions & 0 deletions Block/Adminhtml/System/Config/Form/Composer/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
<?php
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
*/

namespace MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Composer;

class Version extends \Magento\Config\Block\System\Config\Form\Field
{

/**
* @var \Magento\Framework\App\DeploymentConfig
*/
protected $deploymentConfig;

/**
* @var \Magento\Framework\Component\ComponentRegistrarInterface
*/
protected $componentRegistrar;

/**
* @var \Magento\Framework\Filesystem\Directory\ReadFactory
*/
protected $readFactory;

/**
* @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
* @param \Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar
* @param \Magento\Framework\Filesystem\Directory\ReadFactory $readFactory
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\App\DeploymentConfig $deploymentConfig,
\Magento\Framework\Component\ComponentRegistrarInterface $componentRegistrar,
\Magento\Framework\Filesystem\Directory\ReadFactory $readFactory,
array $data = []
) {
$this->deploymentConfig = $deploymentConfig;
$this->componentRegistrar = $componentRegistrar;
$this->readFactory = $readFactory;
parent::__construct($context, $data);
}

/**
* Render button
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
// Remove scope label
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}

/**
* Return element html
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
return 'v' . $this->getVersion();
}

/**
* Get Module version number
*
* @return string
*/
public function getVersion()
{
return $this->getComposerVersion($this->getModuleName());
}

/**
* @return string
*/
public function getModuleName()
{
$classArray = explode('\\', get_class($this));

return count($classArray) > 2 ? "{$classArray[0]}_{$classArray[1]}" : '';
}

/**
* Get module composer version
*
* @param $moduleName
* @return \Magento\Framework\Phrase|string|void
*/
public function getComposerVersion($moduleName)
{
$path = $this->componentRegistrar->getPath(
\Magento\Framework\Component\ComponentRegistrar::MODULE,
$moduleName
);

try {
$directoryRead = $this->readFactory->create($path);
$composerJsonData = $directoryRead->readFile('composer.json');

if ($composerJsonData) {
$data = json_decode($composerJsonData);
return !empty($data->version) ? $data->version : __('Unknown');
}
} catch (\Exception $e) {
//
}

return 'Unknown';
}
}
78 changes: 78 additions & 0 deletions Block/Adminhtml/System/Config/Form/Module/Version.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
*/

namespace MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Module;

class Version extends \Magento\Config\Block\System\Config\Form\Field
{

/**
* @var \Magento\Framework\Module\ModuleListInterface
*/
protected $_moduleList;

/**
* @param \Magento\Backend\Block\Template\Context $context
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
* @param array $data
*/
public function __construct(
\Magento\Backend\Block\Template\Context $context,
\Magento\Framework\Module\ModuleListInterface $moduleList,
array $data = []
) {
parent::__construct($context, $data);
$this->_moduleList = $moduleList;
}

/**
* Render button
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
// Remove scope label
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}

/**
* Return element html
*
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
* @return string
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function _getElementHtml(\Magento\Framework\Data\Form\Element\AbstractElement $element)
{
return 'v' . $this->getVersion();
}

/**
* Get Module version number
*
* @return string
*/
public function getVersion()
{
$moduleInfo = $this->_moduleList->getOne($this->getModuleName());
return $moduleInfo['setup_version'];
}

/**
* @return string
*/
public function getModuleName()
{
$classArray = explode('\\', get_class($this));

return count($classArray) > 2 ? "{$classArray[0]}_{$classArray[1]}" : '';
}
}
26 changes: 26 additions & 0 deletions Helper/Data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
*/

namespace MagePal\NewsletterSignupEmail\Helper;

class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
const XML_PATH_ACTIVE = 'newsletter_signup_email/general/active';

/**
* If enabled
*
* @return bool
*/
public function isEnabled()
{
return !$this->scopeConfig->isSetFlag(
self::XML_PATH_ACTIVE,
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
);
}
}
53 changes: 53 additions & 0 deletions Plugin/Model/SubscriberPlugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
*/
namespace MagePal\NewsletterSignupEmail\Plugin\Model;

class SubscriberPlugin
{

/** @var \MagePal\NewsletterSignupEmail\Helper\Data */
protected $helper;

public function __construct(
\MagePal\NewsletterSignupEmail\Helper\Data $helper
) {
$this->helper = $helper;
}

/**
* @param \Magento\Newsletter\Model\Subscriber $subject
* @param callable $proceed
*/
public function aroundSendUnsubscriptionEmail(\Magento\Newsletter\Model\Subscriber $subject, callable $proceed)
{
if($this->helper->isEnabled()){
$proceed();
}
}

/**
* @param \Magento\Newsletter\Model\Subscriber $subject
* @param callable $proceed
*/
public function aroundSendConfirmationRequestEmail(\Magento\Newsletter\Model\Subscriber $subject, callable $proceed)
{
if($this->helper->isEnabled()){
$proceed();
}
}

/**
* @param \Magento\Newsletter\Model\Subscriber $subject
* @param callable $proceed
*/
public function aroundSendConfirmationSuccessEmail(\Magento\Newsletter\Model\Subscriber $subject, callable $proceed)
{
if($this->helper->isEnabled()){
$proceed();
}
}
}
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<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>

## Enable/Disable Newsletter Signup Email by MagePal


Quickly disable unwanted newsletter signup and unsubscribe emails.


#### Step 1
##### Using Composer (recommended)
```
composer require magepal/magento2-newsletter-signup-email
```

##### Manually (not recommended)
* Download the extension
* Unzip the file
* Create a folder {Magento 2 root}/app/code/MagePal/NewsletterSignupEmail
* Copy the content from the unzip folder


#### Step 2 - Enable extension ("cd" to {Magento root} folder)
```
php -f bin/magento module:enable --clear-static-content MagePal_GeoIp
php -f bin/magento setup:upgrade
```


Contribution
---
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).


Support
---
If you encounter any problems or bugs, please open an issue on [GitHub](https://github.com/magepal/magento2-newsletter-signup-email/issues).

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.

Magento 2 Plugins
---
[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)

© MagePal LLC. | [www.magepal.com](http:/www.magepal.com)
41 changes: 41 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "magepal/magento2-newsletter-signup-email",
"description": "Enable/Disable Newsletter Signup Email",
"keywords": [
"magento 2",
"newsletter",
"magento2 newsletter"
],
"license": [
"proprietary"
],
"homepage": "http://www.magepal.com/",
"support": {
"email": "[email protected]",
"issues": "https://github.com/magepal/magento2-google-tag-manager/issues/"
},
"authors": [
{
"name": "Renon Stewart",
"email": "[email protected]",
"homepage": "http://www.magepal.com/",
"role": "Leader"
}
],
"require": {
"php": "~5.6.0|7.0.2|7.0.4|~7.0.6|~7.1.0",
"magento/module-backend": "100.0.*|100.1.*|100.2.*",
"magento/framework": "100.0.*|100.1.*|101.0.*",
"magento/module-newsletter": "*"
},
"type": "magento2-module",
"version": "1.1.0",
"autoload": {
"files": [
"registration.php"
],
"psr-4": {
"MagePal\\NewsletterSignupEmail\\": ""
}
}
}
23 changes: 23 additions & 0 deletions etc/acl.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0"?>
<!--
/**
* Copyright © MagePal LLC. All rights reserved.
* See COPYING.txt for license details.
* http://www.magepal.com | [email protected]
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Acl/etc/acl.xsd">
<acl>
<resources>
<resource id="Magento_Backend::admin">
<resource id="Magento_Backend::stores">
<resource id="Magento_Backend::stores_settings">
<resource id="Magento_Config::config">
<resource id="MagePal_NewsletterSignupEmail::magepal_newsletter_signup_email" title="Newsletter Signup Email" />
</resource>
</resource>
</resource>
</resource>
</resources>
</acl>
</config>
Loading

0 comments on commit d38bafa

Please sign in to comment.