Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions
Checkout Class Reference
Inheritance diagram for Checkout:
Action RedirectLoginInterface Action AbstractAction ActionInterface Addresses AddressesPost BackToAddresses BackToBilling BackToShipping Billing CheckItems Index Login Overview OverviewPost Register RemoveItem Shipping ShippingPost

Public Member Functions

 __construct (\Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, CustomerRepositoryInterface $customerRepository, AccountManagementInterface $accountManagement)
 
 dispatch (RequestInterface $request)
 
 getCustomerBeforeAuthUrl ()
 
 getActionFlagList ()
 
 getLoginUrl ()
 
 getRedirectActionName ()
 
- Public Member Functions inherited from Action
 __construct (\Magento\Framework\App\Action\Context $context, \Magento\Customer\Model\Session $customerSession, CustomerRepositoryInterface $customerRepository, AccountManagementInterface $accountManagement)
 
- Public Member Functions inherited from Action
 __construct (Context $context)
 
 dispatch (RequestInterface $request)
 
 getActionFlag ()
 
- Public Member Functions inherited from AbstractAction
 __construct (Context $context)
 
 dispatch (RequestInterface $request)
 
 getRequest ()
 
 getResponse ()
 
- Public Member Functions inherited from ActionInterface
 execute ()
 

Protected Member Functions

 _getCheckout ()
 
 _getState ()
 
 _getHelper ()
 
 _getCheckoutSession ()
 
 _validateMinimumAmount ()
 
- Protected Member Functions inherited from Action
 _preDispatchValidateCustomer ($redirect=true, $addErrors=true)
 
- Protected Member Functions inherited from Action
 _forward ($action, $controller=null, $module=null, array $params=null)
 
 _redirect ($path, $arguments=[])
 

Additional Inherited Members

- Data Fields inherited from ActionInterface
const FLAG_NO_DISPATCH = 'no-dispatch'
 
const FLAG_NO_POST_DISPATCH = 'no-postDispatch'
 
const FLAG_NO_DISPATCH_BLOCK_EVENT = 'no-beforeGenerateLayoutBlocksDispatch'
 
const PARAM_NAME_BASE64_URL = 'r64'
 
const PARAM_NAME_URL_ENCODED = 'uenc'
 
- Protected Attributes inherited from Action
 $_customerSession
 
 $customerRepository
 
 $accountManagement
 
- Protected Attributes inherited from Action
 $_objectManager
 
 $_sessionNamespace
 
 $_eventManager
 
 $_actionFlag
 
 $_redirect
 
 $_view
 
 $_url
 
 $messageManager
 
- Protected Attributes inherited from AbstractAction
 $_request
 
 $_response
 
 $resultRedirectFactory
 
 $resultFactory
 

Detailed Description

Multishipping checkout controller @SuppressWarnings(PHPMD.NumberOfChildren) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 18 of file Checkout.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Action\Context  $context,
\Magento\Customer\Model\Session  $customerSession,
CustomerRepositoryInterface  $customerRepository,
AccountManagementInterface  $accountManagement 
)

Constructor

Parameters
\Magento\Framework\App\Action\Context$context
\Magento\Customer\Model\Session$customerSession
CustomerRepositoryInterface$customerRepository
AccountManagementInterface$accountManagement

Definition at line 29 of file Checkout.php.

34  {
35  parent::__construct(
36  $context,
37  $customerSession,
40  );
41  }

Member Function Documentation

◆ _getCheckout()

_getCheckout ( )
protected

Retrieve checkout model

Returns
\Magento\Multishipping\Model\Checkout\Type\Multishipping

Definition at line 48 of file Checkout.php.

49  {
50  return $this->_objectManager->get(\Magento\Multishipping\Model\Checkout\Type\Multishipping::class);
51  }

◆ _getCheckoutSession()

_getCheckoutSession ( )
protected

Retrieve checkout session

Returns
\Magento\Checkout\Model\Session

Definition at line 78 of file Checkout.php.

79  {
80  return $this->_objectManager->get(\Magento\Checkout\Model\Session::class);
81  }

◆ _getHelper()

_getHelper ( )
protected

Retrieve checkout url helper

Returns
\Magento\Multishipping\Helper\Url

Definition at line 68 of file Checkout.php.

69  {
70  return $this->_objectManager->get(\Magento\Multishipping\Helper\Url::class);
71  }

◆ _getState()

_getState ( )
protected

Retrieve checkout state model

Returns
\Magento\Multishipping\Model\Checkout\Type\Multishipping\State

Definition at line 58 of file Checkout.php.

59  {
60  return $this->_objectManager->get(\Magento\Multishipping\Model\Checkout\Type\Multishipping\State::class);
61  }

◆ _validateMinimumAmount()

_validateMinimumAmount ( )
protected

Validate minimum amount

Returns
bool

Definition at line 179 of file Checkout.php.

