没有customerId为1的此类实体



我有一个图2.3.2,并尝试执行订单。完成订单后,成功页面不会重定向。但秩序已经形成。有人能说出问题出在哪里吗。下面是错误日志

main.CRITICAL: No such entity with customerId = 1 {"exception":"[object] 
(Magento\Framework\Exception\NoSuchEntityException(code: 0): No such entity 
with customerId = 1 at /opt/magento/public_html/vendor/magento/framework/Exception/NoSuchEntityException.php:50)"} []main.CRITICAL: No such entity with customerId = 1 {"exception":"[object] (Magento\Framework\Exception\NoSuchEntityException(code: 0): No such entity with customerId = 1 at /opt/magento/public_html/vendor/magento/framework/Exception/NoSuchEntityException.php:50)"} []main.CRITICAL: No such entity with customerId = 1 {"exception":"[object] (Magento\Framework\Exception\NoSuchEntityException(code: 0): No such entity with customerId = 1 at /opt/magento/public_html/vendor/magento/framework/Exception/NoSuchEntityException.php:50)"} [](END)

请在2.3.2中应用此补丁https://patch-diff.githubusercontent.com/raw/magento/magento2/pull/25307.diff

或者升级到2.3.4

来源:https://github.com/magento/magento2/pull/25307

应用此补丁:

diff --git a/app/code/Magento/Checkout/Model/Session.php b/app/code/Magento/Checkout/Model/Session.php
index a654c78853d7..4a4861fa9ccd 100644
--- a/app/code/Magento/Checkout/Model/Session.php
+++ b/app/code/Magento/Checkout/Model/Session.php
@@ -7,6 +7,8 @@

use MagentoCustomerApiDataCustomerInterface;
use MagentoFrameworkAppObjectManager;
+use MagentoFrameworkExceptionNoSuchEntityException;
+use MagentoQuoteApiDataCartInterface;
use MagentoQuoteModelQuote;
use MagentoQuoteModelQuoteIdMaskFactory;
use PsrLogLoggerInterface;
@@ -21,9 +23,6 @@
*/
class Session extends MagentoFrameworkSessionSessionManager
{
-    /**
-     * Checkout state begin
-     */
const CHECKOUT_STATE_BEGIN = 'begin';

/**
@@ -228,7 +227,7 @@ public function setLoadInactive($load = true)
*
* @return Quote
* @throws MagentoFrameworkExceptionLocalizedException
-     * @throws MagentoFrameworkExceptionNoSuchEntityException
+     * @throws NoSuchEntityException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
@@ -273,21 +272,17 @@ public function getQuote()
*/
$quote = $this->quoteRepository->get($this->getQuoteId());
}
-                } catch (MagentoFrameworkExceptionNoSuchEntityException $e) {
+                } catch (NoSuchEntityException $e) {
$this->setQuoteId(null);
}
}

if (!$this->getQuoteId()) {
if ($this->_customerSession->isLoggedIn() || $this->_customer) {
-                    $customerId = $this->_customer
-                        ? $this->_customer->getId()
-                        : $this->_customerSession->getCustomerId();
-                    try {
-                        $quote = $this->quoteRepository->getActiveForCustomer($customerId);
-                        $this->setQuoteId($quote->getId());
-                    } catch (MagentoFrameworkExceptionNoSuchEntityException $e) {
-                        $this->logger->critical($e);
+                    $quoteByCustomer = $this->getQuoteByCustomer();
+                    if ($quoteByCustomer !== null) {
+                        $this->setQuoteId($quoteByCustomer->getId());
+                        $quote = $quoteByCustomer;
}
} else {
$quote->setIsCheckoutCart(true);
@@ -375,7 +370,7 @@ public function loadCustomerQuote()

try {
$customerQuote = $this->quoteRepository->getForCustomer($this->_customerSession->getCustomerId());
-        } catch (MagentoFrameworkExceptionNoSuchEntityException $e) {
+        } catch (NoSuchEntityException $e) {
$customerQuote = $this->quoteFactory->create();
}
$customerQuote->setStoreId($this->_storeManager->getStore()->getId());
@@ -558,7 +553,7 @@ public function restoreQuote()
$this->replaceQuote($quote)->unsLastRealOrderId();
$this->_eventManager->dispatch('restore_quote', ['order' => $order, 'quote' => $quote]);
return true;
-            } catch (MagentoFrameworkExceptionNoSuchEntityException $e) {
+            } catch (NoSuchEntityException $e) {
$this->logger->critical($e);
}
}
@@ -588,4 +583,22 @@ protected function isQuoteMasked()
{
return $this->isQuoteMasked;
}
+
+    /**
+     * Returns quote for customer if there is any
+     */
+    private function getQuoteByCustomer(): ?CartInterface
+    {
+        $customerId = $this->_customer
+            ? $this->_customer->getId()
+            : $this->_customerSession->getCustomerId();
+
+        try {
+            $quote = $this->quoteRepository->getActiveForCustomer($customerId);
+        } catch (NoSuchEntityException $e) {
+            $quote = null;
+        }
+
+        return $quote;
+    }
}
diff --git a/app/code/Magento/Checkout/Test/Unit/Model/SessionTest.php b/app/code/Magento/Checkout/Test/Unit/Model/SessionTest.php
index 26234992e613..969631901adf 100644
--- a/app/code/Magento/Checkout/Test/Unit/Model/SessionTest.php
+++ b/app/code/Magento/Checkout/Test/Unit/Model/SessionTest.php
@@ -9,7 +9,8 @@
*/
namespace MagentoCheckoutTestUnitModel;

