-
-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Create TaxClasses by TaxClassFactory
Relates: #505
- Loading branch information
Showing
6 changed files
with
137 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Extcode\Cart\Domain\Model\Cart; | ||
|
||
/* | ||
* 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 Psr\Log\LoggerInterface; | ||
|
||
final class TaxClassFactory implements TaxClassFactoryInterface | ||
{ | ||
public function __construct( | ||
private readonly LoggerInterface $logger | ||
) {} | ||
|
||
public function getTaxClass(int $taxClassKey, array $taxClassValue): ?TaxClass | ||
{ | ||
if ($this->isValidTaxClassConfig($taxClassKey, $taxClassValue)) { | ||
return new TaxClass( | ||
$taxClassKey, | ||
$taxClassValue['value'], | ||
(float)$taxClassValue['calc'], | ||
$taxClassValue['name'] | ||
); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
private function isValidTaxClassConfig(int $key, array $value): bool | ||
{ | ||
if (empty($value) || | ||
empty($value['name']) || | ||
!isset($value['calc']) || | ||
!is_numeric($value['calc']) | ||
) { | ||
$this->logger->error('Can\'t create tax class object for the configuration with the index=' . $key . '.', []); | ||
|
||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Extcode\Cart\Domain\Model\Cart; | ||
|
||
/* | ||
* 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. | ||
*/ | ||
|
||
interface TaxClassFactoryInterface | ||
{ | ||
public function getTaxClass(int $taxClassKey, array $taxClassValue): ?TaxClass; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Extcode\Cart\Domain\Model\Cart; | ||
|
||
/* | ||
* 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. | ||
*/ | ||
|
||
interface TaxClassInterface | ||
{ | ||
public function getId(): int; | ||
|
||
public function getValue(): string; | ||
|
||
public function getCalc(): float; | ||
|
||
public function getTitle(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
Documentation/Changelog/9.0/Breaking-505-ReplaceParserUtilityParseTaxByDI.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
.. include:: ../../Includes.txt | ||
|
||
====================================================== | ||
Breaking: #505 - Replace ParserUtility::parseTax by DI | ||
====================================================== | ||
|
||
See :issue:`480` | ||
|
||
Description | ||
=========== | ||
|
||
The existing `\Extcode\Cart\Utility\ParserUtility::parseTax()` uses a TaxClassService | ||
which could be configured by a TypoScript Configuration. The change remove the | ||
method from the class and injecting the `Extcode\Cart\Service\TaxClassServiceInterface` | ||
by Dependency Injection. | ||
|
||
Affected Installations | ||
====================== | ||
|
||
All installations where `plugin.tx_cart.taxClasses.className` is used to replace | ||
the default TaxClassService. | ||
|
||
Migration | ||
========= | ||
|
||
Remove the old configuration from TypoScript. | ||
Add an entry to your `Services.yaml` or `Services.php` and configure your | ||
implementation of the `Extcode\Cart\Service\TaxClassServiceInterface` for the | ||
`$taxClassService` constructor argument. | ||
|
||
.. index:: Backend, Dependency Injection |