Skip to content

Commit 5f01793

Browse files
committed
Merge remote-tracking branch 'origin/MC-34063' into 2.4-develop-pr31
2 parents 61a694f + c5563f2 commit 5f01793

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ 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());
100+
if (!$item->getParentItem() || $item->getParentItem()->isChildrenCalculated()) {
101+
$item->setPrice($candidate->getFinalPrice());
102+
}
101103
if (!empty($customPrice)) {
102104
$item->setCustomPrice($customPrice);
103105
$item->setOriginalCustomPrice($customPrice);

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

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,16 @@ protected function setUp(): void
7777

7878
$this->itemMock = $this->getMockBuilder(Item::class)
7979
->addMethods(['setOriginalCustomPrice'])
80-
->onlyMethods(['getId', 'setOptions', 'setProduct', 'addQty', 'setCustomPrice', 'setData', 'setPrice'])
80+
->onlyMethods([
81+
'getId',
82+
'setOptions',
83+
'setProduct',
84+
'addQty',
85+
'setCustomPrice',
86+
'setData',
87+
'setPrice',
88+
'getParentItem'
89+
])
8190
->disableOriginalConstructor()
8291
->getMock();
8392
$this->quoteItemFactoryMock->expects($this->any())
@@ -438,4 +447,41 @@ public function testPrepareWithResetCountAndNotStickAndSameItemId()
438447

439448
$this->processor->prepare($this->itemMock, $this->objectMock, $this->productMock);
440449
}
450+
451+
/**
452+
* @param bool $isChildrenCalculated
453+
* @dataProvider prepareChildProductDataProvider
454+
*/
455+
public function testPrepareChildProduct(bool $isChildrenCalculated): void
456+
{
457+
$finalPrice = 10;
458+
$this->objectMock->method('getResetCount')
459+
->willReturn(false);
460+
$this->productMock->method('getFinalPrice')
461+
->willReturn($finalPrice);
462+
$this->itemMock->expects($isChildrenCalculated ? $this->once() : $this->never())
463+
->method('setPrice')
464+
->with($finalPrice)
465+
->willReturnSelf();
466+
$parentItem = $this->createConfiguredMock(
467+
\Magento\Quote\Model\Quote\Item::class,
468+
[
469+
'isChildrenCalculated' => $isChildrenCalculated
470+
]
471+
);
472+
$this->itemMock->method('getParentItem')
473+
->willReturn($parentItem);
474+
$this->processor->prepare($this->itemMock, $this->objectMock, $this->productMock);
475+
}
476+
477+
/**
478+
* @return array
479+
*/
480+
public function prepareChildProductDataProvider(): array
481+
{
482+
return [
483+
[false],
484+
[true]
485+
];
486+
}
441487
}

0 commit comments

Comments
 (0)