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/Model/Quote/Item/Processor.php b/app/code/Magento/Quote/Model/Quote/Item/Processor.php index 2577008ecbae3..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 */ @@ -97,6 +97,7 @@ public function prepare(Item $item, DataObject $request, Product $candidate): vo $item->addQty($candidate->getCartQty()); $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..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; @@ -68,7 +70,9 @@ 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', @@ -76,8 +80,10 @@ protected function setUp() 'addQty', 'setCustomPrice', 'setOriginalCustomPrice', - 'setData' - ]); + 'setData', + 'setprice' + ] + ); $this->quoteItemFactoryMock->expects($this->any()) ->method('create') ->will($this->returnValue($this->itemMock)); @@ -98,7 +104,13 @@ 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 +251,7 @@ public function testPrepare() $customPrice = 400000000; $itemId = 1; $requestItemId = 1; + $finalPrice = 1000000000; $this->productMock->expects($this->any()) ->method('getCartQty') @@ -246,6 +259,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 +271,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 +301,7 @@ public function testPrepareWithResetCountAndStick() $customPrice = 400000000; $itemId = 1; $requestItemId = 1; + $finalPrice = 1000000000; $this->productMock->expects($this->any()) ->method('getCartQty') @@ -289,6 +309,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 +321,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 +351,7 @@ public function testPrepareWithResetCountAndNotStickAndOtherItemId() $customPrice = 400000000; $itemId = 1; $requestItemId = 2; + $finalPrice = 1000000000; $this->productMock->expects($this->any()) ->method('getCartQty') @@ -332,6 +359,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 +371,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 +401,7 @@ public function testPrepareWithResetCountAndNotStickAndSameItemId() $customPrice = 400000000; $itemId = 1; $requestItemId = 1; + $finalPrice = 1000000000; $this->objectMock->expects($this->any()) ->method('getResetCount') @@ -386,10 +420,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') 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..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,12 +3,17 @@ * 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; 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'; @@ -62,7 +67,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' => [