Пример #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', ['checkout_session' => $this]);
     try {
         $customerQuote = $this->quoteRepository->getForCustomer($this->_customerSession->getCustomerId());
     } catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
         $customerQuote = $this->quoteFactory->create();
     }
     $customerQuote->setStoreId($this->_storeManager->getStore()->getId());
     if ($customerQuote->getId() && $this->getQuoteId() != $customerQuote->getId()) {
         if ($this->getQuoteId()) {
             $this->quoteRepository->save($customerQuote->merge($this->getQuote())->collectTotals());
         }
         $this->setQuoteId($customerQuote->getId());
         if ($this->_quote) {
             $this->quoteRepository->delete($this->_quote);
         }
         $this->_quote = $customerQuote;
     } else {
         $this->getQuote()->getBillingAddress();
         $this->getQuote()->getShippingAddress();
         $this->getQuote()->setCustomer($this->_customerSession->getCustomerDataObject())->setTotalsCollectedFlag(false)->collectTotals();
         $this->quoteRepository->save($this->getQuote());
     }
     return $this;
 }
Пример #2
0
 public function testDelete()
 {
     $this->quoteMock->expects($this->once())->method('delete');
     $this->quoteMock->expects($this->exactly(1))->method('getId')->willReturn(1);
     $this->quoteMock->expects($this->exactly(1))->method('getCustomerId')->willReturn(2);
     $this->model->delete($this->quoteMock);
 }