From 25c55a44cd98b9d1eecadc1ddfb3297e9e47a505 Mon Sep 17 00:00:00 2001 From: Daniel Gohlke Date: Fri, 17 Apr 2026 20:02:58 +0200 Subject: [PATCH] [TASK] Add SiteSets as default configuration for cart --- Build/phpstan-baseline.neon | 418 ++++++++---------- Classes/{ => Configuration}/Constants.php | 2 +- .../Loader/CurrencyTranslationLoader.php} | 4 +- .../CurrencyTranslationLoaderInterface.php} | 4 +- .../Loader/PaymentMethodsLoaderInterface.php} | 4 +- .../ShippingMethodsLoaderInterface.php} | 4 +- .../SiteSets/AbstractConfigurationLoader.php | 136 ++++++ .../Loader/SiteSets/PaymentMethodsLoader.php | 27 ++ .../Loader/SiteSets/ShippingMethodsLoader.php | 27 ++ .../Loader/SiteSets/TaxClassLoader.php | 72 +++ .../Loader/SpecialOptionsLoaderInterface.php} | 4 +- .../Loader/TaxClassLoaderInterface.php} | 4 +- .../AbstractConfigurationLoader.php | 122 +++++ .../TypoScript/PaymentMethodsLoader.php} | 5 +- .../TypoScript/ShippingMethodsLoader.php} | 5 +- .../TypoScript/SpecialOptionsLoader.php} | 5 +- .../Loader/TypoScript/TaxClassLoader.php} | 9 +- Classes/Controller/Cart/ActionController.php | 30 +- Classes/Controller/Cart/CountryController.php | 6 +- Classes/Controller/Cart/OrderController.php | 2 +- Classes/Controller/Cart/PaymentController.php | 2 +- .../Controller/Cart/ShippingController.php | 2 +- Classes/Domain/Model/Cart/Cart.php | 12 +- .../EventListener/Order/Finish/ClearCart.php | 6 +- Classes/EventListener/Order/Finish/Email.php | 6 +- ...ractConfigurationFromTypoScriptService.php | 97 ---- Classes/Utility/CartUtility.php | 22 +- Classes/Utility/Typo3GlobalsUtility.php | 30 +- .../Traversable/ExtractViewHelper.php | 2 +- .../Widgets/Provider/OrdersPerDayProvider.php | 2 +- .../Provider/TurnoverPerDayProvider.php | 2 +- Configuration/Services.php | 1 + Configuration/Services.yaml | 16 - Configuration/Services/Configuration.php | 86 ++++ Configuration/Sets/Payments/config.yaml | 2 + Configuration/Sets/Payments/settings.yaml | 13 + Configuration/Sets/Shippings/config.yaml | 2 + Configuration/Sets/Shippings/settings.yaml | 13 + Configuration/Sets/TaxClass/config.yaml | 2 + Configuration/Sets/TaxClass/settings.yaml | 14 + Configuration/TCA/Overrides/pages.php | 2 +- Configuration/TypoScript/setup.typoscript | 4 +- ...king-756-AddSiteSetConfigurationLoader.rst | 46 ++ ...ture-756-AddSiteSetConfigurationLoader.rst | 41 ++ Documentation/Changelog/12.0/Index.rst | 10 + .../AbstractConfigurationLoaderTest.php} | 16 +- .../Loader/TypoScript/TaxClassLoaderTest.php} | 12 +- Tests/Unit/ConstantsTest.php | 2 +- .../Domain/Model/Cart/CartCouponFixTest.php | 8 +- .../Model/Cart/CartCouponPercentageTest.php | 8 +- Tests/Unit/Domain/Model/Cart/CartTest.php | 28 +- Tests/Unit/Domain/Model/Cart/ServiceTest.php | 8 +- 52 files changed, 950 insertions(+), 457 deletions(-) rename Classes/{ => Configuration}/Constants.php (93%) rename Classes/{Service/CurrencyTranslationService.php => Configuration/Loader/CurrencyTranslationLoader.php} (78%) rename Classes/{Service/CurrencyTranslationServiceInterface.php => Configuration/Loader/CurrencyTranslationLoaderInterface.php} (83%) rename Classes/{Service/PaymentMethodsServiceInterface.php => Configuration/Loader/PaymentMethodsLoaderInterface.php} (83%) rename Classes/{Service/ShippingMethodsServiceInterface.php => Configuration/Loader/ShippingMethodsLoaderInterface.php} (83%) create mode 100644 Classes/Configuration/Loader/SiteSets/AbstractConfigurationLoader.php create mode 100644 Classes/Configuration/Loader/SiteSets/PaymentMethodsLoader.php create mode 100644 Classes/Configuration/Loader/SiteSets/ShippingMethodsLoader.php create mode 100644 Classes/Configuration/Loader/SiteSets/TaxClassLoader.php rename Classes/{Service/SpecialOptionsServiceInterface.php => Configuration/Loader/SpecialOptionsLoaderInterface.php} (79%) rename Classes/{Service/TaxClassServiceInterface.php => Configuration/Loader/TaxClassLoaderInterface.php} (82%) create mode 100644 Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php rename Classes/{Service/PaymentMethodsFromTypoScriptService.php => Configuration/Loader/TypoScript/PaymentMethodsLoader.php} (68%) rename Classes/{Service/ShippingMethodsFromTypoScriptService.php => Configuration/Loader/TypoScript/ShippingMethodsLoader.php} (68%) rename Classes/{Service/SpecialOptionsFromTypoScriptService.php => Configuration/Loader/TypoScript/SpecialOptionsLoader.php} (68%) rename Classes/{Service/TaxClassService.php => Configuration/Loader/TypoScript/TaxClassLoader.php} (84%) delete mode 100644 Classes/Service/AbstractConfigurationFromTypoScriptService.php create mode 100644 Configuration/Services/Configuration.php create mode 100644 Configuration/Sets/Payments/config.yaml create mode 100644 Configuration/Sets/Payments/settings.yaml create mode 100644 Configuration/Sets/Shippings/config.yaml create mode 100644 Configuration/Sets/Shippings/settings.yaml create mode 100644 Configuration/Sets/TaxClass/config.yaml create mode 100644 Configuration/Sets/TaxClass/settings.yaml create mode 100644 Documentation/Changelog/12.0/Breaking-756-AddSiteSetConfigurationLoader.rst create mode 100644 Documentation/Changelog/12.0/Feature-756-AddSiteSetConfigurationLoader.rst rename Tests/Unit/{Service/AbstractConfigurationFromTypoScriptServiceTest.php => Configuration/Loader/TypoScript/AbstractConfigurationLoaderTest.php} (93%) rename Tests/Unit/{Service/TaxClassServiceTest.php => Configuration/Loader/TypoScript/TaxClassLoaderTest.php} (96%) diff --git a/Build/phpstan-baseline.neon b/Build/phpstan-baseline.neon index 4b33ed8a..626acd8d 100644 --- a/Build/phpstan-baseline.neon +++ b/Build/phpstan-baseline.neon @@ -1,5 +1,167 @@ parameters: ignoreErrors: + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\SiteSets\\AbstractConfigurationLoader\:\:getConfigurationsForType\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/SiteSets/AbstractConfigurationLoader.php + + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\SiteSets\\AbstractConfigurationLoader\:\:getCountryCodeFromPreset\(\) has parameter \$configuration with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/SiteSets/AbstractConfigurationLoader.php + + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\SiteSets\\AbstractConfigurationLoader\:\:getServices\(\) has parameter \$configurations with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/SiteSets/AbstractConfigurationLoader.php + + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\SiteSets\\AbstractConfigurationLoader\:\:getTypeZonesPluginSettings\(\) has parameter \$zoneSettings with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/SiteSets/AbstractConfigurationLoader.php + + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\SiteSets\\AbstractConfigurationLoader\:\:getTypeZonesPluginSettings\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/SiteSets/AbstractConfigurationLoader.php + + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\SpecialOptionsLoaderInterface\:\:getSpecialOptions\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/SpecialOptionsLoaderInterface.php + + - + message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#' + identifier: foreach.nonIterable + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php + + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\TypoScript\\AbstractConfigurationLoader\:\:getConfigurationsForType\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php + + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\TypoScript\\AbstractConfigurationLoader\:\:getCountryCodeFromPreset\(\) has parameter \$configuration with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php + + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\TypoScript\\AbstractConfigurationLoader\:\:getServices\(\) has parameter \$configurations with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php + + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\TypoScript\\AbstractConfigurationLoader\:\:getServices\(\) has parameter \$services with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php + + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\TypoScript\\AbstractConfigurationLoader\:\:getServices\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php + + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\TypoScript\\AbstractConfigurationLoader\:\:getTypeZonesPluginSettings\(\) has parameter \$zoneSettings with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php + + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\TypoScript\\AbstractConfigurationLoader\:\:getTypeZonesPluginSettings\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php + + - + message: '#^Parameter \#1 \$serviceKey of method Extcode\\Cart\\Domain\\Model\\Cart\\ServiceFactory\:\:getService\(\) expects int, mixed given\.$#' + identifier: argument.type + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php + + - + message: '#^Parameter \#2 \$serviceConfig of method Extcode\\Cart\\Domain\\Model\\Cart\\ServiceFactory\:\:getService\(\) expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php + + - + message: '#^Possibly invalid array key type mixed\.$#' + identifier: offsetAccess.invalidOffset + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php + + - + message: '#^Property Extcode\\Cart\\Configuration\\Loader\\TypoScript\\AbstractConfigurationLoader\:\:\$configurations type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php + + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\TypoScript\\PaymentMethodsLoader\:\:getPaymentMethods\(\) should return array\ but returns array\.$#' + identifier: return.type + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/PaymentMethodsLoader.php + + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\TypoScript\\ShippingMethodsLoader\:\:getShippingMethods\(\) should return array\ but returns array\.$#' + identifier: return.type + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/ShippingMethodsLoader.php + + - + message: '#^Method Extcode\\Cart\\Configuration\\Loader\\TypoScript\\SpecialOptionsLoader\:\:getSpecialOptions\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/SpecialOptionsLoader.php + + - + message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#' + identifier: foreach.nonIterable + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/TaxClassLoader.php + + - + message: '#^Parameter \#1 \$taxClassKey of method Extcode\\Cart\\Domain\\Model\\Cart\\TaxClassFactoryInterface\:\:getTaxClass\(\) expects int, mixed given\.$#' + identifier: argument.type + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/TaxClassLoader.php + + - + message: '#^Parameter \#2 \$array of function array_key_exists expects array, mixed given\.$#' + identifier: argument.type + count: 2 + path: ../Classes/Configuration/Loader/TypoScript/TaxClassLoader.php + + - + message: '#^Parameter \#2 \$taxClassValue of method Extcode\\Cart\\Domain\\Model\\Cart\\TaxClassFactoryInterface\:\:getTaxClass\(\) expects array, mixed given\.$#' + identifier: argument.type + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/TaxClassLoader.php + + - + message: '#^Possibly invalid array key type mixed\.$#' + identifier: offsetAccess.invalidOffset + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/TaxClassLoader.php + + - + message: '#^Property Extcode\\Cart\\Configuration\\Loader\\TypoScript\\TaxClassLoader\:\:\$settings type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Classes/Configuration/Loader/TypoScript/TaxClassLoader.php + - message: '#^Parameter \#3 \$view of class Extcode\\Cart\\Event\\View\\ModifyViewEvent constructor expects TYPO3Fluid\\Fluid\\View\\ViewInterface, TYPO3\\CMS\\Core\\View\\ViewInterface given\.$#' identifier: argument.type @@ -3564,138 +3726,6 @@ parameters: count: 1 path: ../Classes/Hooks/ItemsProcFunc.php - - - message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#' - identifier: foreach.nonIterable - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Cannot access offset ''code'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Cannot access offset ''countries'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 4 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Cannot access offset ''options'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Cannot access offset ''preset'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Cannot access offset ''settings'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Cannot access offset ''zones'' on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Cannot access offset mixed on mixed\.$#' - identifier: offsetAccess.nonOffsetAccessible - count: 2 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Method Extcode\\Cart\\Service\\AbstractConfigurationFromTypoScriptService\:\:getConfigurationsForType\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Method Extcode\\Cart\\Service\\AbstractConfigurationFromTypoScriptService\:\:getConfigurationsForType\(\) should return array\|null but returns mixed\.$#' - identifier: return.type - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Method Extcode\\Cart\\Service\\AbstractConfigurationFromTypoScriptService\:\:getServices\(\) has parameter \$configurations with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Method Extcode\\Cart\\Service\\AbstractConfigurationFromTypoScriptService\:\:getServices\(\) has parameter \$services with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Method Extcode\\Cart\\Service\\AbstractConfigurationFromTypoScriptService\:\:getServices\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Method Extcode\\Cart\\Service\\AbstractConfigurationFromTypoScriptService\:\:getTypeZonesPluginSettings\(\) has parameter \$zoneSettings with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Method Extcode\\Cart\\Service\\AbstractConfigurationFromTypoScriptService\:\:getTypeZonesPluginSettings\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Method Extcode\\Cart\\Service\\AbstractConfigurationFromTypoScriptService\:\:getTypeZonesPluginSettings\(\) should return array but returns mixed\.$#' - identifier: return.type - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Parameter \#1 \$serviceKey of method Extcode\\Cart\\Domain\\Model\\Cart\\ServiceFactory\:\:getService\(\) expects int, mixed given\.$#' - identifier: argument.type - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Parameter \#2 \$country of method Extcode\\Cart\\Service\\AbstractConfigurationFromTypoScriptService\:\:getTypeZonesPluginSettings\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Parameter \#2 \$serviceConfig of method Extcode\\Cart\\Domain\\Model\\Cart\\ServiceFactory\:\:getService\(\) expects array, mixed given\.$#' - identifier: argument.type - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Parameter \#2 \$string of static method TYPO3\\CMS\\Core\\Utility\\GeneralUtility\:\:trimExplode\(\) expects string, mixed given\.$#' - identifier: argument.type - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Possibly invalid array key type mixed\.$#' - identifier: offsetAccess.invalidOffset - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - - - message: '#^Property Extcode\\Cart\\Service\\AbstractConfigurationFromTypoScriptService\:\:\$configurations type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: ../Classes/Service/AbstractConfigurationFromTypoScriptService.php - - message: '#^Cannot access offset ''bccAddress'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible @@ -3870,12 +3900,6 @@ parameters: count: 1 path: ../Classes/Service/OrderItemCleanupService.php - - - message: '#^Method Extcode\\Cart\\Service\\PaymentMethodsFromTypoScriptService\:\:getPaymentMethods\(\) should return array\ but returns array\.$#' - identifier: return.type - count: 1 - path: ../Classes/Service/PaymentMethodsFromTypoScriptService.php - - message: '#^Binary operation "\." between mixed and string results in an error\.$#' identifier: binaryOp.invalid @@ -3900,60 +3924,6 @@ parameters: count: 1 path: ../Classes/Service/SessionHandler.php - - - message: '#^Method Extcode\\Cart\\Service\\ShippingMethodsFromTypoScriptService\:\:getShippingMethods\(\) should return array\ but returns array\.$#' - identifier: return.type - count: 1 - path: ../Classes/Service/ShippingMethodsFromTypoScriptService.php - - - - message: '#^Method Extcode\\Cart\\Service\\SpecialOptionsFromTypoScriptService\:\:getSpecialOptions\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: ../Classes/Service/SpecialOptionsFromTypoScriptService.php - - - - message: '#^Method Extcode\\Cart\\Service\\SpecialOptionsServiceInterface\:\:getSpecialOptions\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: ../Classes/Service/SpecialOptionsServiceInterface.php - - - - message: '#^Argument of an invalid type mixed supplied for foreach, only iterables are supported\.$#' - identifier: foreach.nonIterable - count: 1 - path: ../Classes/Service/TaxClassService.php - - - - message: '#^Parameter \#1 \$taxClassKey of method Extcode\\Cart\\Domain\\Model\\Cart\\TaxClassFactoryInterface\:\:getTaxClass\(\) expects int, mixed given\.$#' - identifier: argument.type - count: 1 - path: ../Classes/Service/TaxClassService.php - - - - message: '#^Parameter \#2 \$array of function array_key_exists expects array, mixed given\.$#' - identifier: argument.type - count: 2 - path: ../Classes/Service/TaxClassService.php - - - - message: '#^Parameter \#2 \$taxClassValue of method Extcode\\Cart\\Domain\\Model\\Cart\\TaxClassFactoryInterface\:\:getTaxClass\(\) expects array, mixed given\.$#' - identifier: argument.type - count: 1 - path: ../Classes/Service/TaxClassService.php - - - - message: '#^Possibly invalid array key type mixed\.$#' - identifier: offsetAccess.invalidOffset - count: 1 - path: ../Classes/Service/TaxClassService.php - - - - message: '#^Property Extcode\\Cart\\Service\\TaxClassService\:\:\$settings type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: ../Classes/Service/TaxClassService.php - - message: '#^Cannot access offset ''cart'' on mixed\.$#' identifier: offsetAccess.nonOffsetAccessible @@ -4069,7 +4039,7 @@ parameters: path: ../Classes/Utility/CartUtility.php - - message: '#^Parameter \#1 \$countryCode of method Extcode\\Cart\\Service\\TaxClassServiceInterface\:\:getTaxClasses\(\) expects string\|null, mixed given\.$#' + message: '#^Parameter \#1 \$countryCode of method Extcode\\Cart\\Configuration\\Loader\\TaxClassLoaderInterface\:\:getTaxClasses\(\) expects string\|null, mixed given\.$#' identifier: argument.type count: 1 path: ../Classes/Utility/CartUtility.php @@ -4237,7 +4207,19 @@ parameters: path: ../Classes/Utility/TemplateLayout.php - - message: '#^Binary operation "\." between ''Globals BE_USER was…'' and mixed results in an error\.$#' + message: '#^Binary operation "\." between ''\$GLOBALS\[\\''BE_USER\\''\]…'' and mixed results in an error\.$#' + identifier: binaryOp.invalid + count: 1 + path: ../Classes/Utility/Typo3GlobalsUtility.php + + - + message: '#^Binary operation "\." between ''\$GLOBALS\[\\''TYPO3…'' and mixed results in an error\.$#' + identifier: binaryOp.invalid + count: 1 + path: ../Classes/Utility/Typo3GlobalsUtility.php + + - + message: '#^Binary operation "\." between ''\$site was not of…'' and mixed results in an error\.$#' identifier: binaryOp.invalid count: 1 path: ../Classes/Utility/Typo3GlobalsUtility.php @@ -4614,18 +4596,6 @@ parameters: count: 1 path: ../Classes/ViewHelpers/Traversable/ExtractViewHelper.php - - - message: '#^Method Extcode\\Cart\\ViewHelpers\\Traversable\\ExtractViewHelper\:\:render\(\) return type has no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: ../Classes/ViewHelpers/Traversable/ExtractViewHelper.php - - - - message: '#^Method Extcode\\Cart\\ViewHelpers\\Traversable\\ExtractViewHelper\:\:render\(\) should return array but returns mixed\.$#' - identifier: return.type - count: 2 - path: ../Classes/ViewHelpers/Traversable/ExtractViewHelper.php - - message: '#^Parameter \#2 \$key of method Extcode\\Cart\\ViewHelpers\\Traversable\\ExtractViewHelper\:\:extractByKey\(\) expects string, mixed given\.$#' identifier: argument.type @@ -4950,6 +4920,18 @@ parameters: count: 1 path: ../Tests/Functional/EventListener/Mail/AttachmentFromTypoScriptTest.php + - + message: '#^Method Extcode\\Cart\\Tests\\Unit\\Configuration\\Loader\\TypoScript\\AbstractConfigurationLoaderTest\:\:createSubject\(\) has parameter \$configurations with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Tests/Unit/Configuration/Loader/TypoScript/AbstractConfigurationLoaderTest.php + + - + message: '#^Method Extcode\\Cart\\Tests\\Unit\\Configuration\\Loader\\TypoScript\\TaxClassLoaderTest\:\:createSubject\(\) has parameter \$settings with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue + count: 1 + path: ../Tests/Unit/Configuration/Loader/TypoScript/TaxClassLoaderTest.php + - message: '#^Cannot call method getMessage\(\) on mixed\.$#' identifier: method.nonObject @@ -5460,30 +5442,6 @@ parameters: count: 1 path: ../Tests/Unit/Domain/Model/Product/TagTraitTest.php - - - message: '#^Cannot call method getConfigurationsForType\(\) on mixed\.$#' - identifier: method.nonObject - count: 2 - path: ../Tests/Unit/Service/AbstractConfigurationFromTypoScriptServiceTest.php - - - - message: '#^Method Extcode\\Cart\\Tests\\Unit\\Service\\AbstractConfigurationFromTypoScriptServiceTest\:\:createSubject\(\) has no return type specified\.$#' - identifier: missingType.return - count: 1 - path: ../Tests/Unit/Service/AbstractConfigurationFromTypoScriptServiceTest.php - - - - message: '#^Method Extcode\\Cart\\Tests\\Unit\\Service\\AbstractConfigurationFromTypoScriptServiceTest\:\:createSubject\(\) has parameter \$configurations with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: ../Tests/Unit/Service/AbstractConfigurationFromTypoScriptServiceTest.php - - - - message: '#^Method Extcode\\Cart\\Tests\\Unit\\Service\\TaxClassServiceTest\:\:createSubject\(\) has parameter \$settings with no value type specified in iterable type array\.$#' - identifier: missingType.iterableValue - count: 1 - path: ../Tests/Unit/Service/TaxClassServiceTest.php - - message: '#^Method Extcode\\Cart\\Tests\\Unit\\Validation\\Validator\\EmptyValidatorTest\:\:getValidator\(\) has parameter \$options with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue diff --git a/Classes/Constants.php b/Classes/Configuration/Constants.php similarity index 93% rename from Classes/Constants.php rename to Classes/Configuration/Constants.php index e82b1a01..0364cb08 100644 --- a/Classes/Constants.php +++ b/Classes/Configuration/Constants.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Extcode\Cart; +namespace Extcode\Cart\Configuration; /* * This file is part of the package extcode/cart diff --git a/Classes/Service/CurrencyTranslationService.php b/Classes/Configuration/Loader/CurrencyTranslationLoader.php similarity index 78% rename from Classes/Service/CurrencyTranslationService.php rename to Classes/Configuration/Loader/CurrencyTranslationLoader.php index 526392f6..529eccb5 100644 --- a/Classes/Service/CurrencyTranslationService.php +++ b/Classes/Configuration/Loader/CurrencyTranslationLoader.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Extcode\Cart\Service; +namespace Extcode\Cart\Configuration\Loader; /* * This file is part of the package extcode/cart. @@ -11,7 +11,7 @@ * LICENSE file that was distributed with this source code. */ -class CurrencyTranslationService implements CurrencyTranslationServiceInterface +class CurrencyTranslationLoader implements CurrencyTranslationLoaderInterface { public function translatePrice(float $factor, ?float $price = null): ?float { diff --git a/Classes/Service/CurrencyTranslationServiceInterface.php b/Classes/Configuration/Loader/CurrencyTranslationLoaderInterface.php similarity index 83% rename from Classes/Service/CurrencyTranslationServiceInterface.php rename to Classes/Configuration/Loader/CurrencyTranslationLoaderInterface.php index f1ee3fe2..a236a7fb 100644 --- a/Classes/Service/CurrencyTranslationServiceInterface.php +++ b/Classes/Configuration/Loader/CurrencyTranslationLoaderInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Extcode\Cart\Service; +namespace Extcode\Cart\Configuration\Loader; /* * This file is part of the package extcode/cart. @@ -14,7 +14,7 @@ /** * @internal This class is marked internal and is not considered part of the public API. The interface will change in the next major version (v12.0.0). */ -interface CurrencyTranslationServiceInterface +interface CurrencyTranslationLoaderInterface { public function translatePrice(float $factor, ?float $price = null): ?float; } diff --git a/Classes/Service/PaymentMethodsServiceInterface.php b/Classes/Configuration/Loader/PaymentMethodsLoaderInterface.php similarity index 83% rename from Classes/Service/PaymentMethodsServiceInterface.php rename to Classes/Configuration/Loader/PaymentMethodsLoaderInterface.php index 64a59fea..cc892c44 100644 --- a/Classes/Service/PaymentMethodsServiceInterface.php +++ b/Classes/Configuration/Loader/PaymentMethodsLoaderInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Extcode\Cart\Service; +namespace Extcode\Cart\Configuration\Loader; /* * This file is part of the package extcode/cart. @@ -14,7 +14,7 @@ use Extcode\Cart\Domain\Model\Cart\Cart; use Extcode\Cart\Domain\Model\Cart\ServiceInterface; -interface PaymentMethodsServiceInterface +interface PaymentMethodsLoaderInterface { /** * @return ServiceInterface[] diff --git a/Classes/Service/ShippingMethodsServiceInterface.php b/Classes/Configuration/Loader/ShippingMethodsLoaderInterface.php similarity index 83% rename from Classes/Service/ShippingMethodsServiceInterface.php rename to Classes/Configuration/Loader/ShippingMethodsLoaderInterface.php index 882c0b09..f6cc33dd 100644 --- a/Classes/Service/ShippingMethodsServiceInterface.php +++ b/Classes/Configuration/Loader/ShippingMethodsLoaderInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Extcode\Cart\Service; +namespace Extcode\Cart\Configuration\Loader; /* * This file is part of the package extcode/cart. @@ -14,7 +14,7 @@ use Extcode\Cart\Domain\Model\Cart\Cart; use Extcode\Cart\Domain\Model\Cart\ServiceInterface; -interface ShippingMethodsServiceInterface +interface ShippingMethodsLoaderInterface { /** * @return ServiceInterface[] diff --git a/Classes/Configuration/Loader/SiteSets/AbstractConfigurationLoader.php b/Classes/Configuration/Loader/SiteSets/AbstractConfigurationLoader.php new file mode 100644 index 00000000..eb33e167 --- /dev/null +++ b/Classes/Configuration/Loader/SiteSets/AbstractConfigurationLoader.php @@ -0,0 +1,136 @@ +site = Typo3GlobalsUtility::getSiteFromTypo3Request(); + } + + /** + * @param array $services + * + * @return array + */ + public function getServices(?array $configurations, array $services, Cart $cart): array + { + if (is_array($configurations['options'] ?? null) === false) { + return $services; + } + + foreach ($configurations['options'] as $serviceKey => $serviceConfig) { + if (is_numeric($serviceKey) === false + || is_array($serviceConfig) === false + ) { + continue; + } + + $service = $this->serviceFactory->getService( + (int) $serviceKey, + $serviceConfig, + $configurations['preset'] == $serviceKey + ); + $service->setCart($cart); + + $services[$serviceKey] = $service; + } + + return $services; + } + + public function getConfigurationsForType(string $configurationType, ?string $country = null): ?array + { + $configurations = $this->site->getSettings()->getAll(); + if (is_array($configurations['extcode']) === false + || is_array($configurations['extcode'][$configurationType]) === false + ) { + return null; + } + + $configuration = $configurations['extcode'][$configurationType]; + + if (is_null($country)) { + $country = self::getCountryCodeFromPreset($configuration); + } + if (is_null($country)) { + return null; + } + + if (is_array($configuration['countries']) + && is_array($configuration['countries'][$country]) + ) { + return $configuration['countries'][$country]; + } + + if (!empty($configuration['zones']) + && is_array($configuration['zones']) + ) { + $zoneSetting = $this->getTypeZonesPluginSettings($configuration['zones'], $country); + if (!empty($zoneSetting)) { + return $zoneSetting; + } + } + + return $configuration; + } + + protected function getTypeZonesPluginSettings(array $zoneSettings, string $country): array + { + foreach ($zoneSettings as $zoneSetting) { + if (is_array($zoneSetting) === false + || is_string($zoneSetting['countries']) === false + ) { + continue; + } + $countriesInZones = GeneralUtility::trimExplode(',', $zoneSetting['countries'], true); + + if (in_array($country, $countriesInZones)) { + return $zoneSetting; + } + } + + return []; + } + + private static function getCountryCodeFromPreset(array $configuration): ?string + { + if (is_array($configuration['settings']) === false + || is_array($configuration['settings']['countries']) === false + || is_numeric($configuration['settings']['countries']['preset']) === false + ) { + return null; + } + + $preset = (int) $configuration['settings']['countries']['preset']; + + if (is_array($configuration['settings']['countries']['options']) === false + || is_array($configuration['settings']['countries']['options'][$preset]) === false + || is_string($configuration['settings']['countries']['options'][$preset]['code']) === false + ) { + return null; + } + + return $configuration['settings']['countries']['options'][$preset]['code']; + } +} diff --git a/Classes/Configuration/Loader/SiteSets/PaymentMethodsLoader.php b/Classes/Configuration/Loader/SiteSets/PaymentMethodsLoader.php new file mode 100644 index 00000000..99bb143f --- /dev/null +++ b/Classes/Configuration/Loader/SiteSets/PaymentMethodsLoader.php @@ -0,0 +1,27 @@ +getConfigurationsForType('cart-payments', $cart->getBillingCountry()); + + return $this->getServices($configurations, $services, $cart); + } +} diff --git a/Classes/Configuration/Loader/SiteSets/ShippingMethodsLoader.php b/Classes/Configuration/Loader/SiteSets/ShippingMethodsLoader.php new file mode 100644 index 00000000..79d758f3 --- /dev/null +++ b/Classes/Configuration/Loader/SiteSets/ShippingMethodsLoader.php @@ -0,0 +1,27 @@ +getConfigurationsForType('cart-shippings', $cart->getBillingCountry()); + + return $this->getServices($configurations, $services, $cart); + } +} diff --git a/Classes/Configuration/Loader/SiteSets/TaxClassLoader.php b/Classes/Configuration/Loader/SiteSets/TaxClassLoader.php new file mode 100644 index 00000000..d358437f --- /dev/null +++ b/Classes/Configuration/Loader/SiteSets/TaxClassLoader.php @@ -0,0 +1,72 @@ +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; + } +} diff --git a/Classes/Service/SpecialOptionsServiceInterface.php b/Classes/Configuration/Loader/SpecialOptionsLoaderInterface.php similarity index 79% rename from Classes/Service/SpecialOptionsServiceInterface.php rename to Classes/Configuration/Loader/SpecialOptionsLoaderInterface.php index 7adb4e9a..fd5cf0dd 100644 --- a/Classes/Service/SpecialOptionsServiceInterface.php +++ b/Classes/Configuration/Loader/SpecialOptionsLoaderInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Extcode\Cart\Service; +namespace Extcode\Cart\Configuration\Loader; /* * This file is part of the package extcode/cart. @@ -13,7 +13,7 @@ use Extcode\Cart\Domain\Model\Cart\Cart; -interface SpecialOptionsServiceInterface +interface SpecialOptionsLoaderInterface { public function getSpecialOptions(Cart $cart): array; } diff --git a/Classes/Service/TaxClassServiceInterface.php b/Classes/Configuration/Loader/TaxClassLoaderInterface.php similarity index 82% rename from Classes/Service/TaxClassServiceInterface.php rename to Classes/Configuration/Loader/TaxClassLoaderInterface.php index beb280c6..cd1024e4 100644 --- a/Classes/Service/TaxClassServiceInterface.php +++ b/Classes/Configuration/Loader/TaxClassLoaderInterface.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Extcode\Cart\Service; +namespace Extcode\Cart\Configuration\Loader; /* * This file is part of the package extcode/cart. @@ -13,7 +13,7 @@ use Extcode\Cart\Domain\Model\Cart\TaxClass; -interface TaxClassServiceInterface +interface TaxClassLoaderInterface { /** * @return TaxClass[] diff --git a/Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php b/Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php new file mode 100644 index 00000000..7c32ac95 --- /dev/null +++ b/Classes/Configuration/Loader/TypoScript/AbstractConfigurationLoader.php @@ -0,0 +1,122 @@ +configurations = $this->configurationManager->getConfiguration( + ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, + 'Cart' + ); + } + + public function getServices(?array $configurations, array $services, Cart $cart): array + { + if (empty($configurations['options'])) { + return $services; + } + + foreach ($configurations['options'] as $serviceKey => $serviceConfig) { + $service = $this->serviceFactory->getService($serviceKey, $serviceConfig, $configurations['preset'] == $serviceKey); + $service->setCart($cart); + + $services[$serviceKey] = $service; + } + + return $services; + } + + public function getConfigurationsForType(string $configurationType, ?string $country = null): ?array + { + if (is_array($this->configurations[$configurationType]) === false + ) { + return null; + } + + $configuration = $this->configurations[$configurationType]; + + if (is_null($country)) { + $country = self::getCountryCodeFromPreset($configuration); + } + if (is_null($country)) { + return null; + } + + if (!empty($configuration['countries']) + && is_array($configuration['countries']) + && is_array($configuration['countries'][$country]) + ) { + return $configuration['countries'][$country]; + } + + if (!empty($configuration['zones']) + && is_array($configuration['zones']) + ) { + $zoneSetting = $this->getTypeZonesPluginSettings($configuration['zones'], $country); + if (!empty($zoneSetting)) { + return $zoneSetting; + } + } + + return $configuration; + } + + protected function getTypeZonesPluginSettings(array $zoneSettings, string $country): array + { + foreach ($zoneSettings as $zoneSetting) { + if (is_array($zoneSetting) === false + || is_string($zoneSetting['countries']) === false + ) { + continue; + } + $countriesInZones = GeneralUtility::trimExplode(',', $zoneSetting['countries'], true); + + if (in_array($country, $countriesInZones)) { + return $zoneSetting; + } + } + + return []; + } + + private static function getCountryCodeFromPreset(array $configuration): ?string + { + if (is_array($configuration['settings']) === false + || is_array($configuration['settings']['countries']) === false + || is_numeric($configuration['settings']['countries']['preset']) === false + ) { + return null; + } + + $preset = (int) $configuration['settings']['countries']['preset']; + + if (is_array($configuration['settings']['countries']['options']) === false + || is_array($configuration['settings']['countries']['options'][$preset]) === false + || is_string($configuration['settings']['countries']['options'][$preset]['code']) === false + ) { + return null; + } + + return $configuration['settings']['countries']['options'][$preset]['code']; + } +} diff --git a/Classes/Service/PaymentMethodsFromTypoScriptService.php b/Classes/Configuration/Loader/TypoScript/PaymentMethodsLoader.php similarity index 68% rename from Classes/Service/PaymentMethodsFromTypoScriptService.php rename to Classes/Configuration/Loader/TypoScript/PaymentMethodsLoader.php index c083fa24..b926f801 100644 --- a/Classes/Service/PaymentMethodsFromTypoScriptService.php +++ b/Classes/Configuration/Loader/TypoScript/PaymentMethodsLoader.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Extcode\Cart\Service; +namespace Extcode\Cart\Configuration\Loader\TypoScript; /* * This file is part of the package extcode/cart. @@ -11,9 +11,10 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\Cart\Configuration\Loader\PaymentMethodsLoaderInterface; use Extcode\Cart\Domain\Model\Cart\Cart; -class PaymentMethodsFromTypoScriptService extends AbstractConfigurationFromTypoScriptService implements PaymentMethodsServiceInterface +final readonly class PaymentMethodsLoader extends AbstractConfigurationLoader implements PaymentMethodsLoaderInterface { public function getPaymentMethods(Cart $cart): array { diff --git a/Classes/Service/ShippingMethodsFromTypoScriptService.php b/Classes/Configuration/Loader/TypoScript/ShippingMethodsLoader.php similarity index 68% rename from Classes/Service/ShippingMethodsFromTypoScriptService.php rename to Classes/Configuration/Loader/TypoScript/ShippingMethodsLoader.php index 31b579e7..26525abd 100644 --- a/Classes/Service/ShippingMethodsFromTypoScriptService.php +++ b/Classes/Configuration/Loader/TypoScript/ShippingMethodsLoader.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Extcode\Cart\Service; +namespace Extcode\Cart\Configuration\Loader\TypoScript; /* * This file is part of the package extcode/cart. @@ -11,9 +11,10 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\Cart\Configuration\Loader\ShippingMethodsLoaderInterface; use Extcode\Cart\Domain\Model\Cart\Cart; -class ShippingMethodsFromTypoScriptService extends AbstractConfigurationFromTypoScriptService implements ShippingMethodsServiceInterface +final readonly class ShippingMethodsLoader extends AbstractConfigurationLoader implements ShippingMethodsLoaderInterface { public function getShippingMethods(Cart $cart): array { diff --git a/Classes/Service/SpecialOptionsFromTypoScriptService.php b/Classes/Configuration/Loader/TypoScript/SpecialOptionsLoader.php similarity index 68% rename from Classes/Service/SpecialOptionsFromTypoScriptService.php rename to Classes/Configuration/Loader/TypoScript/SpecialOptionsLoader.php index 53256181..e255e182 100644 --- a/Classes/Service/SpecialOptionsFromTypoScriptService.php +++ b/Classes/Configuration/Loader/TypoScript/SpecialOptionsLoader.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Extcode\Cart\Service; +namespace Extcode\Cart\Configuration\Loader\TypoScript; /* * This file is part of the package extcode/cart. @@ -11,9 +11,10 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\Cart\Configuration\Loader\SpecialOptionsLoaderInterface; use Extcode\Cart\Domain\Model\Cart\Cart; -class SpecialOptionsFromTypoScriptService extends AbstractConfigurationFromTypoScriptService implements SpecialOptionsServiceInterface +final readonly class SpecialOptionsLoader extends AbstractConfigurationLoader implements SpecialOptionsLoaderInterface { public function getSpecialOptions(Cart $cart): array { diff --git a/Classes/Service/TaxClassService.php b/Classes/Configuration/Loader/TypoScript/TaxClassLoader.php similarity index 84% rename from Classes/Service/TaxClassService.php rename to Classes/Configuration/Loader/TypoScript/TaxClassLoader.php index 8fdfb3b9..6fc34111 100644 --- a/Classes/Service/TaxClassService.php +++ b/Classes/Configuration/Loader/TypoScript/TaxClassLoader.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Extcode\Cart\Service; +namespace Extcode\Cart\Configuration\Loader\TypoScript; /* * This file is part of the package extcode/cart. @@ -11,18 +11,19 @@ * 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 TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; -final class TaxClassService implements TaxClassServiceInterface +final readonly class TaxClassLoader implements TaxClassLoaderInterface { private array $settings; public function __construct( - private readonly ConfigurationManagerInterface $configurationManager, - private readonly TaxClassFactoryInterface $taxClassFactory + private ConfigurationManagerInterface $configurationManager, + private TaxClassFactoryInterface $taxClassFactory ) { $this->settings = $this->configurationManager->getConfiguration( ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, diff --git a/Classes/Controller/Cart/ActionController.php b/Classes/Controller/Cart/ActionController.php index c889b1e3..a0d7a753 100644 --- a/Classes/Controller/Cart/ActionController.php +++ b/Classes/Controller/Cart/ActionController.php @@ -11,11 +11,11 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\Cart\Configuration\Loader\PaymentMethodsLoaderInterface; +use Extcode\Cart\Configuration\Loader\ShippingMethodsLoaderInterface; +use Extcode\Cart\Configuration\Loader\SpecialOptionsLoaderInterface; use Extcode\Cart\Domain\Model\Cart\Cart; -use Extcode\Cart\Service\PaymentMethodsServiceInterface; use Extcode\Cart\Service\SessionHandler; -use Extcode\Cart\Service\ShippingMethodsServiceInterface; -use Extcode\Cart\Service\SpecialOptionsServiceInterface; use Extcode\Cart\Utility\CartUtility; use TYPO3\CMS\Extbase\Configuration\ConfigurationManager; @@ -25,11 +25,11 @@ abstract class ActionController extends \Extcode\Cart\Controller\ActionControlle protected CartUtility $cartUtility; - protected PaymentMethodsServiceInterface $paymentMethodsService; + protected PaymentMethodsLoaderInterface $paymentMethodsLoader; - protected ShippingMethodsServiceInterface $shippingMethodsService; + protected ShippingMethodsLoaderInterface $shippingMethodsLoader; - protected SpecialOptionsServiceInterface $specialOptionsService; + protected SpecialOptionsLoaderInterface $specialOptionsLoader; protected array $configurations; @@ -51,19 +51,19 @@ public function injectCartUtility(CartUtility $cartUtility): void $this->cartUtility = $cartUtility; } - public function injectPaymentMethodsService(PaymentMethodsServiceInterface $paymentMethodsService): void + public function injectPaymentMethodsService(PaymentMethodsLoaderInterface $paymentMethodsLoader): void { - $this->paymentMethodsService = $paymentMethodsService; + $this->paymentMethodsLoader = $paymentMethodsLoader; } - public function injectShippingMethodsService(ShippingMethodsServiceInterface $shippingMethodsService): void + public function injectShippingMethodsService(ShippingMethodsLoaderInterface $shippingMethodsLoader): void { - $this->shippingMethodsService = $shippingMethodsService; + $this->shippingMethodsLoader = $shippingMethodsLoader; } - public function injectSpecialOptionsService(SpecialOptionsServiceInterface $specialOptionsService): void + public function injectSpecialOptionsService(SpecialOptionsLoaderInterface $specialOptionsLoader): void { - $this->specialOptionsService = $specialOptionsService; + $this->specialOptionsLoader = $specialOptionsLoader; } public function initializeAction(): void @@ -90,9 +90,9 @@ public function parseServicesAndAssignToView(): void protected function parseServices(): void { - $this->payments = $this->paymentMethodsService->getPaymentMethods($this->cart); - $this->shippings = $this->shippingMethodsService->getShippingMethods($this->cart); - $this->specials = $this->specialOptionsService->getSpecialOptions($this->cart); + $this->payments = $this->paymentMethodsLoader->getPaymentMethods($this->cart); + $this->shippings = $this->shippingMethodsLoader->getShippingMethods($this->cart); + $this->specials = $this->specialOptionsLoader->getSpecialOptions($this->cart); } protected function restoreSession(): void diff --git a/Classes/Controller/Cart/CountryController.php b/Classes/Controller/Cart/CountryController.php index 952e6d49..fc29e21e 100644 --- a/Classes/Controller/Cart/CountryController.php +++ b/Classes/Controller/Cart/CountryController.php @@ -4,7 +4,7 @@ namespace Extcode\Cart\Controller\Cart; -use Extcode\Cart\Service\TaxClassServiceInterface; +use Extcode\Cart\Configuration\Loader\TaxClassLoaderInterface; use Psr\Http\Message\ResponseInterface; /* @@ -16,7 +16,7 @@ class CountryController extends ActionController { public function __construct( - protected TaxClassServiceInterface $taxClassService + protected TaxClassLoaderInterface $taxClassLoader ) { } @@ -32,7 +32,7 @@ public function updateAction(): ResponseInterface $this->restoreSession(); - $taxClasses = $this->taxClassService->getTaxClasses($this->cart->getBillingCountry()); + $taxClasses = $this->taxClassLoader->getTaxClasses($this->cart->getBillingCountry()); $this->cart->setTaxClasses($taxClasses); $this->cart->reCalc(); diff --git a/Classes/Controller/Cart/OrderController.php b/Classes/Controller/Cart/OrderController.php index 85b4ecfc..77ba5b2a 100644 --- a/Classes/Controller/Cart/OrderController.php +++ b/Classes/Controller/Cart/OrderController.php @@ -122,7 +122,7 @@ public function createAction( $this->view->assign('orderItem', $orderItem); $paymentId = $this->cart->getPayment()->getId(); - $paymentSettings = $this->paymentMethodsService->getPaymentMethods($this->cart); + $paymentSettings = $this->paymentMethodsLoader->getPaymentMethods($this->cart); if (isset($paymentSettings['options'][$paymentId]['redirects']['success']['url'])) { return $this->redirectToUri( diff --git a/Classes/Controller/Cart/PaymentController.php b/Classes/Controller/Cart/PaymentController.php index 8c47f67e..14a8c381 100644 --- a/Classes/Controller/Cart/PaymentController.php +++ b/Classes/Controller/Cart/PaymentController.php @@ -51,7 +51,7 @@ private function updatePaymentInSession(int $paymentId): void { $this->restoreSession(); - $payments = $this->paymentMethodsService->getPaymentMethods($this->cart); + $payments = $this->paymentMethodsLoader->getPaymentMethods($this->cart); $payment = $payments[$paymentId] ?? null; if (is_null($payment) || $payment->isAvailable() === false) { diff --git a/Classes/Controller/Cart/ShippingController.php b/Classes/Controller/Cart/ShippingController.php index 7b00e3aa..7bbdcda0 100644 --- a/Classes/Controller/Cart/ShippingController.php +++ b/Classes/Controller/Cart/ShippingController.php @@ -51,7 +51,7 @@ private function updateShippingInSession(int $shippingId): void { $this->restoreSession(); - $shippings = $this->shippingMethodsService->getShippingMethods($this->cart); + $shippings = $this->shippingMethodsLoader->getShippingMethods($this->cart); $shipping = $shippings[$shippingId] ?? null; if (is_null($shipping) || $shipping->isAvailable() === false) { diff --git a/Classes/Domain/Model/Cart/Cart.php b/Classes/Domain/Model/Cart/Cart.php index b821d01b..b7300715 100644 --- a/Classes/Domain/Model/Cart/Cart.php +++ b/Classes/Domain/Model/Cart/Cart.php @@ -11,7 +11,7 @@ * LICENSE file that was distributed with this source code. */ -use Extcode\Cart\Service\CurrencyTranslationServiceInterface; +use Extcode\Cart\Configuration\Loader\CurrencyTranslationLoaderInterface; use InvalidArgumentException; use LogicException; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -71,7 +71,7 @@ class Cart implements AdditionalDataInterface protected string $shippingCountry = ''; - private ?CurrencyTranslationServiceInterface $currencyTranslationService = null; + private ?CurrencyTranslationLoaderInterface $currencyTranslationLoader = null; public function __construct( protected array $taxClasses, @@ -80,7 +80,7 @@ public function __construct( protected string $currencySign = '€', protected float $currencyTranslation = 1.00 ) { - $this->currencyTranslationService = GeneralUtility::makeInstance(CurrencyTranslationServiceInterface::class); + $this->currencyTranslationLoader = GeneralUtility::makeInstance(CurrencyTranslationLoaderInterface::class); $this->net = 0.0; $this->gross = 0.0; @@ -982,11 +982,11 @@ public function setCurrencySign(string $currencySign): void public function translatePrice(?float $price = null): ?float { - if (is_null($this->currencyTranslationService)) { - $this->currencyTranslationService = GeneralUtility::makeInstance(CurrencyTranslationServiceInterface::class); + if (is_null($this->currencyTranslationLoader)) { + $this->currencyTranslationLoader = GeneralUtility::makeInstance(CurrencyTranslationLoaderInterface::class); } - return $this->currencyTranslationService->translatePrice($this->getCurrencyTranslation(), $price); + return $this->currencyTranslationLoader->translatePrice($this->getCurrencyTranslation(), $price); } protected function areCouponsCombinable(): bool diff --git a/Classes/EventListener/Order/Finish/ClearCart.php b/Classes/EventListener/Order/Finish/ClearCart.php index 9317d0b9..0ec596b5 100644 --- a/Classes/EventListener/Order/Finish/ClearCart.php +++ b/Classes/EventListener/Order/Finish/ClearCart.php @@ -11,10 +11,10 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\Cart\Configuration\Loader\PaymentMethodsLoaderInterface; use Extcode\Cart\Domain\Model\Order\BillingAddress; use Extcode\Cart\Domain\Model\Order\ShippingAddress; use Extcode\Cart\Event\Order\EventInterface; -use Extcode\Cart\Service\PaymentMethodsServiceInterface; use Extcode\Cart\Service\SessionHandler; use Extcode\Cart\Utility\CartUtility; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -23,7 +23,7 @@ class ClearCart { public function __construct( protected readonly CartUtility $cartUtility, - protected readonly PaymentMethodsServiceInterface $paymentMethodsService, + protected readonly PaymentMethodsLoaderInterface $paymentMethodsLoader, protected readonly SessionHandler $sessionHandler ) { } @@ -34,7 +34,7 @@ public function __invoke(EventInterface $event): void $settings = $event->getSettings(); $paymentId = $cart->getPayment()->getId(); - $paymentSettings = $this->paymentMethodsService->getPaymentMethods($cart); + $paymentSettings = $this->paymentMethodsLoader->getPaymentMethods($cart); if ((int) ($paymentSettings['options'][$paymentId]['preventClearCart'] ?? 0) != 1) { $cartPid = $settings['settings']['cart']['pid']; diff --git a/Classes/EventListener/Order/Finish/Email.php b/Classes/EventListener/Order/Finish/Email.php index f918cc69..07f9ff52 100644 --- a/Classes/EventListener/Order/Finish/Email.php +++ b/Classes/EventListener/Order/Finish/Email.php @@ -11,16 +11,16 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\Cart\Configuration\Loader\PaymentMethodsLoaderInterface; use Extcode\Cart\Domain\Model\Cart\Cart; use Extcode\Cart\Domain\Model\Order\Item; use Extcode\Cart\Event\Order\EventInterface; use Extcode\Cart\Service\MailHandler; -use Extcode\Cart\Service\PaymentMethodsServiceInterface; class Email { public function __construct( - private readonly PaymentMethodsServiceInterface $paymentMethodsService, + private readonly PaymentMethodsLoaderInterface $paymentMethodsLoader, private readonly MailHandler $mailHandler, ) { } @@ -29,7 +29,7 @@ public function __invoke(EventInterface $event): void { $orderItem = $event->getOrderItem(); - $paymentMethods = $this->paymentMethodsService->getPaymentMethods($event->getCart()); + $paymentMethods = $this->paymentMethodsLoader->getPaymentMethods($event->getCart()); $paymentId = $orderItem->getPayment()->getServiceId(); $paymentMethod = $paymentMethods[$paymentId] ?? null; diff --git a/Classes/Service/AbstractConfigurationFromTypoScriptService.php b/Classes/Service/AbstractConfigurationFromTypoScriptService.php deleted file mode 100644 index d3c02bfb..00000000 --- a/Classes/Service/AbstractConfigurationFromTypoScriptService.php +++ /dev/null @@ -1,97 +0,0 @@ -configurations = $this->configurationManager->getConfiguration( - ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK, - 'Cart' - ); - } - - public function getServices(?array $configurations, array $services, Cart $cart): array - { - if (empty($configurations['options'])) { - return $services; - } - - foreach ($configurations['options'] as $serviceKey => $serviceConfig) { - $service = $this->serviceFactory->getService($serviceKey, $serviceConfig, $configurations['preset'] == $serviceKey); - $service->setCart($cart); - - $services[$serviceKey] = $service; - } - - return $services; - } - - public function getConfigurationsForType(string $configurationType, ?string $country = null): ?array - { - if (!isset($this->configurations[$configurationType])) { - return null; - } - - $configuration = $this->configurations[$configurationType]; - - if (is_null($country)) { - if (isset($configuration['settings']['countries']['options'][$configuration['settings']['countries']['preset']]['code'])) { - $country = $configuration['settings']['countries']['options'][$configuration['settings']['countries']['preset']]['code']; - } - } - - if (isset($country)) { - if ( - !empty($configuration['countries']) - && !empty($configuration['countries'][$country]) - && is_array($configuration['countries'][$country]) - ) { - return $configuration['countries'][$country]; - } - - if (!empty($configuration['zones']) && is_array($configuration['zones'])) { - $zoneSetting = $this->getTypeZonesPluginSettings($configuration['zones'], $country); - if (!empty($zoneSetting)) { - return $zoneSetting; - } - } - - return $configuration; - } - - return null; - } - - protected function getTypeZonesPluginSettings(array $zoneSettings, string $country): array - { - foreach ($zoneSettings as $zoneSetting) { - $countriesInZones = GeneralUtility::trimExplode(',', $zoneSetting['countries'], true); - - if (in_array($country, $countriesInZones)) { - return $zoneSetting; - } - } - - return []; - } -} diff --git a/Classes/Utility/CartUtility.php b/Classes/Utility/CartUtility.php index 0c573b61..f260be8f 100644 --- a/Classes/Utility/CartUtility.php +++ b/Classes/Utility/CartUtility.php @@ -11,12 +11,12 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\Cart\Configuration\Loader\PaymentMethodsLoaderInterface; +use Extcode\Cart\Configuration\Loader\ShippingMethodsLoaderInterface; +use Extcode\Cart\Configuration\Loader\TaxClassLoaderInterface; use Extcode\Cart\Domain\Model\Cart\Cart; use Extcode\Cart\Event\Cart\UpdateCountryEvent; -use Extcode\Cart\Service\PaymentMethodsServiceInterface; use Extcode\Cart\Service\SessionHandler; -use Extcode\Cart\Service\ShippingMethodsServiceInterface; -use Extcode\Cart\Service\TaxClassServiceInterface; use InvalidArgumentException; use Psr\EventDispatcher\EventDispatcherInterface; use TYPO3\CMS\Core\Utility\GeneralUtility; @@ -26,9 +26,9 @@ class CartUtility { public function __construct( protected EventDispatcherInterface $eventDispatcher, - protected PaymentMethodsServiceInterface $paymentMethodsService, - protected ShippingMethodsServiceInterface $shippingMethodsService, - protected TaxClassServiceInterface $taxClassService, + protected PaymentMethodsLoaderInterface $paymentMethodsLoader, + protected ShippingMethodsLoaderInterface $shippingMethodsLoader, + protected TaxClassLoaderInterface $taxClassLoader, protected SessionHandler $sessionHandler ) { } @@ -64,7 +64,7 @@ public function updateService(Cart $cart): void { $cart->getPayment()->setCart($cart); if (!$cart->getPayment()->isAvailable()) { - $payments = $this->paymentMethodsService->getPaymentMethods($cart); + $payments = $this->paymentMethodsLoader->getPaymentMethods($cart); $fallBackId = $cart->getPayment()->getFallBackId(); if ($fallBackId) { $payment = $this->getServiceById($payments, $fallBackId); @@ -74,7 +74,7 @@ public function updateService(Cart $cart): void $cart->getShipping()->setCart($cart); if (!$cart->getShipping()->isAvailable()) { - $shippings = $this->shippingMethodsService->getShippingMethods($cart); + $shippings = $this->shippingMethodsLoader->getShippingMethods($cart); $fallBackId = $cart->getShipping()->getFallBackId(); if ($fallBackId) { $shipping = $this->getServiceById($shippings, $fallBackId); @@ -105,7 +105,7 @@ public function getNewCart(array $configurations): Cart $defaultCountry = $configurations['settings']['countries']['options'][$configurations['settings']['countries']['preset']]['code']; - $taxClasses = $this->taxClassService->getTaxClasses($defaultCountry); + $taxClasses = $this->taxClassLoader->getTaxClasses($defaultCountry); $cart = GeneralUtility::makeInstance( Cart::class, @@ -130,7 +130,7 @@ public function getNewCart(array $configurations): Cart protected function setShipping(Cart $cart): void { - $shippings = $this->shippingMethodsService->getShippingMethods($cart); + $shippings = $this->shippingMethodsLoader->getShippingMethods($cart); foreach ($shippings as $shipping) { if ($shipping->isPreset()) { @@ -146,7 +146,7 @@ protected function setShipping(Cart $cart): void protected function setPayment(Cart $cart): void { - $payments = $this->paymentMethodsService->getPaymentMethods($cart); + $payments = $this->paymentMethodsLoader->getPaymentMethods($cart); foreach ($payments as $payment) { if ($payment->isPreset()) { diff --git a/Classes/Utility/Typo3GlobalsUtility.php b/Classes/Utility/Typo3GlobalsUtility.php index a8337fbe..a6cd0da8 100644 --- a/Classes/Utility/Typo3GlobalsUtility.php +++ b/Classes/Utility/Typo3GlobalsUtility.php @@ -11,7 +11,9 @@ * LICENSE file that was distributed with this source code. */ +use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Authentication\BackendUserAuthentication; +use TYPO3\CMS\Core\Site\Entity\Site; use TypeError; final readonly class Typo3GlobalsUtility @@ -20,10 +22,34 @@ public static function getTypo3BackendUser(): BackendUserAuthentication { $user = $GLOBALS['BE_USER'] ?? null; - if (!$user instanceof BackendUserAuthentication) { - throw new TypeError('Globals BE_USER was not of type BackendUserAuthentication, got: ' . $user, 1769004660); + if (($user instanceof BackendUserAuthentication) === false) { + throw new TypeError('$GLOBALS[\'BE_USER\'] was not of type BackendUserAuthentication, got: ' . $user, 1769004660); } return $user; } + + public static function getTypo3Request(): ServerRequestInterface + { + $request = $GLOBALS['TYPO3_REQUEST'] ?? null; + + if (($request instanceof ServerRequestInterface) === false) { + throw new TypeError('$GLOBALS[\'TYPO3_REQUEST\'] was not of type ServerRequestInterface, got: ' . $request, 1776420280); + } + + return $request; + } + + public static function getSiteFromTypo3Request(): Site + { + $request = self::getTypo3Request(); + + $site = $request->getAttribute('site'); + + if (($site instanceof Site) === false) { + throw new TypeError('$site was not of type Site, got: ' . $site, 1776450259); + } + + return $site; + } } diff --git a/Classes/ViewHelpers/Traversable/ExtractViewHelper.php b/Classes/ViewHelpers/Traversable/ExtractViewHelper.php index ed209666..bc8baf7d 100644 --- a/Classes/ViewHelpers/Traversable/ExtractViewHelper.php +++ b/Classes/ViewHelpers/Traversable/ExtractViewHelper.php @@ -41,7 +41,7 @@ public function initializeArguments(): void ); } - public function render(): array + public function render(): mixed { $key = $this->arguments['key']; $content = $this->arguments['content']; diff --git a/Classes/Widgets/Provider/OrdersPerDayProvider.php b/Classes/Widgets/Provider/OrdersPerDayProvider.php index e6187cf9..ee250114 100644 --- a/Classes/Widgets/Provider/OrdersPerDayProvider.php +++ b/Classes/Widgets/Provider/OrdersPerDayProvider.php @@ -4,7 +4,7 @@ namespace Extcode\Cart\Widgets\Provider; -use Extcode\Cart\Constants; +use Extcode\Cart\Configuration\Constants; use TYPO3\CMS\Core\Database\Connection; use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Localization\LanguageService; diff --git a/Classes/Widgets/Provider/TurnoverPerDayProvider.php b/Classes/Widgets/Provider/TurnoverPerDayProvider.php index d2df542e..ee13e873 100644 --- a/Classes/Widgets/Provider/TurnoverPerDayProvider.php +++ b/Classes/Widgets/Provider/TurnoverPerDayProvider.php @@ -4,7 +4,7 @@ namespace Extcode\Cart\Widgets\Provider; -use Extcode\Cart\Constants; +use Extcode\Cart\Configuration\Constants; use TYPO3\CMS\Core\Database\Query\QueryBuilder; use TYPO3\CMS\Core\Localization\LanguageService; use TYPO3\CMS\Core\Localization\LanguageServiceFactory; diff --git a/Configuration/Services.php b/Configuration/Services.php index 37274629..3841a171 100644 --- a/Configuration/Services.php +++ b/Configuration/Services.php @@ -34,5 +34,6 @@ ; } + $containerConfigurator->import('Services/Configuration.php'); $containerConfigurator->import('Services/ConsoleCommands.php'); }; diff --git a/Configuration/Services.yaml b/Configuration/Services.yaml index 36b69b7c..9d796d79 100644 --- a/Configuration/Services.yaml +++ b/Configuration/Services.yaml @@ -138,22 +138,6 @@ services: identifier: 'cart--order--update--log-service-update' event: Extcode\Cart\Event\Order\UpdateServiceEvent - Extcode\Cart\Service\CurrencyTranslationServiceInterface: - alias: Extcode\Cart\Service\CurrencyTranslationService - public: true - - Extcode\Cart\Service\PaymentMethodsFromTypoScriptService: - public: true - - Extcode\Cart\Service\ShippingMethodsFromTypoScriptService: - public: true - - Extcode\Cart\Service\SpecialOptionsFromTypoScriptService: - public: true - - Extcode\Cart\Service\TaxClassService: - public: true - querybuilder.tx_cart_domain_model_order_item: class: 'TYPO3\CMS\Core\Database\Query\QueryBuilder' factory: diff --git a/Configuration/Services/Configuration.php b/Configuration/Services/Configuration.php new file mode 100644 index 00000000..7c7a1324 --- /dev/null +++ b/Configuration/Services/Configuration.php @@ -0,0 +1,86 @@ +services() + ; + + $services + ->alias( + CurrencyTranslationLoaderInterface::class, + CurrencyTranslationLoader::class + ) + ; + + $services + ->alias( + PaymentMethodsLoaderInterface::class, + TypoScriptPaymentMethodsLoader::class + ) + ; + + $services + ->set(SiteSetsPaymentMethodsLoader::class) + ->public() + ; + + $services + ->set(TypoScriptPaymentMethodsLoader::class) + ->public() + ; + + $services + ->alias( + ShippingMethodsLoaderInterface::class, + TypoScriptShippingMethodsLoader::class + ) + ; + + $services + ->set(SiteSetsShippingMethodsLoader::class) + ->public() + ; + + $services + ->set(TypoScriptShippingMethodsLoader::class) + ->public() + ; + + $services + ->set(SpecialOptionsLoader::class) + ->public() + ; + + $services + ->alias( + TaxClassLoaderInterface::class, + TypoScriptTaxClassLoader::class + ) + ; + + $services + ->set(SiteSetsTaxClassLoader::class) + ->public() + ; + + $services + ->set(TypoScriptTaxClassLoader::class) + ->public() + ; +}; diff --git a/Configuration/Sets/Payments/config.yaml b/Configuration/Sets/Payments/config.yaml new file mode 100644 index 00000000..be79c0c2 --- /dev/null +++ b/Configuration/Sets/Payments/config.yaml @@ -0,0 +1,2 @@ +name: extcode/cart-payments +label: 'Cart Payment: Vorkasse' diff --git a/Configuration/Sets/Payments/settings.yaml b/Configuration/Sets/Payments/settings.yaml new file mode 100644 index 00000000..46b2f776 --- /dev/null +++ b/Configuration/Sets/Payments/settings.yaml @@ -0,0 +1,13 @@ +extcode: + cart-payments: + countries: + de: + preset: 1 + options: + 1: + title: 'Vorkasse' + extra: 0.0 + taxClassId: 1 + status: 'open' + at: .de + ch: .de diff --git a/Configuration/Sets/Shippings/config.yaml b/Configuration/Sets/Shippings/config.yaml new file mode 100644 index 00000000..6f60d14d --- /dev/null +++ b/Configuration/Sets/Shippings/config.yaml @@ -0,0 +1,2 @@ +name: extcode/cart-shippings +label: 'Cart Shippings: Standard' diff --git a/Configuration/Sets/Shippings/settings.yaml b/Configuration/Sets/Shippings/settings.yaml new file mode 100644 index 00000000..b5d12f37 --- /dev/null +++ b/Configuration/Sets/Shippings/settings.yaml @@ -0,0 +1,13 @@ +extcode: + cart-shippings: + countries: + de: + preset: 1 + options: + 1: + title: 'Standard' + extra: 7.95 + taxClassId: 1 + status: 'open' + at: .de + ch: .de \ No newline at end of file diff --git a/Configuration/Sets/TaxClass/config.yaml b/Configuration/Sets/TaxClass/config.yaml new file mode 100644 index 00000000..2f543aad --- /dev/null +++ b/Configuration/Sets/TaxClass/config.yaml @@ -0,0 +1,2 @@ +name: extcode/cart-taxclasses +label: 'Cart Tax Classes' diff --git a/Configuration/Sets/TaxClass/settings.yaml b/Configuration/Sets/TaxClass/settings.yaml new file mode 100644 index 00000000..7ebb7ac9 --- /dev/null +++ b/Configuration/Sets/TaxClass/settings.yaml @@ -0,0 +1,14 @@ +extcode: + cart-taxclasses: + 1: + value: 19 + calc: 0.19 + name: 'normal' + 2: + value: 7 + calc: 0.07 + name: 'reduced' + 3: + value: 0 + calc: 0.00 + name: 'free' diff --git a/Configuration/TCA/Overrides/pages.php b/Configuration/TCA/Overrides/pages.php index 643b2959..6e09eb02 100644 --- a/Configuration/TCA/Overrides/pages.php +++ b/Configuration/TCA/Overrides/pages.php @@ -2,7 +2,7 @@ declare(strict_types=1); -use Extcode\Cart\Constants; +use Extcode\Cart\Configuration\Constants; use TYPO3\CMS\Core\Domain\Repository\PageRepository; use TYPO3\CMS\Core\Utility\ArrayUtility; diff --git a/Configuration/TypoScript/setup.typoscript b/Configuration/TypoScript/setup.typoscript index 2cb7c6a3..c83f7456 100755 --- a/Configuration/TypoScript/setup.typoscript +++ b/Configuration/TypoScript/setup.typoscript @@ -120,8 +120,8 @@ plugin.tx_cart { } } -@import 'EXT:cart/Configuration/TypoScript/Settings/*.typoscript -@import 'EXT:cart/Configuration/TypoScript/TaxClasses/setup.typoscript +@import 'EXT:cart/Configuration/TypoScript/Settings/*.typoscript' +@import 'EXT:cart/Configuration/TypoScript/TaxClasses/setup.typoscript' @import 'EXT:cart/Configuration/TypoScript/Payments/setup.typoscript @import 'EXT:cart/Configuration/TypoScript/Shippings/setup.typoscript diff --git a/Documentation/Changelog/12.0/Breaking-756-AddSiteSetConfigurationLoader.rst b/Documentation/Changelog/12.0/Breaking-756-AddSiteSetConfigurationLoader.rst new file mode 100644 index 00000000..6fa4cbfb --- /dev/null +++ b/Documentation/Changelog/12.0/Breaking-756-AddSiteSetConfigurationLoader.rst @@ -0,0 +1,46 @@ +.. include:: ../../Includes.rst.txt + +================================================== +Breaking: #756 - Add Site Set Configuration Loader +================================================== + +See `Issue 756 `__ + +Description +=========== + +Regarding to the new feature configuring cart by site sets the +code was restructured and the services to load configurations +moved to `Configuration/Loader`. + +The interfaces was moved form `Service` to `Configuration`: + +`Classes/Service/CurrencyTranslationServiceInterface.php` => `Classes/Configuration/Loader/CurrencyTranslationLoaderInterface.php` +`Classes/Service/TaxClassServiceInterface.php` => `Classes/Configuration/Loader/TaxClassLoaderInterface.php` +`Classes/Service/PaymentMethodsServiceInterface.php` => `Classes/Configuration/Loader/PaymentMethodsLoaderInterface.php` +`Classes/Service/ShippingMethodsServiceInterface.php` => `Classes/Configuration/Loader/ShippingMethodsLoaderInterface.php` +`Classes/Service/SpecialOptionsServiceInterface.php` => `Classes/Configuration/Loader/SpecialOptionsLoaderInterface.php` + +The classes was moved form `Service` to `Configuration` or `Configuration/TypoScript`: + +`Classes/Service/CurrencyTranslationService.php` => `Classes/Configuration/Loader/CurrencyTranslationLoader.php` +`Classes/Service/PaymentMethodsFromTypoScriptService.php` => `Classes/Configuration/Loader/TypoScript/PaymentMethodsLoader.php` +`Classes/Service/ShippingMethodsFromTypoScriptService.php` => `Classes/Configuration/Loader/TypoScript/ShippingMethodsLoader.php` +`Classes/Service/SpecialOptionsFromTypoScriptService.php` => `Classes/Configuration/Loader/TypoScript/SpecialOptionsLoader.php` +`Classes/Service/TaxClassService.php` => `Classes/Configuration/Loader/TypoScript/TaxClassLoader.php` + +Affected Installations +====================== + +All installations implementing one of the service interfaces or extending one of the +services. + +Migration +========= + +Use interfaces from new namespace. + +.. CAUTION:: + All configuration loaders are now final. If your own configuration loader only extends the + service, you have to copy the code from the final configuration loader class and add your + changes in your own class. Add or update an alias to your own configuration loader class. diff --git a/Documentation/Changelog/12.0/Feature-756-AddSiteSetConfigurationLoader.rst b/Documentation/Changelog/12.0/Feature-756-AddSiteSetConfigurationLoader.rst new file mode 100644 index 00000000..21ab8ee0 --- /dev/null +++ b/Documentation/Changelog/12.0/Feature-756-AddSiteSetConfigurationLoader.rst @@ -0,0 +1,41 @@ +.. include:: ../../Includes.rst.txt + +================================================= +Feature: #756 - Add Site Set Configuration Loader +================================================= + +See `Issue 756 `__ + +Description +=========== + +If you want to switch to the Site Sets configuration loader, +you have to alias the new classes. + +You can decide to move some configuration to Site Sets and +leave others in TypoScript + +.. code-block:: php + + $services + ->alias( + \Extcode\Cart\Configuration\Loader\PaymentMethodsLoaderInterface::class, + \Extcode\Cart\Configuration\Loader\SiteSets\PaymentMethodsLoader::class + ) + ; + +.. code-block:: yaml + + services: + Extcode\Cart\Configuration\Loader\PaymentMethodsLoaderInterface: + alias: Extcode\Cart\Configuration\Loader\SiteSets\PaymentMethodsLoader + +.. NOTE:: + Not all configurations can be moved to Site Sets with the 12.0.0 release. + Others will follow in the near future with a minor release. + +Impact +====== + +No direct impact. + diff --git a/Documentation/Changelog/12.0/Index.rst b/Documentation/Changelog/12.0/Index.rst index dec9057d..f71bf7c3 100644 --- a/Documentation/Changelog/12.0/Index.rst +++ b/Documentation/Changelog/12.0/Index.rst @@ -9,6 +9,16 @@ :local: :depth: 1 +Breaking +-------- + +.. toctree:: + :maxdepth: 1 + :titlesonly: + :glob: + + Breaking-* + Features -------- diff --git a/Tests/Unit/Service/AbstractConfigurationFromTypoScriptServiceTest.php b/Tests/Unit/Configuration/Loader/TypoScript/AbstractConfigurationLoaderTest.php similarity index 93% rename from Tests/Unit/Service/AbstractConfigurationFromTypoScriptServiceTest.php rename to Tests/Unit/Configuration/Loader/TypoScript/AbstractConfigurationLoaderTest.php index c20668d4..c43844e9 100644 --- a/Tests/Unit/Service/AbstractConfigurationFromTypoScriptServiceTest.php +++ b/Tests/Unit/Configuration/Loader/TypoScript/AbstractConfigurationLoaderTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Extcode\Cart\Tests\Unit\Service; +namespace Extcode\Cart\Tests\Unit\Configuration\Loader\TypoScript; /* * This file is part of the package extcode/cart. @@ -11,15 +11,15 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\Cart\Configuration\Loader\TypoScript\AbstractConfigurationLoader; use Extcode\Cart\Domain\Model\Cart\ServiceFactory; -use Extcode\Cart\Service\AbstractConfigurationFromTypoScriptService; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; -#[CoversClass(AbstractConfigurationFromTypoScriptService::class)] -class AbstractConfigurationFromTypoScriptServiceTest extends UnitTestCase +#[CoversClass(AbstractConfigurationLoader::class)] +class AbstractConfigurationLoaderTest extends UnitTestCase { #[Test] public function getTypePluginSettingsReturnsTypeCountrySettings(): void @@ -180,11 +180,15 @@ public function getTypeZonePluginSettingsReturnsTypeZoneSettings(): void ); } - private static function createSubject(array $configurations) + private static function createSubject(array $configurations): AbstractConfigurationLoader { $configurationManager = self::createStub(ConfigurationManagerInterface::class); $configurationManager->method('getConfiguration')->willReturn($configurations); - return new class ($configurationManager, new ServiceFactory()) extends AbstractConfigurationFromTypoScriptService {}; + return new TestConfigurationLoader($configurationManager, new ServiceFactory()); } } + +readonly class TestConfigurationLoader extends AbstractConfigurationLoader +{ +} diff --git a/Tests/Unit/Service/TaxClassServiceTest.php b/Tests/Unit/Configuration/Loader/TypoScript/TaxClassLoaderTest.php similarity index 96% rename from Tests/Unit/Service/TaxClassServiceTest.php rename to Tests/Unit/Configuration/Loader/TypoScript/TaxClassLoaderTest.php index 9f46259f..bfbb58b9 100644 --- a/Tests/Unit/Service/TaxClassServiceTest.php +++ b/Tests/Unit/Configuration/Loader/TypoScript/TaxClassLoaderTest.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Extcode\Cart\Tests\Unit\Service; +namespace Extcode\Cart\Tests\Unit\Configuration\Loader\TypoScript; /* * This file is part of the package extcode/cart. @@ -11,17 +11,17 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\Cart\Configuration\Loader\TypoScript\TaxClassLoader; use Extcode\Cart\Domain\Model\Cart\TaxClass; use Extcode\Cart\Domain\Model\Cart\TaxClassFactory; -use Extcode\Cart\Service\TaxClassService; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use Psr\Log\LoggerInterface; use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; -#[CoversClass(TaxClassService::class)] -class TaxClassServiceTest extends UnitTestCase +#[CoversClass(TaxClassLoader::class)] +class TaxClassLoaderTest extends UnitTestCase { #[Test] public function parsingTaxClassesFromTypoScriptWithoutCountryCodeReturnsDirectlyConfiguredArrayOfTaxClasses(): void @@ -237,12 +237,12 @@ public function parsingTaxClassesFromTypoScriptWithIntegerZeroAsCalcIsValid(): v ); } - private static function createSubject(array $settings): TaxClassService + private static function createSubject(array $settings): TaxClassLoader { $configurationManager = self::createStub(ConfigurationManagerInterface::class); $configurationManager->method('getConfiguration')->willReturn($settings); - return new TaxClassService( + return new TaxClassLoader( $configurationManager, new TaxClassFactory( self::createStub(LoggerInterface::class) diff --git a/Tests/Unit/ConstantsTest.php b/Tests/Unit/ConstantsTest.php index c9046e45..4cd3dc84 100644 --- a/Tests/Unit/ConstantsTest.php +++ b/Tests/Unit/ConstantsTest.php @@ -4,7 +4,7 @@ namespace Extcode\Cart\Tests\Unit; -use Extcode\Cart\Constants; +use Extcode\Cart\Configuration\Constants; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use TYPO3\TestingFramework\Core\Unit\UnitTestCase; diff --git a/Tests/Unit/Domain/Model/Cart/CartCouponFixTest.php b/Tests/Unit/Domain/Model/Cart/CartCouponFixTest.php index c6b5c423..288e2928 100644 --- a/Tests/Unit/Domain/Model/Cart/CartCouponFixTest.php +++ b/Tests/Unit/Domain/Model/Cart/CartCouponFixTest.php @@ -11,11 +11,11 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\Cart\Configuration\Loader\CurrencyTranslationLoader; +use Extcode\Cart\Configuration\Loader\CurrencyTranslationLoaderInterface; use Extcode\Cart\Domain\Model\Cart\Cart; use Extcode\Cart\Domain\Model\Cart\CartCouponFix; use Extcode\Cart\Domain\Model\Cart\TaxClass; -use Extcode\Cart\Service\CurrencyTranslationService; -use Extcode\Cart\Service\CurrencyTranslationServiceInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; @@ -240,8 +240,8 @@ public function isUsableReturnsFalseIfCartMinPriceIsGreaterToGivenPrice(): void private function createCartMock(array $methods = ['getGross']): Cart|MockObject { GeneralUtility::addInstance( - CurrencyTranslationServiceInterface::class, - new CurrencyTranslationService() + CurrencyTranslationLoaderInterface::class, + new CurrencyTranslationLoader() ); return $this->getMockBuilder(Cart::class) diff --git a/Tests/Unit/Domain/Model/Cart/CartCouponPercentageTest.php b/Tests/Unit/Domain/Model/Cart/CartCouponPercentageTest.php index 77b65d15..5b41f999 100644 --- a/Tests/Unit/Domain/Model/Cart/CartCouponPercentageTest.php +++ b/Tests/Unit/Domain/Model/Cart/CartCouponPercentageTest.php @@ -11,11 +11,11 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\Cart\Configuration\Loader\CurrencyTranslationLoader; +use Extcode\Cart\Configuration\Loader\CurrencyTranslationLoaderInterface; use Extcode\Cart\Domain\Model\Cart\Cart; use Extcode\Cart\Domain\Model\Cart\CartCouponPercentage; use Extcode\Cart\Domain\Model\Cart\TaxClass; -use Extcode\Cart\Service\CurrencyTranslationService; -use Extcode\Cart\Service\CurrencyTranslationServiceInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; @@ -270,8 +270,8 @@ public function isUsableReturnsFalseIfCartMinPriceIsGreaterToGivenPrice(): void private function createCartMock(array $methods = ['getGross']): Cart|MockObject { GeneralUtility::addInstance( - CurrencyTranslationServiceInterface::class, - new CurrencyTranslationService() + CurrencyTranslationLoaderInterface::class, + new CurrencyTranslationLoader() ); return $this->getMockBuilder(Cart::class) diff --git a/Tests/Unit/Domain/Model/Cart/CartTest.php b/Tests/Unit/Domain/Model/Cart/CartTest.php index abf8421e..94143af1 100644 --- a/Tests/Unit/Domain/Model/Cart/CartTest.php +++ b/Tests/Unit/Domain/Model/Cart/CartTest.php @@ -11,13 +11,13 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\Cart\Configuration\Loader\CurrencyTranslationLoader; +use Extcode\Cart\Configuration\Loader\CurrencyTranslationLoaderInterface; use Extcode\Cart\Domain\Model\Cart\Cart; use Extcode\Cart\Domain\Model\Cart\CartCouponFix; use Extcode\Cart\Domain\Model\Cart\ProductFactory; use Extcode\Cart\Domain\Model\Cart\ProductFactoryInterface; use Extcode\Cart\Domain\Model\Cart\TaxClass; -use Extcode\Cart\Service\CurrencyTranslationService; -use Extcode\Cart\Service\CurrencyTranslationServiceInterface; use LogicException; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; @@ -1315,8 +1315,8 @@ public function getSubtotalGrossReturnsSubtotalGross(): void $couponGross = 10.00; GeneralUtility::addInstance( - CurrencyTranslationServiceInterface::class, - new CurrencyTranslationService() + CurrencyTranslationLoaderInterface::class, + new CurrencyTranslationLoader() ); $cart = $this->getMockBuilder(Cart::class) ->onlyMethods(['getCouponGross', 'getCurrencyTranslation']) @@ -1353,8 +1353,8 @@ public function getSubtotalNetReturnsSubtotalNet(): void $couponNet = $couponGross / 1.19; GeneralUtility::addInstance( - CurrencyTranslationServiceInterface::class, - new CurrencyTranslationService() + CurrencyTranslationLoaderInterface::class, + new CurrencyTranslationLoader() ); $cart = $this->getMockBuilder(Cart::class) ->onlyMethods(['getCouponNet', 'getCurrencyTranslation']) @@ -1402,8 +1402,8 @@ public function getCurrencyCodeInitiallyReturnsString(): void public function constructorSetsCurrencyCode(): void { GeneralUtility::addInstance( - CurrencyTranslationServiceInterface::class, - new CurrencyTranslationService() + CurrencyTranslationLoaderInterface::class, + new CurrencyTranslationLoader() ); $cart = new Cart( $this->taxClasses, @@ -1455,8 +1455,8 @@ public function getCurrencySignInitiallyReturnsString(): void public function constructorSetsCurrencySign(): void { GeneralUtility::addInstance( - CurrencyTranslationServiceInterface::class, - new CurrencyTranslationService() + CurrencyTranslationLoaderInterface::class, + new CurrencyTranslationLoader() ); $cart = new Cart( $this->taxClasses, @@ -1508,8 +1508,8 @@ public function getCurrencyTranslationInitiallyReturnsFloat(): void public function constructorSetsCurrencyTranslation(): void { GeneralUtility::addInstance( - CurrencyTranslationServiceInterface::class, - new CurrencyTranslationService() + CurrencyTranslationLoaderInterface::class, + new CurrencyTranslationLoader() ); $cart = new Cart( $this->taxClasses, @@ -1603,8 +1603,8 @@ protected function addFirstProductToCarts(): void private function createCart(bool $isNetCart): Cart { GeneralUtility::addInstance( - CurrencyTranslationServiceInterface::class, - new CurrencyTranslationService() + CurrencyTranslationLoaderInterface::class, + new CurrencyTranslationLoader() ); return new Cart($this->taxClasses, $isNetCart); diff --git a/Tests/Unit/Domain/Model/Cart/ServiceTest.php b/Tests/Unit/Domain/Model/Cart/ServiceTest.php index 7325aaa3..dc4ab9aa 100644 --- a/Tests/Unit/Domain/Model/Cart/ServiceTest.php +++ b/Tests/Unit/Domain/Model/Cart/ServiceTest.php @@ -11,12 +11,12 @@ * LICENSE file that was distributed with this source code. */ +use Extcode\Cart\Configuration\Loader\CurrencyTranslationLoader; +use Extcode\Cart\Configuration\Loader\CurrencyTranslationLoaderInterface; use Extcode\Cart\Domain\Model\Cart\Cart; use Extcode\Cart\Domain\Model\Cart\Product; use Extcode\Cart\Domain\Model\Cart\Service; use Extcode\Cart\Domain\Model\Cart\TaxClass; -use Extcode\Cart\Service\CurrencyTranslationService; -use Extcode\Cart\Service\CurrencyTranslationServiceInterface; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\Test; use PHPUnit\Framework\MockObject\MockObject; @@ -471,8 +471,8 @@ public function forTaxClassIdMinusTwoReturnsPseudoTaxClassWithIdMinusTwo(): void private function createCartMock(array $methods = ['getGross']): Cart|MockObject { GeneralUtility::addInstance( - CurrencyTranslationServiceInterface::class, - new CurrencyTranslationService() + CurrencyTranslationLoaderInterface::class, + new CurrencyTranslationLoader() ); return $this->getMockBuilder(Cart::class)