From e77fc028bc2f22b8dfccd1961491b0c08318249a Mon Sep 17 00:00:00 2001 From: ashutosh Date: Thu, 25 Oct 2018 18:02:22 +0530 Subject: [PATCH 1/8] 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 997a050518a374589f919073b6539b83ecaf3c02 Mon Sep 17 00:00:00 2001 From: ashutosh Date: Sun, 28 Oct 2018 15:47:48 +0530 Subject: [PATCH 2/8] fixed unit test issues --- .../Quote/Model/Quote/Item/Processor.php | 3 +- .../Unit/Model/Quote/Item/ProcessorTest.php | 33 +++++++++++++++++-- 2 files changed, 33 insertions(+), 3 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..767834d6a72fc 100644 --- a/app/code/Magento/Quote/Model/Quote/Item/Processor.php +++ b/app/code/Magento/Quote/Model/Quote/Item/Processor.php @@ -95,8 +95,9 @@ 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(); + $item->setPrice($candidate->getFinalPrice()); if (!empty($customPrice)) { $item->setCustomPrice($customPrice); $item->setOriginalCustomPrice($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..7da7ed49149f7 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,6 +240,7 @@ public function testPrepare() $customPrice = 400000000; $itemId = 1; $requestItemId = 1; + $finalPrice = 1000000000; $this->productMock->expects($this->any()) ->method('getCartQty') @@ -246,6 +248,9 @@ public function testPrepare() $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 +260,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 +290,7 @@ public function testPrepareWithResetCountAndStick() $customPrice = 400000000; $itemId = 1; $requestItemId = 1; + $finalPrice = 1000000000; $this->productMock->expects($this->any()) ->method('getCartQty') @@ -289,6 +298,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 +310,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 +340,7 @@ public function testPrepareWithResetCountAndNotStickAndOtherItemId() $customPrice = 400000000; $itemId = 1; $requestItemId = 2; + $finalPrice = 1000000000; $this->productMock->expects($this->any()) ->method('getCartQty') @@ -332,6 +348,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 +360,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 +390,7 @@ public function testPrepareWithResetCountAndNotStickAndSameItemId() $customPrice = 400000000; $itemId = 1; $requestItemId = 1; + $finalPrice = 1000000000; $this->objectMock->expects($this->any()) ->method('getResetCount') @@ -386,10 +409,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 3c282f90d64fde86bf44c4b4b7e70548e493336a Mon Sep 17 00:00:00 2001 From: ashutosh Date: Tue, 30 Oct 2018 02:05:48 +0530 Subject: [PATCH 3/8] fixed phpcs issue: Line exceeds maximum limit of 120 characters; contains 121 --- .../Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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 7da7ed49149f7..0b4b167d2472e 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,13 @@ 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, From e14d5cce259e60d10817e03558c211755059e50b Mon Sep 17 00:00:00 2001 From: ashutosh Date: Tue, 30 Oct 2018 15:37:19 +0530 Subject: [PATCH 4/8] error fixed Whitespace found at end of line --- .../Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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 0b4b167d2472e..e8cfb05ca89b9 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 @@ -100,11 +100,11 @@ 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( From 8b49ff98ca6203d8a38f8bb4054620c20dab686d Mon Sep 17 00:00:00 2001 From: Eden Date: Wed, 24 Jul 2019 04:37:14 +0700 Subject: [PATCH 5/8] to pass static test --- app/code/Magento/Quote/Model/Quote/Item/Processor.php | 2 +- .../Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Quote/Model/Quote/Item/Processor.php b/app/code/Magento/Quote/Model/Quote/Item/Processor.php index 767834d6a72fc..ef4b853862681 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 e8cfb05ca89b9..74cc165021d81 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 @@ -68,7 +68,8 @@ protected function setUp() ['create'] ); - $this->itemMock = $this->createPartialMock(\Magento\Quote\Model\Quote\Item::class, [ + $this->itemMock = $this->createPartialMock(\Magento\Quote\Model\Quote\Item::class, + [ 'getId', 'setOptions', '__wakeup', @@ -78,7 +79,8 @@ protected function setUp() 'setOriginalCustomPrice', 'setData', 'setprice' - ]); + ] + ); $this->quoteItemFactoryMock->expects($this->any()) ->method('create') ->will($this->returnValue($this->itemMock)); From da18ecd570a8855bd2daa23ed6d6264c7fc603a5 Mon Sep 17 00:00:00 2001 From: Eden Date: Wed, 24 Jul 2019 06:47:13 +0700 Subject: [PATCH 6/8] to pass static test, api test --- .../Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php | 3 ++- .../testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) 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 74cc165021d81..208d65925bf3d 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 @@ -68,7 +68,8 @@ protected function setUp() ['create'] ); - $this->itemMock = $this->createPartialMock(\Magento\Quote\Model\Quote\Item::class, + $this->itemMock = $this->createPartialMock( + \Magento\Quote\Model\Quote\Item::class, [ 'getId', 'setOptions', 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..aac82494cf3cb 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php @@ -62,7 +62,7 @@ public function testAddProductToCartWithCustomOptions() 'sku' => $item->getSku(), 'qty' => $item->getQty(), 'name' => $item->getName(), - + 'price' => $item->getPrice(), 'product_type' => $item->getProductType(), 'quote_id' => $item->getQuoteId(), 'product_option' => [ From 23bb9b5f44394e57ecbb3d603fd93e2533e98803 Mon Sep 17 00:00:00 2001 From: Eden Date: Wed, 24 Jul 2019 07:19:27 +0700 Subject: [PATCH 7/8] to pass static test --- .../testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php | 3 +++ 1 file changed, 3 insertions(+) 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 aac82494cf3cb..7c0988392fa41 100644 --- a/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php +++ b/dev/tests/api-functional/testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php @@ -9,6 +9,9 @@ use Magento\Catalog\Api\Data\ProductCustomOptionInterface; use Magento\ConfigurableProduct\Model\Product\Type\Configurable; +/** + * Class \Magento\Catalog\Api\CartItemRepositoryTest + */ class CartItemRepositoryTest extends WebapiAbstract { const SERVICE_NAME = 'quoteCartItemRepositoryV1'; From 2b518365bbbb4d30d745b6a46536c3cad4ff7d50 Mon Sep 17 00:00:00 2001 From: Eden Date: Sun, 28 Jul 2019 19:54:32 +0700 Subject: [PATCH 8/8] add declare(strict_types=1); --- app/code/Magento/Quote/Model/Quote/Item.php | 2 ++ .../Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php | 2 ++ .../testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php | 2 ++ 3 files changed, 6 insertions(+) diff --git a/app/code/Magento/Quote/Model/Quote/Item.php b/app/code/Magento/Quote/Model/Quote/Item.php index 2d6ff67018160..d14ae008ce407 100644 --- a/app/code/Magento/Quote/Model/Quote/Item.php +++ b/app/code/Magento/Quote/Model/Quote/Item.php @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Quote\Model\Quote; use Magento\Framework\Api\AttributeValueFactory; 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 208d65925bf3d..28890ba2a9b24 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 @@ -3,6 +3,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Quote\Test\Unit\Model\Quote\Item; use Magento\Catalog\Model\Product; 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 7c0988392fa41..ad7548b390607 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,8 @@ * Copyright © Magento, Inc. All rights reserved. * See COPYING.txt for license details. */ +declare(strict_types=1); + namespace Magento\Catalog\Api; use Magento\TestFramework\TestCase\WebapiAbstract;