-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathTaxClassLoader.php
More file actions
72 lines (60 loc) · 2.17 KB
/
Copy pathTaxClassLoader.php
File metadata and controls
72 lines (60 loc) · 2.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
declare(strict_types=1);
namespace Extcode\Cart\Configuration\Loader\SiteSets;
/*
* This file is part of the package extcode/cart.
*
* For the full copyright and license information, please read the
* LICENSE file that was distributed with this source code.
*/
use Extcode\Cart\Configuration\Loader\TaxClassLoaderInterface;
use Extcode\Cart\Domain\Model\Cart\TaxClass;
use Extcode\Cart\Domain\Model\Cart\TaxClassFactoryInterface;
use Extcode\Cart\Domain\Model\Cart\TaxClassInterface;
use Extcode\Cart\Utility\Typo3GlobalsUtility;
use TYPO3\CMS\Core\Site\Entity\Site;
final readonly class TaxClassLoader implements TaxClassLoaderInterface
{
private Site $site;
public function __construct(
private TaxClassFactoryInterface $taxClassFactory,
) {
$this->site = Typo3GlobalsUtility::getSiteFromTypo3Request();
}
/**
* @return TaxClass[]
*/
public function getTaxClasses(?string $countryCode = null): array
{
$taxClasses = [];
$configuration = $this->site->getSettings()->getAll();
if (is_array($configuration['extcode']) === false
|| is_array($configuration['extcode']['taxclasses']) === false
) {
return [];
}
$taxClassSettings = $configuration['extcode']['taxclasses'];
if (
is_string($countryCode)
&& array_key_exists($countryCode, $taxClassSettings)
&& is_array($taxClassSettings[$countryCode])
) {
$taxClassSettings = $taxClassSettings[$countryCode];
} elseif (
array_key_exists('fallback', $taxClassSettings)
&& is_array($taxClassSettings['fallback'])
) {
$taxClassSettings = $taxClassSettings['fallback'];
}
foreach ($taxClassSettings as $taxClassKey => $taxClassValue) {
if (is_array($taxClassValue) === false) {
continue;
}
$taxClass = $this->taxClassFactory->getTaxClass($taxClassKey, $taxClassValue);
if ($taxClass instanceof TaxClassInterface) {
$taxClasses[$taxClassKey] = $taxClass;
}
}
return $taxClasses;
}
}