Skip to content

Commit

Permalink
[BUGFIX] Taxclass 'calc' can have value (int)0
Browse files Browse the repository at this point in the history
Setting a the value `calc` of a taxClass to the
integer value '0' works and does no longer result
in an error.

Fixes #430
  • Loading branch information
rintisch committed Mar 25, 2024
1 parent f09d45f commit 338c7f3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Classes/Service/TaxClassService.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,10 @@ protected function isValidTaxClassConfig(int $key, array $value): bool
{
if (empty($value) ||
empty($value['name']) ||
empty($value['calc']) ||
!is_numeric($value['calc'])
(isset($value['calc']) && !is_numeric($value['calc']))
) {
$logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(__CLASS__);
$logger->error('Can\'t create tax class object for \'' . $key . '\'.', []);
$logger->error('Can\'t create tax class object for the configuration with the index=' . $key . '.', []);

return false;
}
Expand Down
28 changes: 28 additions & 0 deletions Tests/Functional/Service/TaxClassServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,4 +256,32 @@ public function parsingTaxClassesFromTypoScriptWithNotConfiguredCountryCodeRetur
$firstTaxClasses->getTitle()
);
}

/**
* @test
*/
public function parsingTaxClassesFromTypoScriptWithIntegerZeroAsCalcIsValid()
{
$settings = [
'taxClasses' => [
'1' => [
'value' => '0',
'calc' => '0',
'name' => 'free',
],
],
];

$reflection = new \ReflectionClass($this->taxClassService);
$reflection_property = $reflection->getProperty('settings');
$reflection_property->setAccessible(true);
$reflection_property->setValue($this->taxClassService, $settings);

$taxClasses = $this->taxClassService->getTaxClasses();

self::assertEquals(
$taxClasses[1]->getCalc(),
0
);
}
}

0 comments on commit 338c7f3

Please sign in to comment.