Skip to content

Commit 2f02e91

Browse files
committed
BUG#AC-3157: Grouped product with tax throws exception with PHP 8.1
1 parent 2e45de7 commit 2f02e91

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,6 @@ public function getDataPriceType(): string
185185
{
186186
return $this->amountRender->getPriceType() === 'finalPrice'
187187
? 'basePrice'
188-
: 'base' . ucfirst($this->amountRender->getPriceType());
188+
: 'base' . ucfirst($this->amountRender->getPriceType() ?? '');
189189
}
190190
}

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@ class AdjustmentTest extends TestCase
5454
*/
5555
protected $model;
5656

57+
/**
58+
* @var AmountRenderInterface
59+
*/
60+
protected $amountRender;
61+
5762
/**
5863
* Init mocks and model
5964
*/
@@ -350,4 +355,26 @@ public function testGetHtmlBoth()
350355

351356
$this->model->render($amountRender, $arguments);
352357
}
358+
359+
/**
360+
* test for method getDataPriceType
361+
*/
362+
public function testGetDataPriceType(): void
363+
{
364+
$amountRender = $this->getMockBuilder(Amount::class)
365+
->addMethods(['getPriceType'])
366+
->disableOriginalConstructor()
367+
->getMock();
368+
$amountRender->expects($this->atLeastOnce())
369+
->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('anythingElse');
376+
$this->model->render($amountRender, []);
377+
//no exception thrown
378+
$this->assertIsString($this->model->getDataPriceType());
379+
}
353380
}

0 commit comments

Comments
 (0)