diff --git a/src/Resources/config/services.xml b/src/Resources/config/services.xml
index b79e98b45..6ecbf5795 100644
--- a/src/Resources/config/services.xml
+++ b/src/Resources/config/services.xml
@@ -108,6 +108,7 @@
+
diff --git a/src/Service/ShippingMethodService.php b/src/Service/ShippingMethodService.php
index ad2f62f56..0337c7e96 100644
--- a/src/Service/ShippingMethodService.php
+++ b/src/Service/ShippingMethodService.php
@@ -2,13 +2,13 @@
namespace Kiener\MolliePayments\Service;
+use Shopware\Core\Checkout\Shipping\SalesChannel\AbstractShippingMethodRoute;
use Shopware\Core\Checkout\Shipping\ShippingMethodCollection;
use Shopware\Core\Checkout\Shipping\ShippingMethodEntity;
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository;
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
-use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsAnyFilter;
-use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter;
use Shopware\Core\System\SalesChannel\SalesChannelContext;
+use Symfony\Component\HttpFoundation\Request;
class ShippingMethodService
{
@@ -17,14 +17,20 @@ class ShippingMethodService
*/
private $shippingMethodRepository;
+ /**
+ * @var AbstractShippingMethodRoute
+ */
+ private $shippingMethodRoute;
+
/**
* Creates a new instance of the shipping method repository.
*
* @param EntityRepository $shippingMethodRepository
*/
- public function __construct($shippingMethodRepository)
+ public function __construct($shippingMethodRepository, AbstractShippingMethodRoute $shippingMethodRoute)
{
$this->shippingMethodRepository = $shippingMethodRepository;
+ $this->shippingMethodRoute = $shippingMethodRoute;
}
/**
@@ -52,18 +58,9 @@ public function getShippingMethodById(string $shippingMethodId, SalesChannelCont
*/
public function getActiveShippingMethods(SalesChannelContext $salesChannelContext): ShippingMethodCollection
{
- $criteria = (new Criteria())
- ->addFilter(new EqualsFilter('active', true))
- ->addFilter(new EqualsFilter('salesChannels.id', $salesChannelContext->getSalesChannel()->getId()))
- ->addFilter(new EqualsAnyFilter('availabilityRuleId', $salesChannelContext->getRuleIds()))
- ->addAssociation('prices')
- ->addAssociation('salesChannels');
-
- /** @var ShippingMethodCollection $shippingMethods */
- $shippingMethods = $this->shippingMethodRepository
- ->search($criteria, $salesChannelContext->getContext())
- ->getEntities();
+ $request = new Request();
+ $request->query->set('onlyAvailable', '1');
- return $shippingMethods->filterByActiveRules($salesChannelContext);
+ return $this->shippingMethodRoute->load($request, $salesChannelContext, new Criteria())->getShippingMethods();
}
}