From ba051dbe76999d300f4be0862f27564dfa08069b Mon Sep 17 00:00:00 2001 From: ashutosh Date: Thu, 25 Oct 2018 17:44:13 +0530 Subject: [PATCH 1/4] fixed Quote Item Prices are NULL in cart related events. #18685 --- app/code/Magento/Quote/Model/Quote/Item/Processor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Quote/Model/Quote/Item/Processor.php b/app/code/Magento/Quote/Model/Quote/Item/Processor.php index 2577008ecbae3..4bb8bd28b0c1c 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/Processor.php +++ b/app/code/Magento/Quote/Model/Quote/Item/Processor.php @@ -95,7 +95,7 @@ public function prepare(Item $item, DataObject $request, Product $candidate): vo $item->setData(CartItemInterface::KEY_QTY, 0); } $item->addQty($candidate->getCartQty()); - + $item->setPrice($item->getProduct()->getFinalPrice()); $customPrice = $request->getCustomPrice(); if (!empty($customPrice)) { $item->setCustomPrice($customPrice); From bc76ea0fd56cccf21a5c5f0438f24e5d3053d594 Mon Sep 17 00:00:00 2001 From: ashutosh Date: Fri, 26 Oct 2018 19:25:54 +0530 Subject: [PATCH 2/4] fixed unit test case issue --- .../Quote/Model/Quote/Item/Processor.php | 2 +- .../Unit/Model/Quote/Item/ProcessorTest.php | 34 +++++++++++++++++-- 2 files changed, 32 insertions(+), 4 deletions(-) diff --git a/app/code/Magento/Quote/Model/Quote/Item/Processor.php b/app/code/Magento/Quote/Model/Quote/Item/Processor.php index 4bb8bd28b0c1c..79c8bb925a1dc 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/Processor.php +++ b/app/code/Magento/Quote/Model/Quote/Item/Processor.php @@ -95,7 +95,7 @@ public function prepare(Item $item, DataObject $request, Product $candidate): vo $item->setData(CartItemInterface::KEY_QTY, 0); } $item->addQty($candidate->getCartQty()); - $item->setPrice($item->getProduct()->getFinalPrice()); + $item->setPrice($candidate->getFinalPrice()); $customPrice = $request->getCustomPrice(); if (!empty($customPrice)) { $item->setCustomPrice($customPrice); diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php index a56de35b70f75..f3d24343a7ca4 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php @@ -76,7 +76,8 @@ protected function setUp() 'addQty', 'setCustomPrice', 'setOriginalCustomPrice', - 'setData' + 'setData', + 'setprice' ]); $this->quoteItemFactoryMock->expects($this->any()) ->method('create') @@ -98,7 +99,7 @@ protected function setUp() $this->productMock = $this->createPartialMock( \Magento\Catalog\Model\Product::class, - ['getCustomOptions', '__wakeup', 'getParentProductId', 'getCartQty', 'getStickWithinParent'] + ['getCustomOptions', '__wakeup', 'getParentProductId', 'getCartQty', 'getStickWithinParent', 'getFinalPrice'] ); $this->objectMock = $this->createPartialMock( \Magento\Framework\DataObject::class, @@ -239,13 +240,16 @@ public function testPrepare() $customPrice = 400000000; $itemId = 1; $requestItemId = 1; - + $finalPrice = 1000000000; $this->productMock->expects($this->any()) ->method('getCartQty') ->will($this->returnValue($qty)); $this->productMock->expects($this->any()) ->method('getStickWithinParent') ->will($this->returnValue(false)); + $this->productMock->expects($this->once()) + ->method('getFinalPrice') + ->will($this->returnValue($finalPrice)); $this->itemMock->expects($this->once()) ->method('addQty') @@ -255,6 +259,9 @@ public function testPrepare() ->will($this->returnValue($itemId)); $this->itemMock->expects($this->never()) ->method('setData'); + $this->itemMock->expects($this->once()) + ->method('setPrice') + ->will($this->returnValue($this->itemMock)); $this->objectMock->expects($this->any()) ->method('getCustomPrice') @@ -282,6 +289,7 @@ public function testPrepareWithResetCountAndStick() $customPrice = 400000000; $itemId = 1; $requestItemId = 1; + $finalPrice = 1000000000; $this->productMock->expects($this->any()) ->method('getCartQty') @@ -289,6 +297,9 @@ public function testPrepareWithResetCountAndStick() $this->productMock->expects($this->any()) ->method('getStickWithinParent') ->will($this->returnValue(true)); + $this->productMock->expects($this->once()) + ->method('getFinalPrice') + ->will($this->returnValue($finalPrice)); $this->itemMock->expects($this->once()) ->method('addQty') @@ -298,6 +309,9 @@ public function testPrepareWithResetCountAndStick() ->will($this->returnValue($itemId)); $this->itemMock->expects($this->never()) ->method('setData'); + $this->itemMock->expects($this->once()) + ->method('setPrice') + ->will($this->returnValue($this->itemMock)); $this->objectMock->expects($this->any()) ->method('getCustomPrice') @@ -325,6 +339,7 @@ public function testPrepareWithResetCountAndNotStickAndOtherItemId() $customPrice = 400000000; $itemId = 1; $requestItemId = 2; + $finalPrice = 1000000000; $this->productMock->expects($this->any()) ->method('getCartQty') @@ -332,6 +347,9 @@ public function testPrepareWithResetCountAndNotStickAndOtherItemId() $this->productMock->expects($this->any()) ->method('getStickWithinParent') ->will($this->returnValue(false)); + $this->productMock->expects($this->once()) + ->method('getFinalPrice') + ->will($this->returnValue($finalPrice)); $this->itemMock->expects($this->once()) ->method('addQty') @@ -341,6 +359,9 @@ public function testPrepareWithResetCountAndNotStickAndOtherItemId() ->will($this->returnValue($itemId)); $this->itemMock->expects($this->never()) ->method('setData'); + $this->itemMock->expects($this->once()) + ->method('setPrice') + ->will($this->returnValue($this->itemMock)); $this->objectMock->expects($this->any()) ->method('getCustomPrice') @@ -368,6 +389,7 @@ public function testPrepareWithResetCountAndNotStickAndSameItemId() $customPrice = 400000000; $itemId = 1; $requestItemId = 1; + $finalPrice = 1000000000; $this->objectMock->expects($this->any()) ->method('getResetCount') @@ -386,10 +408,16 @@ public function testPrepareWithResetCountAndNotStickAndSameItemId() $this->productMock->expects($this->any()) ->method('getStickWithinParent') ->will($this->returnValue(false)); + $this->productMock->expects($this->once()) + ->method('getFinalPrice') + ->will($this->returnValue($finalPrice)); $this->itemMock->expects($this->once()) ->method('addQty') ->with($qty); + $this->itemMock->expects($this->once()) + ->method('setPrice') + ->will($this->returnValue($this->itemMock)); $this->objectMock->expects($this->any()) ->method('getCustomPrice') From ccac19d377a1813c38e57494c446615bf5fad0dd Mon Sep 17 00:00:00 2001 From: Sergii Ivashchenko Date: Sun, 13 Jan 2019 19:55:57 +0000 Subject: [PATCH 3/4] magento/magento2#18806: Fixed static and WebAPI tests --- app/code/Magento/Quote/Model/Quote/Item/Processor.php | 2 +- .../Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php | 9 ++++++++- .../Magento/Catalog/Api/CartItemRepositoryTest.php | 8 +++++--- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Quote/Model/Quote/Item/Processor.php b/app/code/Magento/Quote/Model/Quote/Item/Processor.php index 79c8bb925a1dc..a69f5c27be11b 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/Processor.php +++ b/app/code/Magento/Quote/Model/Quote/Item/Processor.php @@ -53,8 +53,8 @@ public function __construct( /** * Initialize quote item object * - * @param DataObject $request * @param Product $product + * @param DataObject $request * * @return Item */ diff --git a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php index f3d24343a7ca4..d253da8683a7b 100644 --- a/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php +++ b/app/code/Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php @@ -99,7 +99,14 @@ protected function setUp() $this->productMock = $this->createPartialMock( \Magento\Catalog\Model\Product::class, - ['getCustomOptions', '__wakeup', 'getParentProductId', 'getCartQty', 'getStickWithinParent', 'getFinalPrice'] + [ + 'getCustomOptions', + '__wakeup', + 'getParentProductId', + 'getCartQty', + 'getStickWithinParent', + 'getFinalPrice' + ] ); $this->objectMock = $this->createPartialMock( \Magento\Framework\DataObject::class, diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php index 18f57515c4d18..43f73530c305b 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php @@ -3,6 +3,7 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ + namespace Magento\Catalog\Api; use Magento\TestFramework\TestCase\WebapiAbstract; @@ -58,11 +59,12 @@ public function testAddProductToCartWithCustomOptions() $item = $quote->getAllItems()[0]; $this->assertEquals( [ - 'item_id' => $item->getItemId(), + 'item_id' => (int) $item->getItemId(), 'sku' => $item->getSku(), 'qty' => $item->getQty(), 'name' => $item->getName(), - + 'price' => $item->getPrice(), + 'product_type' => $item->getProductType(), 'quote_id' => $item->getQuoteId(), 'product_option' => [ @@ -80,7 +82,7 @@ public function testAddProductToCartWithCustomOptions() */ public function testGetList() { - /** @var \Magento\Quote\Model\Quote $quote */ + /** @var \Magento\Quote\Model\Quote $quote */ $quote = $this->objectManager->create(\Magento\Quote\Model\Quote::class); $quote->load('test_order_1', 'reserved_order_id'); $cartId = $quote->getId(); From 2a6d02d96cc43aa47b4f08245c947bd24fb35529 Mon Sep 17 00:00:00 2001 From: Pavel Bystritsky Date: Mon, 28 Jan 2019 16:07:40 +0200 Subject: [PATCH 4/4] ENGCOM-3272: Database compare and Web-API tests fix. --- .../Setup/Patch/Data/UpdateQuoteItemPrice.php | 98 +++++++++++++++++++ .../Catalog/Api/CartItemRepositoryTest.php | 1 + 2 files changed, 99 insertions(+) create mode 100644 app/code/Magento/ConfigurableProduct/Setup/Patch/Data/UpdateQuoteItemPrice.php diff --git a/app/code/Magento/ConfigurableProduct/Setup/Patch/Data/UpdateQuoteItemPrice.php b/app/code/Magento/ConfigurableProduct/Setup/Patch/Data/UpdateQuoteItemPrice.php new file mode 100644 index 0000000000000..8cb2fd48f427e --- /dev/null +++ b/app/code/Magento/ConfigurableProduct/Setup/Patch/Data/UpdateQuoteItemPrice.php @@ -0,0 +1,98 @@ +moduleDataSetup = $moduleDataSetup; + } + + /** + * @inheritdoc + */ + public function apply() + { + $this->moduleDataSetup->getConnection()->beginTransaction(); + try { + $this->applyPatch(); + $this->moduleDataSetup->getConnection()->commit(); + } catch (\Exception $e) { + $this->moduleDataSetup->getConnection()->rollBack(); + throw $e; + } + } + + /** + * Update 'price' value for quote items without price of configurable products subproducts. + * + * @return void + */ + private function applyPatch(): void + { + $connection = $this->moduleDataSetup->getConnection(); + $quoteItemTable = $this->moduleDataSetup->getTable('quote_item'); + $select = $connection->select(); + $select->joinLeft( + ['qi2' => $quoteItemTable], + 'qi1.parent_item_id = qi2.item_id', + ['price'] + )->where( + 'qi1.price = 0' + . ' AND qi1.parent_item_id IS NOT NULL' + . ' AND qi2.product_type = "' . Configurable::TYPE_CODE . '"' + ); + $updateQuoteItem = $this->moduleDataSetup->getConnection()->updateFromSelect( + $select, + ['qi1' => $quoteItemTable] + ); + $this->moduleDataSetup->getConnection()->query($updateQuoteItem); + } + + /** + * @inheritdoc + */ + public static function getDependencies() + { + return []; + } + + /** + * @inheritdoc + */ + public static function getVersion() + { + return '2.2.2'; + } + + /** + * @inheritdoc + */ + public function getAliases() + { + return []; + } +} diff --git a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php index 43f73530c305b..0bd1ee109be0a 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php @@ -72,6 +72,7 @@ public function testAddProductToCartWithCustomOptions() 'custom_options' => $this->getOptions(), ], ], + 'price' => $item->getPrice(), ], $response );