Exemple #1
0
 /**
  * Load data for customer quote and merge with current quote
  *
  * @return $this
  */
 public function loadCustomerQuote()
 {
     if (!$this->_customerSession->getCustomerId()) {
         return $this;
     }
     $this->_eventManager->dispatch('load_customer_quote_before', array('checkout_session' => $this));
     $customerQuote = $this->_quoteFactory->create()->setStoreId($this->_storeManager->getStore()->getId())->loadByCustomer($this->_customerSession->getCustomerId());
     if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId()) {
         if ($this->getQuoteId()) {
             $customerQuote->merge($this->getQuote())->collectTotals()->save();
         }
         $this->setQuoteId($customerQuote->getId());
         if ($this->_quote) {
             $this->_quote->delete();
         }
         $this->_quote = $customerQuote;
     } else {
         $this->getQuote()->getBillingAddress();
         $this->getQuote()->getShippingAddress();
         $this->getQuote()->setCustomerData($this->_customerSession->getCustomerDataObject())->setTotalsCollectedFlag(false)->collectTotals()->save();
     }
     return $this;
 }