Add.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\ProductAlert\Controller;
  7. use Magento\Framework\App\Action\Action;
  8. use Magento\Framework\App\Action\Context;
  9. use Magento\Customer\Model\Session as CustomerSession;
  10. use Magento\Framework\App\RequestInterface;
  11. abstract class Add extends Action
  12. {
  13. /**
  14. * @var \Magento\Customer\Model\Session
  15. */
  16. protected $customerSession;
  17. /**
  18. * @param \Magento\Framework\App\Action\Context $context
  19. * @param \Magento\Customer\Model\Session $customerSession
  20. */
  21. public function __construct(
  22. Context $context,
  23. CustomerSession $customerSession
  24. ) {
  25. $this->customerSession = $customerSession;
  26. parent::__construct($context);
  27. }
  28. /**
  29. * Check customer authentication for some actions
  30. *
  31. * @param \Magento\Framework\App\RequestInterface $request
  32. * @return \Magento\Framework\App\ResponseInterface
  33. */
  34. public function dispatch(RequestInterface $request)
  35. {
  36. if (!$this->customerSession->authenticate()) {
  37. $this->_actionFlag->set('', 'no-dispatch', true);
  38. if (!$this->customerSession->getBeforeUrl()) {
  39. $this->customerSession->setBeforeUrl($this->_redirect->getRefererUrl());
  40. }
  41. }
  42. return parent::dispatch($request);
  43. }
  44. }