vendor/shopware/core/Checkout/Shipping/SalesChannel/SortedShippingMethodRoute.php line 39

  1. <?php declare(strict_types=1);
  2. namespace Shopware\Core\Checkout\Shipping\SalesChannel;
  3. use Shopware\Core\Checkout\Shipping\Hook\ShippingMethodRouteHook;
  4. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  5. use Shopware\Core\Framework\Log\Package;
  6. use Shopware\Core\Framework\Script\Execution\ScriptExecutor;
  7. use Shopware\Core\System\SalesChannel\SalesChannelContext;
  8. use Symfony\Component\HttpFoundation\Request;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. #[Route(defaults: ['_routeScope' => ['store-api']])]
  11. #[Package('checkout')]
  12. class SortedShippingMethodRoute extends AbstractShippingMethodRoute
  13. {
  14.     /**
  15.      * @internal
  16.      */
  17.     public function __construct(
  18.         private readonly AbstractShippingMethodRoute $decorated,
  19.         private readonly ScriptExecutor $scriptExecutor
  20.     ) {
  21.     }
  22.     public function getDecorated(): AbstractShippingMethodRoute
  23.     {
  24.         return $this->decorated;
  25.     }
  26.     #[Route(path'/store-api/shipping-method'name'store-api.shipping.method'methods: ['GET''POST'], defaults: ['_entity' => 'shipping_method'])]
  27.     public function load(Request $requestSalesChannelContext $contextCriteria $criteria): ShippingMethodRouteResponse
  28.     {
  29.         $response $this->getDecorated()->load($request$context$criteria);
  30.         $response->getShippingMethods()->sortShippingMethodsByPreference($context);
  31.         $this->scriptExecutor->execute(new ShippingMethodRouteHook(
  32.             $response->getShippingMethods(),
  33.             $request->query->getBoolean('onlyAvailable') || $request->request->getBoolean('onlyAvailable'),
  34.             $context
  35.         ));
  36.         return $response;
  37.     }
  38. }