From d38bafa2b253874d1e44f93e08fe99bcd42d4a99 Mon Sep 17 00:00:00 2001 From: Renon Stewart Date: Tue, 16 Oct 2018 17:18:14 -0400 Subject: [PATCH] Disable newsletter signup --- .../System/Config/Form/Composer/Version.php | 119 ++++++++++++++++++ .../System/Config/Form/Module/Version.php | 78 ++++++++++++ Helper/Data.php | 26 ++++ Plugin/Model/SubscriberPlugin.php | 53 ++++++++ README.md | 44 +++++++ composer.json | 41 ++++++ etc/acl.xml | 23 ++++ etc/adminhtml/system.xml | 46 +++++++ etc/di.xml | 15 +++ etc/module.xml | 6 + registration.php | 7 ++ 11 files changed, 458 insertions(+) create mode 100644 Block/Adminhtml/System/Config/Form/Composer/Version.php create mode 100644 Block/Adminhtml/System/Config/Form/Module/Version.php create mode 100644 Helper/Data.php create mode 100644 Plugin/Model/SubscriberPlugin.php create mode 100755 README.md create mode 100644 composer.json create mode 100644 etc/acl.xml create mode 100644 etc/adminhtml/system.xml create mode 100644 etc/di.xml create mode 100644 etc/module.xml create mode 100644 registration.php diff --git a/Block/Adminhtml/System/Config/Form/Composer/Version.php b/Block/Adminhtml/System/Config/Form/Composer/Version.php new file mode 100644 index 0000000..67748f8 --- /dev/null +++ b/Block/Adminhtml/System/Config/Form/Composer/Version.php @@ -0,0 +1,119 @@ +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'; + } +} diff --git a/Block/Adminhtml/System/Config/Form/Module/Version.php b/Block/Adminhtml/System/Config/Form/Module/Version.php new file mode 100644 index 0000000..3300eab --- /dev/null +++ b/Block/Adminhtml/System/Config/Form/Module/Version.php @@ -0,0 +1,78 @@ +_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]}" : ''; + } +} diff --git a/Helper/Data.php b/Helper/Data.php new file mode 100644 index 0000000..11956a2 --- /dev/null +++ b/Helper/Data.php @@ -0,0 +1,26 @@ +scopeConfig->isSetFlag( + self::XML_PATH_ACTIVE, + \Magento\Store\Model\ScopeInterface::SCOPE_STORE + ); + } +} diff --git a/Plugin/Model/SubscriberPlugin.php b/Plugin/Model/SubscriberPlugin.php new file mode 100644 index 0000000..ca5327f --- /dev/null +++ b/Plugin/Model/SubscriberPlugin.php @@ -0,0 +1,53 @@ +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(); + } + } +} \ No newline at end of file diff --git a/README.md b/README.md new file mode 100755 index 0000000..5db900c --- /dev/null +++ b/README.md @@ -0,0 +1,44 @@ +Magento Extension Provider + +## 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 support@magepal.com 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) diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..01b6d50 --- /dev/null +++ b/composer.json @@ -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": "support@magepal.com", + "issues": "https://github.com/magepal/magento2-google-tag-manager/issues/" + }, + "authors": [ + { + "name": "Renon Stewart", + "email": "renon@magepal.com", + "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\\": "" + } + } +} \ No newline at end of file diff --git a/etc/acl.xml b/etc/acl.xml new file mode 100644 index 0000000..4579eab --- /dev/null +++ b/etc/acl.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml new file mode 100644 index 0000000..5e60b81 --- /dev/null +++ b/etc/adminhtml/system.xml @@ -0,0 +1,46 @@ + + + + + + + +
+ + magepal + MagePal_NewsletterSignupEmail::magepal_newsletter_signup_email + + + 1 + + Copyright © 2018 www.magepal.com / support@magepal.com
+ Thanks for choosing MagePal Extensions. Trusted by 1000s of developers worldwide.

+
+ ]]> +
+ + + MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Module\Version + + + + MagePal\NewsletterSignupEmail\Block\Adminhtml\System\Config\Form\Composer\Version + +
+ + + + + Magento\Config\Model\Config\Source\Yesno + + +
+
+
diff --git a/etc/di.xml b/etc/di.xml new file mode 100644 index 0000000..4603624 --- /dev/null +++ b/etc/di.xml @@ -0,0 +1,15 @@ + + + + + + + + \ No newline at end of file diff --git a/etc/module.xml b/etc/module.xml new file mode 100644 index 0000000..4bd0329 --- /dev/null +++ b/etc/module.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/registration.php b/registration.php new file mode 100644 index 0000000..dee7615 --- /dev/null +++ b/registration.php @@ -0,0 +1,7 @@ +