Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Agreement.php
Go to the documentation of this file.
1 <?php
7 
9 
14 {
20  protected $_coreRegistry = null;
21 
26  public function __construct(
27  \Magento\Framework\App\Action\Context $context,
28  \Magento\Framework\Registry $coreRegistry
29  ) {
30  $this->_coreRegistry = $coreRegistry;
31  parent::__construct($context);
32  }
33 
41  {
42  if (!$request->isDispatched()) {
43  return parent::dispatch($request);
44  }
45  if (!$this->_getSession()->authenticate()) {
46  $this->_actionFlag->set('', 'no-dispatch', true);
47  }
48  return parent::dispatch($request);
49  }
50 
56  protected function _initAgreement()
57  {
58  $agreementId = $this->getRequest()->getParam('agreement');
59  if ($agreementId) {
61  $billingAgreement = $this->_objectManager->create(\Magento\Paypal\Model\Billing\Agreement::class)
62  ->load($agreementId);
63  $currentCustomerId = $this->_getSession()->getCustomerId();
64  $agreementCustomerId = $billingAgreement->getCustomerId();
65  if ($billingAgreement->getId() && $agreementCustomerId == $currentCustomerId) {
66  $this->_coreRegistry->register('current_billing_agreement', $billingAgreement);
67  return $billingAgreement;
68  }
69  }
70  $this->messageManager->addErrorMessage(
71  __('Please specify the correct billing agreement ID and try again.')
72  );
73  $this->_redirect('*/*/');
74  return false;
75  }
76 
82  protected function _getSession()
83  {
84  return $this->_objectManager->get(\Magento\Customer\Model\Session::class);
85  }
86 }
_redirect($path, $arguments=[])
Definition: Action.php:167
$billingAgreement
__()
Definition: __.php:13
dispatch(RequestInterface $request)
Definition: Agreement.php:40
__construct(\Magento\Framework\App\Action\Context $context, \Magento\Framework\Registry $coreRegistry)
Definition: Agreement.php:26