/
ProvideAvailableShippingMethodsAction.php
36 lines (28 loc) · 1.26 KB
/
ProvideAvailableShippingMethodsAction.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
declare(strict_types=1);
namespace Sylius\AdminOrderCreationPlugin\Controller;
use Sylius\AdminOrderCreationPlugin\Preparator\OrderPreparatorInterface;
use Sylius\AdminOrderCreationPlugin\Provider\AvailableShippingMethodsListProvider;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
final class ProvideAvailableShippingMethodsAction
{
/** @var OrderPreparatorInterface */
private $orderPreparator;
/** @var AvailableShippingMethodsListProvider */
private $availableShippingMethodsListProvider;
public function __construct(
OrderPreparatorInterface $orderPreparator,
AvailableShippingMethodsListProvider $availableShippingMethodsListProvider
) {
$this->orderPreparator = $orderPreparator;
$this->availableShippingMethodsListProvider = $availableShippingMethodsListProvider;
}
public function __invoke(Request $request): Response
{
$order = $this->orderPreparator->prepareFromRequest($request);
$shipment = $order->getShipments()->get((int) $request->attributes->get('shipmentNumber'));
return new JsonResponse($this->availableShippingMethodsListProvider->__invoke($shipment));
}
}