Skip to content

Commit 36fb3b7

Browse files
committed
Added suggested changes + fixed static tests + fixed functional tests + some cleanup.
1 parent 96b969d commit 36fb3b7

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

app/code/Magento/Checkout/Model/Session.php

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
namespace Magento\Checkout\Model;
77

88
use Magento\Customer\Api\Data\CustomerInterface;
9-
use Magento\Framework\Api\SearchCriteriaBuilder;
10-
use Magento\Framework\Api\SortOrderBuilder;
119
use Magento\Framework\App\ObjectManager;
12-
use Magento\Framework\Exception\InputException;
1310
use Magento\Framework\Exception\NoSuchEntityException;
1411
use Magento\Quote\Api\Data\CartInterface;
1512
use Magento\Quote\Model\Quote;
@@ -26,9 +23,6 @@
2623
*/
2724
class Session extends \Magento\Framework\Session\SessionManager
2825
{
29-
/**
30-
* Checkout state begin
31-
*/
3226
const CHECKOUT_STATE_BEGIN = 'begin';
3327

3428
/**
@@ -233,7 +227,7 @@ public function setLoadInactive($load = true)
233227
*
234228
* @return Quote
235229
* @throws \Magento\Framework\Exception\LocalizedException
236-
* @throws \Magento\Framework\Exception\NoSuchEntityException
230+
* @throws NoSuchEntityException
237231
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
238232
* @SuppressWarnings(PHPMD.NPathComplexity)
239233
*/
@@ -278,16 +272,16 @@ public function getQuote()
278272
*/
279273
$quote = $this->quoteRepository->get($this->getQuoteId());
280274
}
281-
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
275+
} catch (NoSuchEntityException $e) {
282276
$this->setQuoteId(null);
283277
}
284278
}
285279

286280
if (!$this->getQuoteId()) {
287281
if ($this->_customerSession->isLoggedIn() || $this->_customer) {
288282
$quoteByCustomer = $this->getQuoteByCustomer();
289-
if ($quoteByCustomer !== false) {
290-
$this->setQuoteId($quote->getId());
283+
if ($quoteByCustomer !== null) {
284+
$this->setQuoteId($quoteByCustomer->getId());
291285
$quote = $quoteByCustomer;
292286
}
293287
} else {
@@ -376,7 +370,7 @@ public function loadCustomerQuote()
376370

377371
try {
378372
$customerQuote = $this->quoteRepository->getForCustomer($this->_customerSession->getCustomerId());
379-
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
373+
} catch (NoSuchEntityException $e) {
380374
$customerQuote = $this->quoteFactory->create();
381375
}
382376
$customerQuote->setStoreId($this->_storeManager->getStore()->getId());
@@ -559,7 +553,7 @@ public function restoreQuote()
559553
$this->replaceQuote($quote)->unsLastRealOrderId();
560554
$this->_eventManager->dispatch('restore_quote', ['order' => $order, 'quote' => $quote]);
561555
return true;
562-
} catch (\Magento\Framework\Exception\NoSuchEntityException $e) {
556+
} catch (NoSuchEntityException $e) {
563557
$this->logger->critical($e);
564558
}
565559
}
@@ -591,9 +585,9 @@ protected function isQuoteMasked()
591585
}
592586

593587
/**
594-
* @return CartInterface|false
588+
* Returns quote for customer if there is any
595589
*/
596-
private function getQuoteByCustomer()
590+
private function getQuoteByCustomer(): ?CartInterface
597591
{
598592
$customerId = $this->_customer
599593
? $this->_customer->getId()
@@ -602,7 +596,7 @@ private function getQuoteByCustomer()
602596
try {
603597
$quote = $this->quoteRepository->getActiveForCustomer($customerId);
604598
} catch (NoSuchEntityException $e) {
605-
$quote = false;
599+
$quote = null;
606600
}
607601

608602
return $quote;

0 commit comments

Comments
 (0)