Skip to content

Commit

Permalink
MOL-1071: fix service loading problem on Shopware 5.3 and lower
Browse files Browse the repository at this point in the history
  • Loading branch information
boxblinkracer committed Mar 9, 2023
1 parent 3ac08f5 commit 0e11f51
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 19 deletions.
42 changes: 24 additions & 18 deletions Components/Services/BasketService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,46 @@
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
{
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;

/**
Expand All @@ -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');

Expand All @@ -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();
}

/**
Expand Down
39 changes: 39 additions & 0 deletions Components/Services/ShopwareVersionService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace MollieShopware\Components\Services;

use Shopware\Components\DependencyInjection\Container as DIContainer;

class ShopwareVersionService
{

/**
* @var string
*/
private $shopwareVersion;


/**
* @param DIContainer $container
*/
public function __construct($container)
{
$releaseKey = 'shopware.release.version';

if ($container->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;
}
}
7 changes: 6 additions & 1 deletion Resources/services/components/mixed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
</service>


<service id="mollie_shopware.shopware.version" class="MollieShopware\Components\Services\ShopwareVersionService">
<argument type="service" id="service_container"/>
</service>

<service id="mollie_shopware.order_service" class="MollieShopware\Components\Services\OrderService" public="true">
<argument type="service" id="models"/>
<argument type="service" id="mollie_shopware.components.logger"/>
Expand All @@ -75,6 +79,7 @@
<service id="mollie_shopware.basket_service" class="MollieShopware\Components\Services\BasketService" public="true">
<argument type="service" id="models"/>
<argument type="service" id="mollie_shopware.components.logger"/>
<argument type="service" id="mollie_shopware.shopware.version"/>
<argument type="service" id="service_container"/>
</service>

Expand Down Expand Up @@ -192,7 +197,7 @@
</service>

<service id="mollie_shopware.components.active_payment_methods_provider" class="MollieShopware\Components\Payment\Provider\ActivePaymentMethodsProvider" public="true">
<argument type="service" id="mollie_shopware.api_factory" />
<argument type="service" id="mollie_shopware.api_factory"/>
<argument type="service" id="mollie_shopware.components.logger"/>
</service>

Expand Down

0 comments on commit 0e11f51

Please sign in to comment.