Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Protected Member Functions | Protected Attributes
Cart Class Reference
Inheritance diagram for Cart:
Action ViewInterface AbstractAction ActionInterface Add Addgroup Configure CouponPost Delete EstimatePost EstimateUpdatePost Index UpdateItemOptions UpdatePost

Public Member Functions

 __construct (\Magento\Framework\App\Action\Context $context, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Checkout\Model\Session $checkoutSession, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Data\Form\FormKey\Validator $formKeyValidator, CustomerCart $cart)
 
- 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

 _goBack ($backUrl=null)
 
 getBackUrl ($defaultUrl=null)
 
- Protected Member Functions inherited from Action
 _forward ($action, $controller=null, $module=null, array $params=null)
 
 _redirect ($path, $arguments=[])
 

Protected Attributes

 $_scopeConfig
 
 $_checkoutSession
 
 $_storeManager
 
 $_formKeyValidator
 
 $cart
 
- Protected Attributes inherited from Action
 $_objectManager
 
 $_sessionNamespace
 
 $_eventManager
 
 $_actionFlag
 
 $_redirect
 
 $_view
 
 $_url
 
 $messageManager
 
- Protected Attributes inherited from AbstractAction
 $_request
 
 $_response
 
 $resultRedirectFactory
 
 $resultFactory
 

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'
 

Detailed Description

Shopping cart controller

Definition at line 14 of file Cart.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\App\Action\Context  $context,
\Magento\Framework\App\Config\ScopeConfigInterface  $scopeConfig,
\Magento\Checkout\Model\Session  $checkoutSession,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Framework\Data\Form\FormKey\Validator  $formKeyValidator,
CustomerCart  $cart 
)
Parameters
\Magento\Framework\App\Action\Context$context
\Magento\Framework\App\Config\ScopeConfigInterface$scopeConfig
\Magento\Checkout\Model\Session$checkoutSession
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\Data\Form\FormKey\Validator$formKeyValidator
CustomerCart$cart@codeCoverageIgnore

Definition at line 50 of file Cart.php.

57  {
58  $this->_formKeyValidator = $formKeyValidator;
59  $this->_scopeConfig = $scopeConfig;
60  $this->_checkoutSession = $checkoutSession;
61  $this->_storeManager = $storeManager;
62  $this->cart = $cart;
63  parent::__construct($context);
64  }
$storeManager

Member Function Documentation

◆ _goBack()

_goBack (   $backUrl = null)
protected

Set back redirect url to response

Parameters
null | string$backUrl
Returns
\Magento\Framework\Controller\Result\Redirect

Definition at line 73 of file Cart.php.

74  {
75  $resultRedirect = $this->resultRedirectFactory->create();
76 
77  if ($backUrl || $backUrl = $this->getBackUrl($this->_redirect->getRefererUrl())) {
78  $resultRedirect->setUrl($backUrl);
79  }
80 
81  return $resultRedirect;
82  }
getBackUrl($defaultUrl=null)
Definition: Cart.php:112
_redirect($path, $arguments=[])
Definition: Action.php:167

◆ getBackUrl()

getBackUrl (   $defaultUrl = null)
protected

Get resolved back url

Parameters
string | null$defaultUrl
Returns
mixed|null|string

Definition at line 112 of file Cart.php.

113  {
114  $returnUrl = $this->getRequest()->getParam('return_url');
115  if ($returnUrl && $this->_isInternalUrl($returnUrl)) {
116  $this->messageManager->getMessages()->clear();
117  return $returnUrl;
118  }
119 
120  if ($this->shouldRedirectToCart() || $this->getRequest()->getParam('in_cart')) {
121  if ($this->getRequest()->getActionName() == 'add' && !$this->getRequest()->getParam('in_cart')) {
122  $this->_checkoutSession->setContinueShoppingUrl($this->_redirect->getRefererUrl());
123  }
124  return $this->_url->getUrl('checkout/cart');
125  }
126 
127  return $defaultUrl;
128  }
_redirect($path, $arguments=[])
Definition: Action.php:167

Field Documentation

◆ $_checkoutSession

$_checkoutSession
protected

Definition at line 24 of file Cart.php.

◆ $_formKeyValidator

$_formKeyValidator
protected

Definition at line 34 of file Cart.php.

◆ $_scopeConfig

$_scopeConfig
protected

Definition at line 19 of file Cart.php.

◆ $_storeManager

$_storeManager
protected

Definition at line 29 of file Cart.php.

◆ $cart

$cart
protected

Definition at line 39 of file Cart.php.


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