diff --git a/Classes/Domain/Model/Cart/FeVariant.php b/Classes/Domain/Model/Cart/FeVariant.php index ddec47c4..f962e771 100644 --- a/Classes/Domain/Model/Cart/FeVariant.php +++ b/Classes/Domain/Model/Cart/FeVariant.php @@ -11,7 +11,7 @@ * LICENSE file that was distributed with this source code. */ -class FeVariant +class FeVariant implements FeVariantInterface { protected ?Product $product = null; diff --git a/Classes/Domain/Model/Cart/FeVariantInterface.php b/Classes/Domain/Model/Cart/FeVariantInterface.php new file mode 100644 index 00000000..1f17dd45 --- /dev/null +++ b/Classes/Domain/Model/Cart/FeVariantInterface.php @@ -0,0 +1,16 @@ +feVariant = $feVariant; @@ -153,7 +153,7 @@ public function changeVariantsQuantity(array $variantQuantity): void } } - public function getFeVariant(): ?FeVariant + public function getFeVariant(): ?FeVariantInterface { return $this->feVariant; } @@ -554,9 +554,16 @@ protected function calcGross(): void foreach ($this->beVariants as $variant) { $sum += $variant->getGross(); } + if ($this->feVariant instanceof FeVariantWithPriceInterface) { + $sum += $this->feVariant->getPrice(); + } $this->gross = $sum; } else { - $this->gross = $this->getBestPrice() * $this->quantity; + $sum = $this->getBestPrice(); + if ($this->feVariant instanceof FeVariantWithPriceInterface) { + $sum += $this->feVariant->getPrice(); + } + $this->gross = $sum * $this->quantity; } } else { $this->calcNet(); @@ -582,9 +589,16 @@ protected function calcNet(): void foreach ($this->beVariants as $variant) { $sum += $variant->getNet(); } + if ($this->feVariant instanceof FeVariantWithPriceInterface) { + $sum += $this->feVariant->getPrice(); + } $this->net = $sum; } else { - $this->net = $this->getBestPrice() * $this->quantity; + $sum = $this->getBestPrice(); + if ($this->feVariant instanceof FeVariantWithPriceInterface) { + $sum += $this->feVariant->getPrice(); + } + $this->net = $sum * $this->quantity; } } else { $this->calcGross(); diff --git a/Documentation/Changelog/9.0/Feature-465-DateFormatInBackendModuleFilter.rst b/Documentation/Changelog/9.0/Feature-465-DateFormatInBackendModuleFilter.rst index 86e1a47c..f9c70774 100644 --- a/Documentation/Changelog/9.0/Feature-465-DateFormatInBackendModuleFilter.rst +++ b/Documentation/Changelog/9.0/Feature-465-DateFormatInBackendModuleFilter.rst @@ -32,6 +32,7 @@ Before this the dates in the backend were always in the format `d.m.Y`, now it Migration ========= + To get the old formatting you need to overwrite the above shown TypoScript constants: diff --git a/Documentation/Changelog/9.4/Feature-615-AllowFeVariantToHaveAPrice.rst b/Documentation/Changelog/9.4/Feature-615-AllowFeVariantToHaveAPrice.rst new file mode 100644 index 00000000..bc6d7b50 --- /dev/null +++ b/Documentation/Changelog/9.4/Feature-615-AllowFeVariantToHaveAPrice.rst @@ -0,0 +1,50 @@ +.. include:: ../../Includes.rst.txt + +=============================================== +Feature: #615 - Allow FeVariant to have a price +=============================================== + +See `Issue 615 `__ + +Description +=========== + +The default `FeVariant` implementation cannot have a price. In order to be able +to process own `FeVariant`s with a price, the method arguments should use a +`FeVariantInterface` instead. + +The `FeVariantWithPriceInterface` extends the `FeVariantInterface` with a +`getPrice()` method. +The price calculation of a product then takes into account whether the +`FeVariant` implements the `FeVariantWithPriceInterface` to add this price as +well. + +To create an own `FeVariant` for a `Product`, you have to replace the +`CreateCartFrontendVariants` EventListener. + +.. code-block:: yaml + :caption: EXT:my_extension/Configuration/Services.yaml + + Extcode\CartProducts\EventListener\Create\CreateCartFrontendVariants: null + + MyVendor\MyExtension\EventListener\Create\CreateCartFrontendVariants: + tags: + - name: event.listener + identifier: 'cart-products--create--create-cart-frontend-variants' + event: Extcode\CartProducts\Event\RetrieveProductsFromRequestEvent + after: 'cart-products--create--load-product' + + +This is very flexible. You can implement `FeVariant`s as checkboxes and add some +surcharge for some options. Another idea is to calculate the price markup +depending on the number of characters entered.How you can use this is up to you. +However, you should test carefully whether the price calculation for the product +price then fits, especially if you use more than one front-end variant with a +price for a product. + +Impact +====== + +No Impact. + +.. index:: Frontend, API diff --git a/Documentation/Changelog/9.4/Index.rst b/Documentation/Changelog/9.4/Index.rst new file mode 100644 index 00000000..0fa7086a --- /dev/null +++ b/Documentation/Changelog/9.4/Index.rst @@ -0,0 +1,20 @@ +.. include:: ../../Includes.rst.txt + +9.4 Changes +=========== + +**Table of contents** + +.. contents:: + :local: + :depth: 1 + +Features +-------- + +.. toctree:: + :maxdepth: 1 + :titlesonly: + :glob: + + Feature-* diff --git a/Documentation/Changelog/Index.rst b/Documentation/Changelog/Index.rst index 3cc03d24..6d026dc3 100644 --- a/Documentation/Changelog/Index.rst +++ b/Documentation/Changelog/Index.rst @@ -10,6 +10,7 @@ ChangeLog :maxdepth: 5 :titlesonly: + 9.4/Index 9.3/Index 9.1/Index 9.0/Index diff --git a/Documentation/guides.xml b/Documentation/guides.xml index cd9077d7..23821f58 100644 --- a/Documentation/guides.xml +++ b/Documentation/guides.xml @@ -11,8 +11,8 @@ interlink-shortcode="extcode/cart" /> diff --git a/ext_emconf.php b/ext_emconf.php index 6c647375..702fc71d 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.3.0', + 'version' => '9.4.0', 'state' => 'stable', 'author' => 'Daniel Gohlke', 'author_email' => 'ext@extco.de',