10 use Magento\Quote\Model\QuoteIdMaskFactory;
133 \
Magento\Sales\Model\OrderFactory $orderFactory,
136 \
Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress,
143 $this->_orderFactory = $orderFactory;
144 $this->_customerSession = $customerSession;
146 $this->_remoteAddress = $remoteAddress;
147 $this->_eventManager = $eventManager;
186 return isset($this->_quote);
198 $this->_loadInactive = $load;
209 public function getQuote()
211 $this->_eventManager->dispatch(
'custom_quote_process', [
'checkout_session' => $this]);
213 if ($this->_quote ===
null) {
214 $quote = $this->quoteFactory->create();
217 if ($this->_loadInactive) {
228 if (
$quote->getQuoteCurrencyCode() != $this->_storeManager->getStore()->getCurrentCurrencyCode()) {
229 $quote->setStore($this->_storeManager->getStore());
230 $this->quoteRepository->save(
$quote->collectTotals());
237 }
catch (\
Magento\Framework\Exception\NoSuchEntityException $e) {
245 ? $this->_customer->getId()
246 : $this->_customerSession->getCustomerId();
250 }
catch (\
Magento\Framework\Exception\NoSuchEntityException $e) {
253 $quote->setIsCheckoutCart(
true);
254 $this->_eventManager->dispatch(
'checkout_quote_init', [
'quote' =>
$quote]);
258 if ($this->_customer) {
259 $quote->setCustomer($this->_customer);
260 }
elseif ($this->_customerSession->isLoggedIn()) {
261 $quote->setCustomer($this->customerRepository->getById($this->_customerSession->getCustomerId()));
264 $quote->setStore($this->_storeManager->getStore());
278 $remoteAddress = $this->_remoteAddress->getRemoteAddress();
279 if ($remoteAddress) {
280 $this->_quote->setRemoteIp($remoteAddress);
281 $xForwardIp = $this->request->getServer(
'HTTP_X_FORWARDED_FOR');
282 $this->_quote->setXForwardedFor($xForwardIp);
294 return 'quote_id_' . $this->_storeManager->getStore()->getWebsiteId();
323 if (!$this->_customerSession->getCustomerId()) {
327 $this->_eventManager->dispatch(
'load_customer_quote_before', [
'checkout_session' => $this]);
330 $customerQuote = $this->quoteRepository->getForCustomer($this->_customerSession->getCustomerId());
332 $customerQuote = $this->quoteFactory->create();
334 $customerQuote->setStoreId($this->_storeManager->getStore()->getId());
336 if ($customerQuote->getId() && $this->
getQuoteId() != $customerQuote->getId()) {
338 $this->quoteRepository->save(
339 $customerQuote->merge($this->getQuote())->collectTotals()
346 $this->quoteRepository->delete($this->_quote);
348 $this->_quote = $customerQuote;
350 $this->getQuote()->getBillingAddress();
351 $this->getQuote()->getShippingAddress();
352 $this->getQuote()->setCustomer($this->_customerSession->getCustomerDataObject())
353 ->setTotalsCollectedFlag(
false)
355 $this->quoteRepository->save($this->getQuote());
368 $steps = $this->getSteps();
370 if (is_array(
$data)) {
371 $steps[$step] =
$data;
374 if (!isset($steps[$step])) {
377 if (is_string(
$data)) {
381 $this->setSteps($steps);
393 $steps = $this->getSteps();
394 if ($step ===
null) {
397 if (!isset($steps[$step])) {
400 if (
$data ===
null) {
401 return $steps[$step];
403 if (!is_string(
$data) || !isset($steps[$step][
$data])) {
406 return $steps[$step][
$data];
417 $this->_eventManager->dispatch(
'checkout_quote_destroy', [
'quote' => $this->getQuote()]);
418 $this->_quote =
null;
420 $this->setLastSuccessQuoteId(
null);
431 parent::clearStorage();
432 $this->_quote =
null;
443 $this->setRedirectUrl(
null)->setLastOrderId(
null)->setLastRealOrderId(
null)->setAdditionalMessages(
null);
452 $this->setCheckoutState(self::CHECKOUT_STATE_BEGIN);
474 $orderId = $this->getLastRealOrderId();
475 if ($this->_order !==
null && $orderId == $this->_order->getIncrementId()) {
478 $this->_order = $this->_orderFactory->create();
480 $this->_order->loadByIncrementId($orderId);
490 public function restoreQuote()
496 $quote = $this->quoteRepository->get(
$order->getQuoteId());
497 $quote->setIsActive(1)->setReservedOrderId(
null);
498 $this->quoteRepository->save(
$quote);
500 $this->_eventManager->dispatch(
'restore_quote', [
'order' =>
$order,
'quote' =>
$quote]);
const CHECKOUT_STATE_BEGIN
getStepData($step=null, $data=null)
elseif(isset( $params[ 'redirect_parent']))
setIsQuoteMasked($isQuoteMasked)
setLoadInactive($load=true)
setStepData($step, $data, $value=null)
getData($key='', $clear=false)
setCustomerData($customer)
__construct(\Magento\Framework\App\Request\Http $request, \Magento\Framework\Session\SidResolverInterface $sidResolver, \Magento\Framework\Session\Config\ConfigInterface $sessionConfig, \Magento\Framework\Session\SaveHandlerInterface $saveHandler, \Magento\Framework\Session\ValidatorInterface $validator, \Magento\Framework\Session\StorageInterface $storage, \Magento\Framework\Stdlib\CookieManagerInterface $cookieManager, \Magento\Framework\Stdlib\Cookie\CookieMetadataFactory $cookieMetadataFactory, \Magento\Framework\App\State $appState, \Magento\Sales\Model\OrderFactory $orderFactory, \Magento\Customer\Model\Session $customerSession, \Magento\Quote\Api\CartRepositoryInterface $quoteRepository, \Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository, QuoteIdMaskFactory $quoteIdMaskFactory, \Magento\Quote\Model\QuoteFactory $quoteFactory)