/** * Get checkout quote instance by current session * * @return Quote */ public function getQuote() { $this->_eventManager->dispatch('custom_quote_process', array('checkout_session' => $this)); if ($this->_quote === null) { /** @var $quote Quote */ $quote = $this->_quoteFactory->create()->setStoreId($this->_storeManager->getStore()->getId()); if ($this->getQuoteId()) { if ($this->_loadInactive) { $quote->load($this->getQuoteId()); } else { $quote->loadActive($this->getQuoteId()); } if ($quote->getId()) { /** * If current currency code of quote is not equal current currency code of store, * need recalculate totals of quote. It is possible if customer use currency switcher or * store switcher. */ if ($quote->getQuoteCurrencyCode() != $this->_storeManager->getStore()->getCurrentCurrencyCode()) { $quote->setStore($this->_storeManager->getStore()); $quote->collectTotals()->save(); /* * We mast to create new quote object, because collectTotals() * can to create links with other objects. */ $quote = $this->_quoteFactory->create()->setStoreId($this->_storeManager->getStore()->getId()); $quote->load($this->getQuoteId()); } } else { $this->setQuoteId(null); } } if (!$this->getQuoteId()) { if ($this->_customerSession->isLoggedIn() || $this->_customer) { $customerId = $this->_customer ? $this->_customer->getId() : $this->_customerSession->getCustomerId(); $quote->loadByCustomer($customerId); $this->setQuoteId($quote->getId()); } else { $quote->setIsCheckoutCart(true); $this->_eventManager->dispatch('checkout_quote_init', array('quote' => $quote)); } } if ($this->getQuoteId()) { if ($this->_customer) { $quote->setCustomerData($this->_customer); } else { if ($this->_customerSession->isLoggedIn()) { $quote->setCustomerData($this->_customerSession->getCustomerDataObject()); } } } $quote->setStore($this->_storeManager->getStore()); $this->_quote = $quote; } if ($remoteAddr = $this->_remoteAddress->getRemoteAddress()) { $this->_quote->setRemoteIp($remoteAddr); $xForwardIp = $this->request->getServer('HTTP_X_FORWARDED_FOR'); $this->_quote->setXForwardedFor($xForwardIp); } return $this->_quote; }