Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Attributes
Guest Class Reference
Inheritance diagram for Guest:
AbstractHelper

Public Member Functions

 __construct (App\Helper\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\Registry $coreRegistry, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory, \Magento\Framework\Message\ManagerInterface $messageManager, \Magento\Sales\Model\OrderFactory $orderFactory, \Magento\Framework\Controller\Result\RedirectFactory $resultRedirectFactory, \Magento\Sales\Api\OrderRepositoryInterface $orderRepository=null, \Magento\Framework\Api\SearchCriteriaBuilder $searchCriteria=null)
 
 loadValidOrder (App\RequestInterface $request)
 
 getBreadcrumbs (\Magento\Framework\View\Result\Page $resultPage)
 
- Public Member Functions inherited from AbstractHelper
 __construct (Context $context)
 
 isModuleOutputEnabled ($moduleName=null)
 

Data Fields

const COOKIE_NAME = 'guest-view'
 
const COOKIE_PATH = '/'
 
const COOKIE_LIFETIME = 600
 

Protected Attributes

 $coreRegistry
 
 $customerSession
 
 $cookieManager
 
 $cookieMetadataFactory
 
 $messageManager
 
 $orderFactory
 
 $resultRedirectFactory
 
- Protected Attributes inherited from AbstractHelper
 $_moduleName
 
 $_request
 
 $_moduleManager
 
 $_logger
 
 $_urlBuilder
 
 $_httpHeader
 
 $_eventManager
 
 $_remoteAddress
 
 $urlEncoder
 
 $urlDecoder
 
 $scopeConfig
 
 $_cacheConfig
 

Additional Inherited Members

- Protected Member Functions inherited from AbstractHelper
 _getRequest ()
 
 _getModuleName ()
 
 _getUrl ($route, $params=[])
 

Detailed Description

Sales module base helper @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Definition at line 19 of file Guest.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( App\Helper\Context  $context,
\Magento\Store\Model\StoreManagerInterface  $storeManager,
\Magento\Framework\Registry  $coreRegistry,
\Magento\Customer\Model\Session  $customerSession,
\Magento\Framework\Stdlib\CookieManagerInterface  $cookieManager,
\Magento\Framework\Stdlib\Cookie\CookieMetadataFactory  $cookieMetadataFactory,
\Magento\Framework\Message\ManagerInterface  $messageManager,
\Magento\Sales\Model\OrderFactory  $orderFactory,
\Magento\Framework\Controller\Result\RedirectFactory  $resultRedirectFactory,
\Magento\Sales\Api\OrderRepositoryInterface  $orderRepository = null,
\Magento\Framework\Api\SearchCriteriaBuilder  $searchCriteria = null 
)
Parameters
App\Helper\Context$context
\Magento\Store\Model\StoreManagerInterface$storeManager
\Magento\Framework\Registry$coreRegistry
\Magento\Customer\Model\Session$customerSession
\Magento\Framework\Stdlib\CookieManagerInterface$cookieManager
\Magento\Framework\Stdlib\Cookie\CookieMetadataFactory$cookieMetadataFactory
\Magento\Framework\Message\ManagerInterface$messageManager
\Magento\Sales\Model\OrderFactory$orderFactory
\Magento\Framework\Controller\Result\RedirectFactory$resultRedirectFactory
\Magento\Sales\Api\OrderRepositoryInterface$orderRepository
\Magento\Framework\Api\SearchCriteriaBuilder$searchCriteria@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 108 of file Guest.php.

120  {
121  $this->coreRegistry = $coreRegistry;
122  $this->storeManager = $storeManager;
123  $this->customerSession = $customerSession;
124  $this->cookieManager = $cookieManager;
125  $this->cookieMetadataFactory = $cookieMetadataFactory;
126  $this->messageManager = $messageManager;
127  $this->orderFactory = $orderFactory;
128  $this->resultRedirectFactory = $resultRedirectFactory;
130  ->get(\Magento\Sales\Api\OrderRepositoryInterface::class);
131  $this->searchCriteriaBuilder = $searchCriteria?: \Magento\Framework\App\ObjectManager::getInstance()
132  ->get(\Magento\Framework\Api\SearchCriteriaBuilder::class);
133  parent::__construct(
134  $context
135  );
136  }
$orderRepository
Definition: order.php:69
$storeManager
$searchCriteria

