Skip to content

Commit 034142a

Browse files
committed
BUG#AC-3157: Grouped product with tax throws exception with PHP 8.1
1 parent 7fa8c4f commit 034142a

File tree

2 files changed

+17
-13
lines changed

2 files changed

+17
-13
lines changed

app/code/Magento/Tax/Pricing/Render/Adjustment.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,7 @@ public function displayPriceExcludingTax()
183183
*/
184184
public function getDataPriceType(): string
185185
{
186-
return $this->amountRender->getPriceType() === 'finalPrice'
187-
? 'basePrice'
188-
: 'base' . ucfirst($this->amountRender->getPriceType() ?? '');
186+
$priceType = $this->amountRender->getPriceType();
187+
return $priceType === 'finalPrice' ? 'basePrice' : ($priceType ? 'base' . ucfirst($priceType) : '');
189188
}
190189
}

app/code/Magento/Tax/Test/Unit/Pricing/Render/AdjustmentTest.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
class AdjustmentTest extends TestCase
3030
{
3131
/**
32-
* Context mock
33-
*
3432
* @var \Magento\Framework\View\Element\Template\Context
3533
*/
3634
protected $contextMock;
@@ -358,23 +356,30 @@ public function testGetHtmlBoth()
358356

359357
/**
360358
* test for method getDataPriceType
359+
* @dataProvider dataPriceTypeDataProvider
361360
*/
362-
public function testGetDataPriceType(): void
361+
public function testGetDataPriceType(?string $priceType, string $priceTypeValue): void
363362
{
364363
$amountRender = $this->getMockBuilder(Amount::class)
365364
->addMethods(['getPriceType'])
366365
->disableOriginalConstructor()
367366
->getMock();
368367
$amountRender->expects($this->atLeastOnce())
369368
->method('getPriceType')
370-
->willReturn('finalPrice');
371-
$this->model->render($amountRender, []);
372-
$this->assertEquals('basePrice', $this->model->getDataPriceType());
373-
$amountRender->expects($this->atLeastOnce())
374-
->method('getPriceType')
375-
->willReturn(null);
369+
->willReturn($priceType);
376370
$this->model->render($amountRender, []);
377-
//no exception thrown
371+
//no exception is thrown
372+
$this->assertEquals($priceTypeValue, $this->model->getDataPriceType());
378373
$this->assertIsString($this->model->getDataPriceType());
379374
}
375+
376+
/**
377+
* data provider for testGetDataPriceType
378+
*
379+
* @return array
380+
*/
381+
public function dataPriceTypeDataProvider(): array
382+
{
383+
return [['finalPrice', 'basePrice'], [null, '']];
384+
}
380385
}

0 commit comments

Comments
 (0)