From 130883352e5332f1a03ae8374dfd3f56c624fbe0 Mon Sep 17 00:00:00 2001 From: Fiko Borizqy Date: Fri, 25 Feb 2022 01:04:58 +0000 Subject: [PATCH 1/3] Bug Fixed: [Duplicate orders with same Quote Id at same time with few time difference.](https://github.com/magento/magento2/issues/13952) --- app/code/Magento/Quote/Model/QuoteManagement.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index 51b68411d4080..ce6bb4f3b1960 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -388,6 +388,8 @@ protected function createCustomerCart($customerId, $storeId) public function placeOrder($cartId, PaymentInterface $paymentMethod = null) { $quote = $this->quoteRepository->getActive($cartId); + $quote->setIsActive(false); + $this->quoteRepository->save($quote); $customer = $quote->getCustomer(); $customerId = $customer ? $customer->getId() : null; @@ -611,6 +613,8 @@ protected function submitQuote(QuoteEntity $quote, $orderData = []) ); $this->quoteRepository->save($quote); } catch (\Exception $e) { + $quote->setIsActive(1); + $this->quoteRepository->save($quote); $this->rollbackAddresses($quote, $order, $e); throw $e; } From c4b3a0a92a4050e50dfdd870c648b8fb5834d9e0 Mon Sep 17 00:00:00 2001 From: Fiko Borizqy Date: Fri, 12 Aug 2022 02:28:21 +0000 Subject: [PATCH 2/3] fix arguments of app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php::testExecuteUrlKey --- .../Observer/ProductProcessUrlRewriteSavingObserverTest.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php index 0f74ce0f14d77..c28667c123b2e 100644 --- a/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php +++ b/app/code/Magento/CatalogUrlRewrite/Test/Unit/Observer/ProductProcessUrlRewriteSavingObserverTest.php @@ -302,7 +302,9 @@ public function urlKeyDataProvider() * @param array $origData * @param array $newData * @param int $expectedExecutionCount - * @param int $expectedStoresToAdd + * @param array $expectedStoresToAdd + * @param array $doesEntityHaveOverriddenVisibilityForStore + * @param array $expectedStoresToRemove * @throws \Magento\UrlRewrite\Model\Exception\UrlAlreadyExistsException * @dataProvider urlKeyDataProvider */ @@ -312,7 +314,7 @@ public function testExecuteUrlKey( int $expectedExecutionCount, array $expectedStoresToAdd = [], array $doesEntityHaveOverriddenVisibilityForStore = [], - array $expectedStoresToRemove = [], + array $expectedStoresToRemove = [] ) { $this->product->setData($origData); $this->product->setOrigData(); From a5de75320e7fff5ae58a55914abac071fcbf87a8 Mon Sep 17 00:00:00 2001 From: Fiko Borizqy Date: Fri, 12 Aug 2022 07:37:17 +0000 Subject: [PATCH 3/3] issue#13952: add condition if empty cart. --- app/code/Magento/Quote/Model/QuoteManagement.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Quote/Model/QuoteManagement.php b/app/code/Magento/Quote/Model/QuoteManagement.php index ce6bb4f3b1960..31a44dea52391 100644 --- a/app/code/Magento/Quote/Model/QuoteManagement.php +++ b/app/code/Magento/Quote/Model/QuoteManagement.php @@ -388,11 +388,14 @@ protected function createCustomerCart($customerId, $storeId) public function placeOrder($cartId, PaymentInterface $paymentMethod = null) { $quote = $this->quoteRepository->getActive($cartId); - $quote->setIsActive(false); - $this->quoteRepository->save($quote); $customer = $quote->getCustomer(); $customerId = $customer ? $customer->getId() : null; + if (!$quote->isEmpty()) { + $quote->setIsActive(false); + $this->quoteRepository->save($quote); + } + if ($paymentMethod) { $paymentMethod->setChecks( [ @@ -613,8 +616,10 @@ protected function submitQuote(QuoteEntity $quote, $orderData = []) ); $this->quoteRepository->save($quote); } catch (\Exception $e) { - $quote->setIsActive(1); - $this->quoteRepository->save($quote); + if (!$quote->isEmpty()) { + $quote->setIsActive(1); + $this->quoteRepository->save($quote); + } $this->rollbackAddresses($quote, $order, $e); throw $e; }