From 0e11f51efb8f0c9d30b76d283a63c1ccf574ce02 Mon Sep 17 00:00:00 2001 From: Christian Dangl Date: Thu, 9 Mar 2023 08:52:05 +0100 Subject: [PATCH] MOL-1071: fix service loading problem on Shopware 5.3 and lower --- Components/Services/BasketService.php | 42 +++++++++++-------- .../Services/ShopwareVersionService.php | 39 +++++++++++++++++ Resources/services/components/mixed.xml | 7 +++- 3 files changed, 69 insertions(+), 19 deletions(-) create mode 100644 Components/Services/ShopwareVersionService.php diff --git a/Components/Services/BasketService.php b/Components/Services/BasketService.php index 297d9a5e..6ff8e3f0 100644 --- a/Components/Services/BasketService.php +++ b/Components/Services/BasketService.php @@ -5,22 +5,16 @@ use Enlight_Components_Db_Adapter_Pdo_Mysql; use Exception; use MollieShopware\Components\Config; -use MollieShopware\Components\Logger; -use MollieShopware\Components\TransactionBuilder\Models\MollieBasketItem; use MollieShopware\Services\VersionCompare\VersionCompare; use Psr\Log\LoggerInterface; -use Shopware\Bundle\OrderBundle\Service\CalculationService; use Shopware\Bundle\OrderBundle\Service\CalculationServiceInterface; use Shopware\Components\DependencyInjection\Container as DIContainer; use Shopware\Components\Model\ModelManager; -use Shopware\Models\Order\Basket; use Shopware\Models\Order\Detail; use Shopware\Models\Order\Order; -use Shopware\Models\Order\Repository; use Shopware\Models\Order\Status; use Shopware\Models\Voucher\Voucher; use Shopware_Components_Modules; -use Symfony\Component\HttpFoundation\Request; use Zend_Db_Adapter_Exception; class BasketService @@ -28,19 +22,29 @@ class BasketService const MODE_PREMIUM = 1; const MODE_VOUCHER = 2; - /** @var Config $config */ + /** + * @var Config $config + */ protected $config; - /** @var ModelManager $modelManager */ + /** + * @var ModelManager $modelManager + */ protected $modelManager; - /** @var Shopware_Components_Modules $basketModule */ + /** + * @var Shopware_Components_Modules $basketModule + */ protected $basketModule; - /** @var OrderService $orderService */ + /** + * @var OrderService $orderService + */ protected $orderService; - /** @var null|Enlight_Components_Db_Adapter_Pdo_Mysql */ + /** + * @var null|Enlight_Components_Db_Adapter_Pdo_Mysql + */ protected $db; /** @@ -53,19 +57,23 @@ class BasketService */ private $shopwareVersion; - /** @var DIContainer */ + /** + * @var DIContainer + */ private $container; + /** * @param ModelManager $modelManager * @param LoggerInterface $logger - * @param DIContainer $container - * @throws Exception + * @param ShopwareVersionService $shopwareVersionService + * @param $container */ - public function __construct(ModelManager $modelManager, LoggerInterface $logger, $container) + public function __construct(ModelManager $modelManager, LoggerInterface $logger, ShopwareVersionService $shopwareVersionService, $container) { $this->modelManager = $modelManager; $this->logger = $logger; + $this->container = $container; $this->config = Shopware()->Container()->get('mollie_shopware.config'); @@ -75,9 +83,7 @@ public function __construct(ModelManager $modelManager, LoggerInterface $logger, $this->db = Shopware()->Container()->get('db'); - $this->shopwareVersion = (string)$container->getParameter('shopware.release.version'); - - $this->container = $container; + $this->shopwareVersion = $shopwareVersionService->getShopwareVersion(); } /** diff --git a/Components/Services/ShopwareVersionService.php b/Components/Services/ShopwareVersionService.php new file mode 100644 index 00000000..44a4a618 --- /dev/null +++ b/Components/Services/ShopwareVersionService.php @@ -0,0 +1,39 @@ +hasParameter($releaseKey)) { + $this->shopwareVersion = (string)$container->getParameter($releaseKey); + } else { + # coming with v5.3 as far as I know + # we need it only for checks > 5.7.x, so I guess that should be fine + $this->shopwareVersion = '5.3'; + } + } + + /** + * @return string + */ + public function getShopwareVersion() + { + return $this->shopwareVersion; + } +} diff --git a/Resources/services/components/mixed.xml b/Resources/services/components/mixed.xml index 82119511..dda91b6f 100644 --- a/Resources/services/components/mixed.xml +++ b/Resources/services/components/mixed.xml @@ -67,6 +67,10 @@ + + + + @@ -75,6 +79,7 @@ + @@ -192,7 +197,7 @@ - +