SubscriberPlugin.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. namespace Dotdigitalgroup\Email\Plugin;
  3. /**
  4. * Newsletter disable susbcriber email depending on settings value.
  5. */
  6. class SubscriberPlugin
  7. {
  8. /**
  9. * @var \Magento\Framework\App\Config\ScopeConfigInterface
  10. */
  11. public $scopeConfig;
  12. /**
  13. * SubscriberPlugin constructor.
  14. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  15. */
  16. public function __construct(
  17. \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  18. ) {
  19. $this->scopeConfig = $scopeConfig;
  20. }
  21. /**
  22. * @param \Magento\Newsletter\Model\Subscriber $subscriber
  23. * @param callable $proceed
  24. *
  25. * @return mixed
  26. */
  27. public function aroundSendConfirmationSuccessEmail(
  28. \Magento\Newsletter\Model\Subscriber $subscriber,
  29. callable $proceed
  30. ) {
  31. $storeId = $subscriber->getStoreId();
  32. //scope config for sending newsletter is disabled
  33. if (! $this->scopeConfig->getValue(
  34. \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_DISABLE_NEWSLETTER_SUCCESS,
  35. 'store',
  36. $storeId
  37. )
  38. ) {
  39. return $proceed();
  40. }
  41. }
  42. }