180  {
181  if (!$this->_getCheckout()->validateMinimumAmount()) {
182  $error = $this->_getCheckout()->getMinimumAmountError();
183  $this->messageManager->addError($error);
184  $this->_forward('backToAddresses');
185  return false;
186  }
187  return true;
188  }
_forward($action, $controller=null, $module=null, array $params=null)
Definition: Action.php:137

◆ dispatch()

dispatch ( RequestInterface  $request)

Dispatch request

Parameters
RequestInterface$request
Returns
\Magento\Framework\App\ResponseInterface
Exceptions

Catch index action call to set some flags before checkout/type_multishipping model initialization

Definition at line 92 of file Checkout.php.

93  {
94  $this->_request = $request;
95  if ($this->_actionFlag->get('', 'redirectLogin')) {
96  return parent::dispatch($request);
97  }
98 
99  $action = $request->getActionName();
100 
101  $checkoutSessionQuote = $this->_getCheckoutSession()->getQuote();
105  if ($action == 'index') {
106  $checkoutSessionQuote->setIsMultiShipping(true);
107  $this->_getCheckoutSession()->setCheckoutState(\Magento\Checkout\Model\Session::CHECKOUT_STATE_BEGIN);
108  } elseif (!$checkoutSessionQuote->getIsMultiShipping() && !in_array(
109  $action,
110  ['login', 'register', 'success']
111  )
112  ) {
113  $this->_redirect('*/*/index');
114  $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
115  return parent::dispatch($request);
116  }
117 
118  if (!in_array($action, ['login', 'register'])) {
119  $customerSession = $this->_objectManager->get(\Magento\Customer\Model\Session::class);
120  if (!$customerSession->authenticate($this->_getHelper()->getMSLoginUrl())) {
121  $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
122  }
123 
124  if (!$this->_objectManager->get(
125  \Magento\Multishipping\Helper\Data::class
126  )->isMultishippingCheckoutAvailable()) {
127  $error = $this->_getCheckout()->getMinimumAmountError();
128  $this->messageManager->addError($error);
129  $this->getResponse()->setRedirect($this->_getHelper()->getCartUrl());
130  $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
131  return parent::dispatch($request);
132  }
133  }
134 
136  if ($result instanceof \Magento\Framework\Controller\ResultInterface) {
137  return $result;
138  }
139 
140  if (!$result) {
141  return $this->getResponse();
142  }
143 
144  if ($this->_getCheckoutSession()->getCartWasUpdated(true)
145  &&
146  !in_array($action, ['index', 'login', 'register', 'addresses', 'success'])
147  ) {
148  $this->getResponse()->setRedirect($this->_getHelper()->getCartUrl());
149  $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
150  return parent::dispatch($request);
151  }
152 
153  if ($action == 'success' && $this->_getCheckout()->getCheckoutSession()->getDisplaySuccess(true)) {
154  return parent::dispatch($request);
155  }
156 
157  try {
158  $checkout = $this->_getCheckout();
159  } catch (StateException $e) {
160  $this->getResponse()->setRedirect($this->_getHelper()->getMSNewShippingUrl());
161  $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
162  return parent::dispatch($request);
163  }
164 
165  $quote = $checkout->getQuote();
166  if (!$quote->hasItems() || $quote->getHasError() || $quote->isVirtual()) {
167  $this->getResponse()->setRedirect($this->_getHelper()->getCartUrl());
168  $this->_actionFlag->set('', self::FLAG_NO_DISPATCH, true);
169  }
170 
171  return parent::dispatch($request);
172  }
_redirect($path, $arguments=[])
Definition: Action.php:167
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$quote
_preDispatchValidateCustomer($redirect=true, $addErrors=true)
Definition: Action.php:60

◆ getActionFlagList()

getActionFlagList ( )

Returns a list of action flags [flag_key] => boolean

Returns
array

Implements RedirectLoginInterface.

Definition at line 207 of file Checkout.php.

208  {
209  return ['redirectLogin' => true];
210  }

◆ getCustomerBeforeAuthUrl()

getCustomerBeforeAuthUrl ( )

Returns before_auth_url redirect parameter for customer session

Returns
string

Implements RedirectLoginInterface.

Definition at line 195 of file Checkout.php.

196  {
197  return $this->_objectManager->create(
198  \Magento\Framework\UrlInterface::class
199  )->getUrl('*/*', ['_secure' => true]);
200  }

◆ getLoginUrl()

getLoginUrl ( )

Returns login url parameter for redirect

Returns
string

Implements RedirectLoginInterface.

Definition at line 217 of file Checkout.php.

218  {
219  return $this->_getHelper()->getMSLoginUrl();
220  }

◆ getRedirectActionName()

getRedirectActionName ( )

Returns action name which requires redirect

Returns
string

Implements RedirectLoginInterface.

Definition at line 227 of file Checkout.php.

228  {
229  return 'index';
230  }

The documentation for this class was generated from the following file: