|
6 | 6 | namespace Magento\Checkout\Model;
|
7 | 7 |
|
8 | 8 | use Magento\Customer\Api\Data\CustomerInterface;
|
| 9 | +use Magento\Framework\Api\SearchCriteriaBuilder; |
| 10 | +use Magento\Framework\Api\SortOrderBuilder; |
9 | 11 | use Magento\Framework\App\ObjectManager;
|
| 12 | +use Magento\Framework\Exception\InputException; |
| 13 | +use Magento\Framework\Exception\NoSuchEntityException; |
| 14 | +use Magento\Quote\Api\Data\CartInterface; |
10 | 15 | use Magento\Quote\Model\Quote;
|
11 | 16 | use Magento\Quote\Model\QuoteIdMaskFactory;
|
12 | 17 | use Psr\Log\LoggerInterface;
|
@@ -280,13 +285,10 @@ public function getQuote()
|
280 | 285 |
|
281 | 286 | if (!$this->getQuoteId()) {
|
282 | 287 | if ($this->_customerSession->isLoggedIn() || $this->_customer) {
|
283 |
| - $customerId = $this->_customer |
284 |
| - ? $this->_customer->getId() |
285 |
| - : $this->_customerSession->getCustomerId(); |
286 |
| - |
287 |
| - $quote = $this->quoteRepository->getForCustomer($customerId); |
288 |
| - if ($quote->getIsActive()) { |
| 288 | + $quoteByCustomer = $this->getQuoteByCustomer(); |
| 289 | + if ($quoteByCustomer !== false) { |
289 | 290 | $this->setQuoteId($quote->getId());
|
| 291 | + $quote = $quoteByCustomer; |
290 | 292 | }
|
291 | 293 | } else {
|
292 | 294 | $quote->setIsCheckoutCart(true);
|
@@ -587,4 +589,22 @@ protected function isQuoteMasked()
|
587 | 589 | {
|
588 | 590 | return $this->isQuoteMasked;
|
589 | 591 | }
|
| 592 | + |
| 593 | + /** |
| 594 | + * @return CartInterface|false |
| 595 | + */ |
| 596 | + private function getQuoteByCustomer() |
| 597 | + { |
| 598 | + $customerId = $this->_customer |
| 599 | + ? $this->_customer->getId() |
| 600 | + : $this->_customerSession->getCustomerId(); |
| 601 | + |
| 602 | + try { |
| 603 | + $quote = $this->quoteRepository->getActiveForCustomer($customerId); |
| 604 | + } catch (NoSuchEntityException $e) { |
| 605 | + $quote = false; |
| 606 | + } |
| 607 | + |
| 608 | + return $quote; |
| 609 | + } |
590 | 610 | }
|
0 commit comments