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

Public Member Functions

 __construct (\Magento\Persistent\Helper\Session $persistentSession, \Magento\Persistent\Helper\Data $persistentData, \Magento\Checkout\Model\Session $checkoutSession, \Magento\Customer\Model\Session $customerSession, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository)
 
 execute (\Magento\Framework\Event\Observer $observer)
 
- Public Member Functions inherited from ObserverInterface
 execute (Observer $observer)
 

Protected Attributes

 $customerRepository
 
 $_customerSession
 
 $_checkoutSession
 
 $_persistentSession = null
 
 $_persistentData = null
 

Detailed Description

Class EmulateQuote

Definition at line 14 of file EmulateQuoteObserver.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Persistent\Helper\Session  $persistentSession,
\Magento\Persistent\Helper\Data  $persistentData,
\Magento\Checkout\Model\Session  $checkoutSession,
\Magento\Customer\Model\Session  $customerSession,
\Magento\Customer\Api\CustomerRepositoryInterface  $customerRepository 
)
Parameters
\Magento\Persistent\Helper\Session$persistentSession
\Magento\Persistent\Helper\Data$persistentData
\Magento\Checkout\Model\Session$checkoutSession
\Magento\Customer\Model\Session$customerSession
\Magento\Customer\Api\CustomerRepositoryInterface$customerRepository

Definition at line 58 of file EmulateQuoteObserver.php.

64  {
65  $this->_persistentSession = $persistentSession;
66  $this->_persistentData = $persistentData;
67  $this->_checkoutSession = $checkoutSession;
68  $this->_customerSession = $customerSession;
69  $this->customerRepository = $customerRepository;
70  }
$persistentSession
Definition: persistent.php:11

Member Function Documentation

◆ execute()

execute ( \Magento\Framework\Event\Observer  $observer)

Emulate quote by persistent data

Parameters
\Magento\Framework\Event\Observer$observer
Returns
void

Definition at line 78 of file EmulateQuoteObserver.php.

79  {
80  $stopActions = ['persistent_index_saveMethod', 'customer_account_createpost'];
81 
82  if (!$this->_persistentData->canProcess($observer)
83  || !$this->_persistentSession->isPersistent()
84  || $this->_customerSession->isLoggedIn()
85  ) {
86  return;
87  }
88 
89  $actionName = $observer->getEvent()->getRequest()->getFullActionName();
90 
91  if (in_array($actionName, $stopActions)) {
92  return;
93  }
94 
95  if ($this->_persistentData->isShoppingCartPersist()) {
96  $this->_checkoutSession->setCustomerData(
97  $this->customerRepository->getById($this->_persistentSession->getSession()->getCustomerId())
98  );
99  if (!$this->_checkoutSession->hasQuote()) {
100  $this->_checkoutSession->getQuote();
101  }
102  }
103  }

Field Documentation

◆ $_checkoutSession

$_checkoutSession
protected

Definition at line 35 of file EmulateQuoteObserver.php.

◆ $_customerSession

$_customerSession
protected

Definition at line 28 of file EmulateQuoteObserver.php.

◆ $_persistentData

$_persistentData = null
protected

Definition at line 49 of file EmulateQuoteObserver.php.

◆ $_persistentSession

$_persistentSession = null
protected

Definition at line 42 of file EmulateQuoteObserver.php.

◆ $customerRepository

$customerRepository
protected

Definition at line 21 of file EmulateQuoteObserver.php.


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