From 2bdcc11de0bd8d127a3115383ea960577c840920 Mon Sep 17 00:00:00 2001 From: "vadim.malesh" Date: Wed, 4 Mar 2020 16:23:26 +0200 Subject: [PATCH 1/3] 14086: Guest cart API ignoring cartId in url for some methods --- .../Magento/Quote/Plugin/UpdateCartId.php | 49 +++++++++++++++++ app/code/Magento/Quote/etc/webapi_rest/di.xml | 3 ++ .../Quote/Api/GuestCartItemRepositoryTest.php | 54 ++++++++++--------- 3 files changed, 81 insertions(+), 25 deletions(-) create mode 100644 app/code/Magento/Quote/Plugin/UpdateCartId.php diff --git a/app/code/Magento/Quote/Plugin/UpdateCartId.php b/app/code/Magento/Quote/Plugin/UpdateCartId.php new file mode 100644 index 0000000000000..3d5dd21f2e494 --- /dev/null +++ b/app/code/Magento/Quote/Plugin/UpdateCartId.php @@ -0,0 +1,49 @@ +request = $request; + } + + /** + * Update id from request if param cartId exist + * + * @param GuestCartItemRepositoryInterface $guestCartItemRepository + * @param CartItemInterface $cartItem + * @return void + * @SuppressWarnings(PHPMD.UnusedFormalParameter) + */ + public function beforeSave( + GuestCartItemRepositoryInterface $guestCartItemRepository, + CartItemInterface $cartItem + ): void { + if ($cartId = $this->request->getParam('cartId')) { + $cartItem->setQuoteId($cartId); + } + } +} diff --git a/app/code/Magento/Quote/etc/webapi_rest/di.xml b/app/code/Magento/Quote/etc/webapi_rest/di.xml index 27d5ff7753425..a55d2146be156 100644 --- a/app/code/Magento/Quote/etc/webapi_rest/di.xml +++ b/app/code/Magento/Quote/etc/webapi_rest/di.xml @@ -13,4 +13,7 @@ + + + diff --git a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php index e03a54f9463d7..ddd986bdafc60 100644 --- a/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Quote/Api/GuestCartItemRepositoryTest.php @@ -1,6 +1,5 @@ objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager(); + $this->objectManager = Bootstrap::getObjectManager(); } /** + * Test quote items + * * @magentoApiDataFixture Magento/Checkout/_files/quote_with_items_saved.php */ public function testGetList() @@ -112,12 +121,16 @@ public function testAddItem() ]; $requestData = [ - "cartItem" => [ - "sku" => $productSku, - "qty" => 7, - "quote_id" => $cartId, + 'cartItem' => [ + 'sku' => $productSku, + 'qty' => 7, ], ]; + + if (TESTS_WEB_API_ADAPTER === self::ADAPTER_SOAP) { + $requestData['cartItem']['quote_id'] = $cartId; + } + $this->_webApiCall($serviceInfo, $requestData); $this->assertTrue($quote->hasProductId(2)); $this->assertEquals(7, $quote->getItemByProduct($product)->getQty()); @@ -205,20 +218,11 @@ public function testUpdateItem(array $stockData, string $errorMessage = null) ], ]; - if (TESTS_WEB_API_ADAPTER == self::ADAPTER_SOAP) { - $requestData = [ - "cartItem" => [ - "qty" => 5, - "quote_id" => $cartId, - "itemId" => $itemId, - ], - ]; - } else { - $requestData = [ - "cartItem" => [ - "qty" => 5, - "quote_id" => $cartId, - ], + $requestData['cartItem']['qty'] = 5; + if (TESTS_WEB_API_ADAPTER === self::ADAPTER_SOAP) { + $requestData['cartItem'] += [ + 'quote_id' => $cartId, + 'itemId' => $itemId, ]; } if ($errorMessage) { From 23f98498398e58b755ddffbe65601633402ea0af Mon Sep 17 00:00:00 2001 From: "vadim.malesh" Date: Tue, 10 Mar 2020 11:12:30 +0200 Subject: [PATCH 2/3] improvement --- app/code/Magento/Quote/Plugin/UpdateCartId.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Plugin/UpdateCartId.php b/app/code/Magento/Quote/Plugin/UpdateCartId.php index 3d5dd21f2e494..46aecd176454f 100644 --- a/app/code/Magento/Quote/Plugin/UpdateCartId.php +++ b/app/code/Magento/Quote/Plugin/UpdateCartId.php @@ -42,7 +42,9 @@ public function beforeSave( GuestCartItemRepositoryInterface $guestCartItemRepository, CartItemInterface $cartItem ): void { - if ($cartId = $this->request->getParam('cartId')) { + $cartId = $this->request->getParam('cartId'); + + if ($cartId) { $cartItem->setQuoteId($cartId); } } From e3c2951cb7fe8c25afc3ad7ee8a8cda8c64422d0 Mon Sep 17 00:00:00 2001 From: engcom-Echo Date: Wed, 11 Mar 2020 15:32:56 +0200 Subject: [PATCH 3/3] Fix mftf test --- .../Swatches/Test/Mftf/Section/AdminManageSwatchSection.xml | 1 + .../Swatches/Test/Mftf/Test/AdminCreateImageSwatchTest.xml | 2 ++ .../Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml | 1 + 3 files changed, 4 insertions(+) diff --git a/app/code/Magento/Swatches/Test/Mftf/Section/AdminManageSwatchSection.xml b/app/code/Magento/Swatches/Test/Mftf/Section/AdminManageSwatchSection.xml index 629599eba84fe..ab4502f3e9cfb 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Section/AdminManageSwatchSection.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Section/AdminManageSwatchSection.xml @@ -21,6 +21,7 @@ + diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateImageSwatchTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateImageSwatchTest.xml index 0e24d63728d9d..5a78efcde33b7 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateImageSwatchTest.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Test/AdminCreateImageSwatchTest.xml @@ -53,6 +53,7 @@ + @@ -62,6 +63,7 @@ + diff --git a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml index 427797bdb09e2..39b3ca51327ba 100644 --- a/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml +++ b/app/code/Magento/Swatches/Test/Mftf/Test/StorefrontFilterByImageSwatchTest.xml @@ -55,6 +55,7 @@ +