Skip to content

Commit 8e11a8d

Browse files
authored
ENGCOM-5521: [Forwardport] fixed Quote Item Prices are NULL in cart related events. #18685 #23839
2 parents 662d961 + 4933cb2 commit 8e11a8d

File tree

4 files changed

+54
-6
lines changed

4 files changed

+54
-6
lines changed

app/code/Magento/Quote/Model/Quote/Item.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Quote\Model\Quote;
79

810
use Magento\Framework\Api\AttributeValueFactory;

app/code/Magento/Quote/Model/Quote/Item/Processor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ public function __construct(
5353
/**
5454
* Initialize quote item object
5555
*
56-
* @param DataObject $request
5756
* @param Product $product
57+
* @param DataObject $request
5858
*
5959
* @return Item
6060
*/
@@ -97,6 +97,7 @@ public function prepare(Item $item, DataObject $request, Product $candidate): vo
9797
$item->addQty($candidate->getCartQty());
9898

9999
$customPrice = $request->getCustomPrice();
100+
$item->setPrice($candidate->getFinalPrice());
100101
if (!empty($customPrice)) {
101102
$item->setCustomPrice($customPrice);
102103
$item->setOriginalCustomPrice($customPrice);

app/code/Magento/Quote/Test/Unit/Model/Quote/Item/ProcessorTest.php

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Quote\Test\Unit\Model\Quote\Item;
79

810
use Magento\Catalog\Model\Product;
@@ -68,16 +70,20 @@ protected function setUp()
6870
['create']
6971
);
7072

71-
$this->itemMock = $this->createPartialMock(\Magento\Quote\Model\Quote\Item::class, [
73+
$this->itemMock = $this->createPartialMock(
74+
\Magento\Quote\Model\Quote\Item::class,
75+
[
7276
'getId',
7377
'setOptions',
7478
'__wakeup',
7579
'setProduct',
7680
'addQty',
7781
'setCustomPrice',
7882
'setOriginalCustomPrice',
79-
'setData'
80-
]);
83+
'setData',
84+
'setprice'
85+
]
86+
);
8187
$this->quoteItemFactoryMock->expects($this->any())
8288
->method('create')
8389
->will($this->returnValue($this->itemMock));
@@ -98,7 +104,13 @@ protected function setUp()
98104

99105
$this->productMock = $this->createPartialMock(
100106
\Magento\Catalog\Model\Product::class,
101-
['getCustomOptions', '__wakeup', 'getParentProductId', 'getCartQty', 'getStickWithinParent']
107+
[
108+
'getCustomOptions',
109+
'__wakeup',
110+
'getParentProductId',
111+
'getCartQty',
112+
'getStickWithinParent',
113+
'getFinalPrice']
102114
);
103115
$this->objectMock = $this->createPartialMock(
104116
\Magento\Framework\DataObject::class,
@@ -239,13 +251,17 @@ public function testPrepare()
239251
$customPrice = 400000000;
240252
$itemId = 1;
241253
$requestItemId = 1;
254+
$finalPrice = 1000000000;
242255

243256
$this->productMock->expects($this->any())
244257
->method('getCartQty')
245258
->will($this->returnValue($qty));
246259
$this->productMock->expects($this->any())
247260
->method('getStickWithinParent')
248261
->will($this->returnValue(false));
262+
$this->productMock->expects($this->once())
263+
->method('getFinalPrice')
264+
->will($this->returnValue($finalPrice));
249265

250266
$this->itemMock->expects($this->once())
251267
->method('addQty')
@@ -255,6 +271,9 @@ public function testPrepare()
255271
->will($this->returnValue($itemId));
256272
$this->itemMock->expects($this->never())
257273
->method('setData');
274+
$this->itemMock->expects($this->once())
275+
->method('setPrice')
276+
->will($this->returnValue($this->itemMock));
258277

259278
$this->objectMock->expects($this->any())
260279
->method('getCustomPrice')
@@ -282,13 +301,17 @@ public function testPrepareWithResetCountAndStick()
282301
$customPrice = 400000000;
283302
$itemId = 1;
284303
$requestItemId = 1;
304+
$finalPrice = 1000000000;
285305

286306
$this->productMock->expects($this->any())
287307
->method('getCartQty')
288308
->will($this->returnValue($qty));
289309
$this->productMock->expects($this->any())
290310
->method('getStickWithinParent')
291311
->will($this->returnValue(true));
312+
$this->productMock->expects($this->once())
313+
->method('getFinalPrice')
314+
->will($this->returnValue($finalPrice));
292315

293316
$this->itemMock->expects($this->once())
294317
->method('addQty')
@@ -298,6 +321,9 @@ public function testPrepareWithResetCountAndStick()
298321
->will($this->returnValue($itemId));
299322
$this->itemMock->expects($this->never())
300323
->method('setData');
324+
$this->itemMock->expects($this->once())
325+
->method('setPrice')
326+
->will($this->returnValue($this->itemMock));
301327

302328
$this->objectMock->expects($this->any())
303329
->method('getCustomPrice')
@@ -325,13 +351,17 @@ public function testPrepareWithResetCountAndNotStickAndOtherItemId()
325351
$customPrice = 400000000;
326352
$itemId = 1;
327353
$requestItemId = 2;
354+
$finalPrice = 1000000000;
328355

329356
$this->productMock->expects($this->any())
330357
->method('getCartQty')
331358
->will($this->returnValue($qty));
332359
$this->productMock->expects($this->any())
333360
->method('getStickWithinParent')
334361
->will($this->returnValue(false));
362+
$this->productMock->expects($this->once())
363+
->method('getFinalPrice')
364+
->will($this->returnValue($finalPrice));
335365

336366
$this->itemMock->expects($this->once())
337367
->method('addQty')
@@ -341,6 +371,9 @@ public function testPrepareWithResetCountAndNotStickAndOtherItemId()
341371
->will($this->returnValue($itemId));
342372
$this->itemMock->expects($this->never())
343373
->method('setData');
374+
$this->itemMock->expects($this->once())
375+
->method('setPrice')
376+
->will($this->returnValue($this->itemMock));
344377

345378
$this->objectMock->expects($this->any())
346379
->method('getCustomPrice')
@@ -368,6 +401,7 @@ public function testPrepareWithResetCountAndNotStickAndSameItemId()
368401
$customPrice = 400000000;
369402
$itemId = 1;
370403
$requestItemId = 1;
404+
$finalPrice = 1000000000;
371405

372406
$this->objectMock->expects($this->any())
373407
->method('getResetCount')
@@ -386,10 +420,16 @@ public function testPrepareWithResetCountAndNotStickAndSameItemId()
386420
$this->productMock->expects($this->any())
387421
->method('getStickWithinParent')
388422
->will($this->returnValue(false));
423+
$this->productMock->expects($this->once())
424+
->method('getFinalPrice')
425+
->will($this->returnValue($finalPrice));
389426

390427
$this->itemMock->expects($this->once())
391428
->method('addQty')
392429
->with($qty);
430+
$this->itemMock->expects($this->once())
431+
->method('setPrice')
432+
->will($this->returnValue($this->itemMock));
393433

394434
$this->objectMock->expects($this->any())
395435
->method('getCustomPrice')

dev/tests/api-functional/testsuite/Magento/Catalog/Api/CartItemRepositoryTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,17 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Catalog\Api;
79

810
use Magento\TestFramework\TestCase\WebapiAbstract;
911
use Magento\Catalog\Api\Data\ProductCustomOptionInterface;
1012
use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
1113

14+
/**
15+
* Class \Magento\Catalog\Api\CartItemRepositoryTest
16+
*/
1217
class CartItemRepositoryTest extends WebapiAbstract
1318
{
1419
const SERVICE_NAME = 'quoteCartItemRepositoryV1';
@@ -62,7 +67,7 @@ public function testAddProductToCartWithCustomOptions()
6267
'sku' => $item->getSku(),
6368
'qty' => $item->getQty(),
6469
'name' => $item->getName(),
65-
70+
'price' => $item->getPrice(),
6671
'product_type' => $item->getProductType(),
6772
'quote_id' => $item->getQuoteId(),
6873
'product_option' => [

0 commit comments

Comments
 (0)