-use MagentoCheckoutModelSession;
+use MagentoCheckoutModelSession;
+use MagentoFrameworkExceptionNoSuchEntityException;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -374,6 +375,68 @@ public function testGetStepData()
$this->assertEquals($stepData['complex']['key'], $session->getStepData('complex', 'key'));
}

+    /**
+     * Ensure that if quote not exist for customer quote will be null
+     *
+     * @return void
+     */
+    public function testGetQuote(): void
+    {
+        $storeManager = $this->getMockForAbstractClass(MagentoStoreModelStoreManagerInterface::class);
+        $customerSession = $this->createMock(MagentoCustomerModelSession::class);
+        $quoteRepository = $this->createMock(MagentoQuoteApiCartRepositoryInterface::class);
+        $quoteFactory = $this->createMock(MagentoQuoteModelQuoteFactory::class);
+        $quote = $this->createMock(MagentoQuoteModelQuote::class);
+        $logger = $this->createMock(PsrLogLoggerInterface::class);
+        $loggerMethods = get_class_methods(PsrLogLoggerInterface::class);
+
+        $quoteFactory->expects($this->once())
+             ->method('create')
+             ->willReturn($quote);
+        $customerSession->expects($this->exactly(3))
+             ->method('isLoggedIn')
+             ->willReturn(true);
+        $store = $this->getMockBuilder(MagentoStoreModelStore::class)
+             ->disableOriginalConstructor()
+             ->setMethods(['getWebsiteId', '__wakeup'])
+             ->getMock();
+        $storeManager->expects($this->any())
+             ->method('getStore')
+             ->will($this->returnValue($store));
+        $storage = $this->getMockBuilder(MagentoFrameworkSessionStorage::class)
+             ->disableOriginalConstructor()
+             ->setMethods(['setData', 'getData'])
+             ->getMock();
+        $storage->expects($this->at(0))
+             ->method('getData')
+             ->willReturn(1);
+        $quoteRepository->expects($this->once())
+             ->method('getActiveForCustomer')
+         ->willThrowException(new NoSuchEntityException());
+
+        foreach ($loggerMethods as $method) {
+            $logger->expects($this->never())->method($method);
+        }
+
+        $quote->expects($this->once())
+             ->method('setCustomer')
+             ->with(null);
+
+        $constructArguments = $this->_helper->getConstructArguments(
+            MagentoCheckoutModelSession::class,
+            [
+                'storeManager' => $storeManager,
+                'quoteRepository' => $quoteRepository,
+                'customerSession' => $customerSession,
+                'storage' => $storage,
+                'quoteFactory' => $quoteFactory,
+                'logger' => $logger
+            ]
+        );
+        $this->_session = $this->_helper->getObject(MagentoCheckoutModelSession::class, $constructArguments);
+        $this->_session->getQuote();
+    }
+
public function testSetStepData()
{
$stepData = [

相关内容

  • 没有找到相关文章

最新更新