Member Function Documentation

◆ getBreadcrumbs()

getBreadcrumbs ( \Magento\Framework\View\Result\Page  $resultPage)

Get Breadcrumbs for current controller action

Parameters
\Magento\Framework\View\Result\Page$resultPage
Returns
void

Definition at line 179 of file Guest.php.

180  {
181  $breadcrumbs = $resultPage->getLayout()->getBlock('breadcrumbs');
182  if (!$breadcrumbs) {
183  return;
184  }
185  $breadcrumbs->addCrumb(
186  'home',
187  [
188  'label' => __('Home'),
189  'title' => __('Go to Home Page'),
190  'link' => $this->storeManager->getStore()->getBaseUrl()
191  ]
192  );
193  $breadcrumbs->addCrumb(
194  'cms_page',
195  ['label' => __('Order Information'), 'title' => __('Order Information')]
196  );
197  }
__()
Definition: __.php:13

◆ loadValidOrder()

loadValidOrder ( App\RequestInterface  $request)

Try to load valid order by $_POST or $_COOKIE

Parameters
App\RequestInterface$request
Returns
\Magento\Framework\Controller\Result\Redirect|bool
Exceptions

Definition at line 148 of file Guest.php.

149  {
150  if ($this->customerSession->isLoggedIn()) {
151  return $this->resultRedirectFactory->create()->setPath('sales/order/history');
152  }
153  $post = $request->getPostValue();
154  $fromCookie = $this->cookieManager->getCookie(self::COOKIE_NAME);
155  if (empty($post) && !$fromCookie) {
156  return $this->resultRedirectFactory->create()->setPath('sales/guest/form');
157  }
158  // It is unique place in the class that process exception and only InputException. It is need because by
159  // input data we found order and one more InputException could be throws deeper in stack trace
160  try {
161  $order = (!empty($post)
162  && isset($post['oar_order_id'], $post['oar_type'])
163  && !$this->hasPostDataEmptyFields($post))
164  ? $this->loadFromPost($post) : $this->loadFromCookie($fromCookie);
165  $this->coreRegistry->register('current_order', $order);
166  return true;
167  } catch (InputException $e) {
168  $this->messageManager->addErrorMessage($e->getMessage());
169  return $this->resultRedirectFactory->create()->setPath('sales/guest/form');
170  }
171  }
$order
Definition: order.php:55

Field Documentation

◆ $cookieManager

$cookieManager
protected

Definition at line 36 of file Guest.php.

◆ $cookieMetadataFactory

$cookieMetadataFactory
protected

Definition at line 41 of file Guest.php.

◆ $coreRegistry

$coreRegistry
protected

Definition at line 26 of file Guest.php.

◆ $customerSession

$customerSession
protected

Definition at line 31 of file Guest.php.

◆ $messageManager

$messageManager
protected

Definition at line 46 of file Guest.php.

◆ $orderFactory

$orderFactory
protected

Definition at line 51 of file Guest.php.

◆ $resultRedirectFactory

$resultRedirectFactory
protected

Definition at line 56 of file Guest.php.

◆ COOKIE_LIFETIME

const COOKIE_LIFETIME = 600

Cookie lifetime value

Definition at line 81 of file Guest.php.

◆ COOKIE_NAME

const COOKIE_NAME = 'guest-view'

Cookie key for guest view

Definition at line 71 of file Guest.php.

◆ COOKIE_PATH

const COOKIE_PATH = '/'

Cookie path

Definition at line 76 of file Guest.php.


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