diff --git a/Build/phpstan-baseline.neon b/Build/phpstan-baseline.neon index e244ca64..2c4057f4 100644 --- a/Build/phpstan-baseline.neon +++ b/Build/phpstan-baseline.neon @@ -5,26 +5,6 @@ parameters: count: 1 path: ../Classes/Controller/Cart/OrderController.php - - - message: "#^Deprecated in PHP 8\\.0\\: Required parameter \\$price follows optional parameter \\$beVariant\\.$#" - count: 1 - path: ../Classes/Domain/Model/Cart/BeVariant.php - - - - message: "#^Deprecated in PHP 8\\.0\\: Required parameter \\$priceCalcMethod follows optional parameter \\$beVariant\\.$#" - count: 1 - path: ../Classes/Domain/Model/Cart/BeVariant.php - - - - message: "#^Deprecated in PHP 8\\.0\\: Required parameter \\$sku follows optional parameter \\$beVariant\\.$#" - count: 1 - path: ../Classes/Domain/Model/Cart/BeVariant.php - - - - message: "#^Deprecated in PHP 8\\.1\\: Required parameter \\$title follows optional parameter \\$beVariant\\.$#" - count: 1 - path: ../Classes/Domain/Model/Cart/BeVariant.php - - message: "#^Call to an undefined method Extcode\\\\Cart\\\\Domain\\\\Model\\\\Cart\\\\CartCouponInterface\\:\\:getTaxClass\\(\\)\\.$#" count: 2 diff --git a/Classes/Domain/Model/Cart/BeVariant.php b/Classes/Domain/Model/Cart/BeVariant.php index a1f47162..0fff53a3 100644 --- a/Classes/Domain/Model/Cart/BeVariant.php +++ b/Classes/Domain/Model/Cart/BeVariant.php @@ -13,10 +13,6 @@ class BeVariant { - protected ?Product $product = null; - - protected ?BeVariant $parentBeVariant = null; - protected string $titleDelimiter = ' - '; protected string $skuDelimiter = '-'; @@ -45,30 +41,13 @@ class BeVariant public function __construct( protected string $id, - ?Product $product = null, - ?self $beVariant = null, + protected self|Product $parent, protected string $title, protected string $sku, protected int $priceCalcMethod, protected float $price, protected int $quantity = 0 ) { - if ($product === null && $beVariant === null) { - throw new \InvalidArgumentException(); - } - - if ($product != null && $beVariant != null) { - throw new \InvalidArgumentException(); - } - - if ($product !== null) { - $this->product = $product; - } - - if ($beVariant !== null) { - $this->parentBeVariant = $beVariant; - } - $this->reCalc(); } @@ -102,36 +81,28 @@ public function toArray(): array return $variantArr; } - public function getProduct(): ?Product + public function getParent(): self|Product { - return $this->product; + return $this->parent; } - public function setProduct(Product $product): void + public function setParent(self|Product $parent): void { - $this->product = $product; + $this->parent = $parent; } - public function getParentBeVariant(): ?self + public function getProduct(): Product { - return $this->parentBeVariant; - } + if ($this->parent instanceof Product) { + return $this->parent; + } - public function setParentBeVariant(self $parentBeVariant): void - { - $this->parentBeVariant = $parentBeVariant; + return $this->parent->getProduct(); } public function isNetPrice(): bool { - if ($this->getParentBeVariant()) { - return $this->getParentBeVariant()->isNetPrice(); - } - if ($this->getProduct()) { - return $this->getProduct()->isNetPrice(); - } - - return false; + return $this->parent->isNetPrice(); } public function getId(): string @@ -158,10 +129,10 @@ public function getCompleteTitle(): string { $title = ''; - if ($this->getParentBeVariant()) { - $title = $this->getParentBeVariant()->getCompleteTitle(); - } elseif ($this->getProduct()) { - $title = $this->getProduct()->getTitle(); + if ($this->parent instanceof self) { + $title = $this->parent->getCompleteTitle(); + } elseif ($this->parent instanceof Product) { + $title = $this->parent->getTitle(); } if ($this->isFeVariant) { @@ -178,8 +149,8 @@ public function getCompleteTitleWithoutProduct(): string $title = ''; $titleDelimiter = ''; - if ($this->getParentBeVariant()) { - $title = $this->getParentBeVariant()->getCompleteTitleWithoutProduct(); + if ($this->parent instanceof self) { + $title = $this->parent->getCompleteTitleWithoutProduct(); $titleDelimiter = $this->titleDelimiter; } @@ -244,12 +215,12 @@ public function getPriceCalculated(): float { $price = $this->getBestPrice(); - if ($this->getParentBeVariant()) { - $parentPrice = $this->getParentBeVariant()->getBestPrice(); - } elseif ($this->getProduct()) { - $parentPrice = $this->getProduct()->getBestPrice($this->getQuantity()); + if ($this->parent instanceof self) { + $parentPrice = $this->parent->getBestPrice(); + } elseif ($this->parent instanceof Product) { + $parentPrice = $this->parent->getBestPrice($this->getQuantity()); } else { - $parentPrice = 0; + $parentPrice = 0.0; } if ($this->priceCalcMethod === 0) { @@ -285,15 +256,11 @@ public function getParentPrice(): float return 0.0; } - if ($this->getParentBeVariant()) { - return $this->getParentBeVariant()->getBestPrice(); + if ($this->parent instanceof self) { + return $this->parent->getBestPrice(); } - if ($this->getProduct()) { - return $this->getProduct()->getBestPrice($this->getQuantity()); - } - - return 0.0; + return $this->parent->getBestPrice($this->getQuantity()); } public function setPrice(float $price): void @@ -332,10 +299,10 @@ public function getCompleteSku(): string { $sku = ''; - if ($this->getParentBeVariant()) { - $sku = $this->getParentBeVariant()->getCompleteSku(); - } elseif ($this->getProduct()) { - $sku = $this->getProduct()->getSku(); + if ($this->parent instanceof self) { + $sku = $this->parent->getCompleteSku(); + } elseif ($this->parent instanceof Product) { + $sku = $this->parent->getSku(); } if ($this->isFeVariant) { @@ -353,8 +320,8 @@ public function getCompleteSkuWithoutProduct(): string $skuDelimiter = ''; - if ($this->getParentBeVariant()) { - $sku = $this->getParentBeVariant()->getCompleteSkuWithoutProduct(); + if ($this->parent instanceof self) { + $sku = $this->parent->getCompleteSkuWithoutProduct(); $skuDelimiter = $this->titleDelimiter; } @@ -416,14 +383,7 @@ public function getTax(): float public function getTaxClass(): ?TaxClass { - if ($this->getParentBeVariant()) { - return $this->getParentBeVariant()->getTaxClass(); - } - if ($this->getProduct()) { - return $this->getProduct()->getTaxClass(); - } - - return null; + return $this->parent->getTaxClass(); } public function setQuantity(int $newQuantity): void diff --git a/Classes/Domain/Model/Cart/Product.php b/Classes/Domain/Model/Cart/Product.php index c1f5b65c..9791896c 100644 --- a/Classes/Domain/Model/Cart/Product.php +++ b/Classes/Domain/Model/Cart/Product.php @@ -130,7 +130,7 @@ public function addBeVariant(BeVariant $newVariant): void $variant->setQuantity($newQuantity); } } else { - $newVariant->setProduct($this); + $newVariant->setParent($this); $this->beVariants[$newVariantsId] = $newVariant; } diff --git a/Classes/EventListener/Order/Create/PersistOrder/Products.php b/Classes/EventListener/Order/Create/PersistOrder/Products.php index bb0f06ac..b23992ff 100644 --- a/Classes/EventListener/Order/Create/PersistOrder/Products.php +++ b/Classes/EventListener/Order/Create/PersistOrder/Products.php @@ -141,20 +141,7 @@ protected function addVariantsOfVariant(BeVariant $variant, int $level): void protected function addBeVariant(BeVariant $variant, int $level): void { - $variantInner = $variant; - for ($count = $level; $count > 0; $count--) { - if ($count > 1) { - $variantInner = $variantInner->getParentBeVariant(); - } else { - $cartProduct = $variantInner->getProduct(); - } - } - unset($variantInner); - - if (!isset($cartProduct)) { - // ToDo Add Error Message - return; - } + $cartProduct = $variant->getProduct(); $orderProduct = GeneralUtility::makeInstance( \Extcode\Cart\Domain\Model\Order\Product::class @@ -193,11 +180,7 @@ protected function addBeVariant(BeVariant $variant, int $level): void $orderProduct->addProductAdditional($orderProductAdditional); - if ($count > 1) { - $variantInner = $variantInner->getParentBeVariant(); - } else { - $cartProduct = $variantInner->getProduct(); - } + $variantInner = $variantInner->getParent(); } unset($variantInner); diff --git a/Classes/ViewHelpers/FieldNameViewHelper.php b/Classes/ViewHelpers/FieldNameViewHelper.php index 6e2475bd..b4593272 100644 --- a/Classes/ViewHelpers/FieldNameViewHelper.php +++ b/Classes/ViewHelpers/FieldNameViewHelper.php @@ -55,11 +55,12 @@ protected function getVariantFieldName(BeVariant $variant): string { $fieldName = ''; - if ($variant->getParentBeVariant()) { - $fieldName .= $this->getVariantFieldName($variant->getParentBeVariant()); + if ($variant->getParent() instanceof BeVariant) { + $fieldName .= $this->getVariantFieldName($variant->getParent()); } - if ($variant->getProduct()) { - $fieldName .= '[' . $variant->getProduct()->getId() . ']'; + + if ($variant->getParent() instanceof Product) { + $fieldName .= '[' . $variant->getParent()->getId() . ']'; } $fieldName .= '[' . $variant->getId() . ']'; diff --git a/Documentation/Changelog/10.0/Breaking-611-ChangePhpDependency.rst b/Documentation/Changelog/10.0/Breaking-611-ChangePhpDependency.rst new file mode 100644 index 00000000..eea1c0db --- /dev/null +++ b/Documentation/Changelog/10.0/Breaking-611-ChangePhpDependency.rst @@ -0,0 +1,33 @@ +.. include:: ../../Includes.rst.txt + +================================================= +Breaking: #611 - Change BeVariant Parent Handling +================================================= + +See `Issue 611 `__ + +Description +=========== + +Previously, a `BeVariant` had either another `BeVariant` or a `Product` as its parent element. These were passed in the +constructor method. + +Thanks to PHP's union types, this can now be resolved. A `BeVariant` now has a `$parent` that is either of type +`BeVariant` or of type `Product`. + +The individual methods have been adapted accordingly and it is checked of which class `$parent` is an instance. In some +cases, the case differentiation could be omitted completely. + +Affected Installations +====================== + +All product extensions that use their own `BeVariant` in the products are affected. The provided extensions +extcode/cart-products and extcode/cart-events will be adapted accordingly. + +Migration +========= + +If a custom product extension is used, the constructor must be adapted accordingly. Furthermore, a few +methods in `BeVariant` have been replaced or their behavior adapted. + +.. index:: API diff --git a/Documentation/Changelog/10.0/Index.rst b/Documentation/Changelog/10.0/Index.rst new file mode 100644 index 00000000..f1afa74d --- /dev/null +++ b/Documentation/Changelog/10.0/Index.rst @@ -0,0 +1,20 @@ +.. include:: ../../Includes.rst.txt + +10.0 Changes +============ + +**Table of contents** + +.. contents:: + :local: + :depth: 1 + +Breaking +-------- + +.. toctree:: + :maxdepth: 1 + :titlesonly: + :glob: + + Breaking-* diff --git a/Documentation/Changelog/Index.rst b/Documentation/Changelog/Index.rst index 6d026dc3..df6a0063 100644 --- a/Documentation/Changelog/Index.rst +++ b/Documentation/Changelog/Index.rst @@ -10,6 +10,7 @@ ChangeLog :maxdepth: 5 :titlesonly: + 10.0/Index 9.4/Index 9.3/Index 9.1/Index diff --git a/Documentation/guides.xml b/Documentation/guides.xml index f95211ce..39dfb9f7 100644 --- a/Documentation/guides.xml +++ b/Documentation/guides.xml @@ -11,8 +11,8 @@ interlink-shortcode="extcode/cart" /> diff --git a/README.md b/README.md index 4e45ee32..7ca1f648 100644 --- a/README.md +++ b/README.md @@ -45,17 +45,7 @@ Sometimes minor versions also result in minor adjustments to own templates or co ## 3.1 Compatibility and supported Versions -| Cart | TYPO3 | PHP | Support/Development | -|--------|------------|-----------|--------------------------------------| -| 9.x.x | 12.4 | 8.1 - 8.4 | Features, Bugfixes, Security Updates | -| 8.x.x | 10.4, 11.5 | 7.2+ | Features, Bugfixes, Security Updates | -| 7.x.x | 10.4 | 7.2 - 7.4 | Security Updates | -| 6.x.x | 9.5 | 7.2 - 7.4 | | -| 5.x.x | 8.7 | 7.0 - 7.4 | | -| 4.x.x | 7.6 - 8.7 | 5.6 - 7.2 | | -| 3.x.x | 6.2 - 8.7 | 5.6 - 7.0 | | -| 2.x.x | | | | -| 1.x.x | | | | +Please refer to the current [README](https://github.com/extcode/cart/blob/main/README.md#31-compatibility-and-supported-versions). If you need extended support for features and bug fixes outside of the currently supported versions, we are happy to offer paid services. diff --git a/Tests/Unit/Domain/Model/Cart/BeVariantTest.php b/Tests/Unit/Domain/Model/Cart/BeVariantTest.php index dd255dde..70734a85 100644 --- a/Tests/Unit/Domain/Model/Cart/BeVariantTest.php +++ b/Tests/Unit/Domain/Model/Cart/BeVariantTest.php @@ -68,7 +68,6 @@ public function setUp(): void $this->beVariant = new BeVariant( $this->id, $this->product, - null, $this->title, $this->sku, $this->priceCalcMethod, @@ -181,40 +180,6 @@ public function getQuantityReturnsQuantitySetByConstructor(): void ); } - #[Test] - public function constructVariantWithoutCartProductOrVariantThrowsInvalidArgumentException(): void - { - $this->expectException(\InvalidArgumentException::class); - - new BeVariant( - $this->id, - null, - null, - $this->sku, - $this->title, - $this->priceCalcMethod, - $this->price, - $this->quantity - ); - } - - #[Test] - public function constructVariantWithCartProductAndVariantThrowsInvalidArgumentException(): void - { - $this->expectException(\InvalidArgumentException::class); - - new BeVariant( - $this->id, - $this->product, - $this->beVariant, - $this->sku, - $this->title, - $this->priceCalcMethod, - $this->price, - $this->quantity - ); - } - #[Test] public function constructWithoutTitleThrowsException(): void { @@ -224,7 +189,6 @@ public function constructWithoutTitleThrowsException(): void 1, $this->product, null, - null, 'test-variant-sku', 0, 1.0, @@ -240,7 +204,6 @@ public function constructWithoutSkuThrowsException(): void new BeVariant( 1, $this->product, - null, 'Test Variant', null, 0, @@ -257,7 +220,6 @@ public function constructWithoutQuantityThrowsException(): void new BeVariant( 1, $this->product, - null, 'Test Variant', 'test-variant-sku', 0, @@ -448,7 +410,6 @@ public function getParentPriceRespectsTheQuantityDiscountsOfProductsForEachVaria $beVariant1 = new BeVariant( '1', $this->product, - null, $title, $sku, $priceCalcMethod, @@ -460,7 +421,6 @@ public function getParentPriceRespectsTheQuantityDiscountsOfProductsForEachVaria $beVariant2 = new BeVariant( '2', $this->product, - null, $title, $sku, $priceCalcMethod, @@ -472,7 +432,6 @@ public function getParentPriceRespectsTheQuantityDiscountsOfProductsForEachVaria $beVariant3 = new BeVariant( '3', $this->product, - null, $title, $sku, $priceCalcMethod, diff --git a/ext_emconf.php b/ext_emconf.php index 47470a61..b9e29680 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -4,7 +4,7 @@ 'title' => 'Cart', 'description' => 'Shopping Cart(s) for TYPO3', 'category' => 'plugin', - 'version' => '9.4.1', + 'version' => '10.0.0', 'state' => 'stable', 'author' => 'Daniel Gohlke', 'author_email' => 'ext@extco.de',