Skip to content

Commit a69028e

Browse files
Replaced: /orders -> /shipments
1 parent 79fb765 commit a69028e

23 files changed

+333
-304
lines changed

.editorconfig

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,8 @@ indent_size = 4
8787

8888
[phpunit.xml{,.dist}]
8989
indent_style = space
90-
indent_size = 4
90+
indent_size = 4
91+
92+
[tests/Responses/Expected/**/*.json]
93+
indent_style = space
94+
indent_size = 4

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ imports:
6262

6363
Like it was done at:
6464

65+
- [tests/Application/Entity](tests/Application/Entity)
6566
- [tests/Application/Repository](tests/Application/Repository)
6667
- [tests/Application/config/packages/_sylius.yaml](tests/Application/config/packages/_sylius.yaml)
6768

@@ -128,10 +129,10 @@ curl "$SYLIUS_HOST/api/lagersystem/product-variants/$SYLIUS_SOME_PRODUCT_VARIANT
128129
-H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
129130
```
130131

131-
### Order list enpoint
132+
### Shipments list enpoint
132133

133134
```bash
134-
curl "$SYLIUS_HOST/api/lagersystem/orders?limit=3" \
135+
curl "$SYLIUS_HOST/api/lagersystem/shipments?locale=en_US&limit=3" \
135136
-H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN"
136137
```
137138

src/Controller/Order/OrderIndexAction.php renamed to src/Controller/Shipment/ShipmentIndexAction.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,35 +2,36 @@
22

33
declare(strict_types=1);
44

5-
namespace Setono\SyliusLagersystemPlugin\Controller\Order;
5+
namespace Setono\SyliusLagersystemPlugin\Controller\Shipment;
66

77
use FOS\RestBundle\View\View;
88
use FOS\RestBundle\View\ViewHandlerInterface;
99
use Setono\SyliusLagersystemPlugin\Model\PaginatorDetails;
10-
use Setono\SyliusLagersystemPlugin\ViewRepository\Order\OrderViewRepositoryInterface;
10+
use Setono\SyliusLagersystemPlugin\ViewRepository\Shipment\ShipmentViewRepositoryInterface;
1111
use Symfony\Component\HttpFoundation\Request;
1212
use Symfony\Component\HttpFoundation\Response;
1313

14-
final class OrderIndexAction
14+
final class ShipmentIndexAction
1515
{
1616
/** @var ViewHandlerInterface */
1717
private $viewHandler;
1818

19-
/** @var OrderViewRepositoryInterface */
20-
private $orderViewRepository;
19+
/** @var ShipmentViewRepositoryInterface */
20+
private $shipmentViewRepository;
2121

2222
public function __construct(
2323
ViewHandlerInterface $viewHandler,
24-
OrderViewRepositoryInterface $orderViewRepository
24+
ShipmentViewRepositoryInterface $shipmentViewRepository
2525
) {
2626
$this->viewHandler = $viewHandler;
27-
$this->orderViewRepository = $orderViewRepository;
27+
$this->shipmentViewRepository = $shipmentViewRepository;
2828
}
2929

3030
public function __invoke(Request $request): Response
3131
{
32-
$page = $this->orderViewRepository->getAllPaginated(
33-
new PaginatorDetails($request->attributes->get('_route'), $request->query->all())
32+
$page = $this->shipmentViewRepository->getAllPaginated(
33+
new PaginatorDetails($request->attributes->get('_route'), $request->query->all()),
34+
$request->query->get('locale')
3435
);
3536

3637
return $this->viewHandler->handle(

src/Factory/Order/OrderViewFactory.php

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77
use Setono\SyliusLagersystemPlugin\Factory\Address\AddressViewFactoryInterface;
88
use Setono\SyliusLagersystemPlugin\Factory\Customer\CustomerViewFactoryInterface;
99
use Setono\SyliusLagersystemPlugin\Factory\PaymentViewFactoryInterface;
10-
use Setono\SyliusLagersystemPlugin\Factory\ShipmentViewFactoryInterface;
1110
use Setono\SyliusLagersystemPlugin\View\Order\OrderView;
1211
use Sylius\Component\Core\Model\AdjustmentInterface;
1312
use Sylius\Component\Core\Model\CustomerInterface;
1413
use Sylius\Component\Core\Model\OrderInterface;
1514
use Sylius\Component\Core\Model\OrderItemInterface;
1615
use Sylius\Component\Core\Model\PaymentInterface;
17-
use Sylius\Component\Core\Model\ShipmentInterface;
1816
use Webmozart\Assert\Assert;
1917

2018
class OrderViewFactory implements OrderViewFactoryInterface
@@ -25,9 +23,6 @@ class OrderViewFactory implements OrderViewFactoryInterface
2523
/** @var AddressViewFactoryInterface */
2624
protected $addressViewFactory;
2725

28-
/** @var ShipmentViewFactoryInterface */
29-
protected $shipmentViewFactory;
30-
3126
/** @var PaymentViewFactoryInterface */
3227
protected $paymentViewFactory;
3328

@@ -43,15 +38,13 @@ class OrderViewFactory implements OrderViewFactoryInterface
4338
public function __construct(
4439
CustomerViewFactoryInterface $customerViewFactory,
4540
AddressViewFactoryInterface $addressViewFactory,
46-
ShipmentViewFactoryInterface $shipmentViewFactory,
4741
PaymentViewFactoryInterface $paymentViewFactory,
4842
AdjustmentViewFactoryInterface $adjustmentViewFactory,
4943
ItemViewFactoryInterface $itemFactory,
5044
string $orderViewClass
5145
) {
5246
$this->customerViewFactory = $customerViewFactory;
5347
$this->addressViewFactory = $addressViewFactory;
54-
$this->shipmentViewFactory = $shipmentViewFactory;
5548
$this->paymentViewFactory = $paymentViewFactory;
5649
$this->adjustmentViewFactory = $adjustmentViewFactory;
5750
$this->itemFactory = $itemFactory;
@@ -97,11 +90,6 @@ public function create(OrderInterface $order): OrderView
9790
);
9891
}
9992

100-
/** @var ShipmentInterface $shipment */
101-
foreach ($order->getShipments() as $shipment) {
102-
$orderView->shipments[] = $this->shipmentViewFactory->create($shipment, $localeCode);
103-
}
104-
10593
/** @var PaymentInterface $payment */
10694
foreach ($order->getPayments() as $payment) {
10795
$orderView->payments[] = $this->paymentViewFactory->create($payment, $localeCode);

src/Factory/ShipmentViewFactory.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,35 +4,45 @@
44

55
namespace Setono\SyliusLagersystemPlugin\Factory;
66

7+
use Setono\SyliusLagersystemPlugin\Factory\Order\OrderViewFactoryInterface;
78
use Setono\SyliusLagersystemPlugin\View\ShipmentView;
89
use Sylius\Component\Core\Model\OrderInterface;
910
use Sylius\Component\Core\Model\ShipmentInterface;
11+
use Webmozart\Assert\Assert;
1012

1113
class ShipmentViewFactory implements ShipmentViewFactoryInterface
1214
{
1315
/** @var ShippingMethodViewFactoryInterface */
1416
protected $shippingMethodViewFactory;
1517

18+
/** @var OrderViewFactoryInterface */
19+
protected $orderViewFactory;
20+
1621
/** @var string */
1722
protected $shipmentViewClass;
1823

1924
public function __construct(
2025
ShippingMethodViewFactoryInterface $shippingMethodViewFactory,
26+
OrderViewFactoryInterface $orderViewFactory,
2127
string $shipmentViewClass
2228
) {
2329
$this->shippingMethodViewFactory = $shippingMethodViewFactory;
30+
$this->orderViewFactory = $orderViewFactory;
2431
$this->shipmentViewClass = $shipmentViewClass;
2532
}
2633

2734
public function create(ShipmentInterface $shipment, string $locale): ShipmentView
2835
{
29-
/** @var OrderInterface $order */
36+
/** @var OrderInterface|null $order */
3037
$order = $shipment->getOrder();
38+
Assert::notNull($order);
3139

3240
/** @var ShipmentView $shipmentView */
3341
$shipmentView = new $this->shipmentViewClass();
42+
$shipmentView->id = $shipment->getId();
3443
$shipmentView->state = $shipment->getState();
3544
$shipmentView->method = $this->shippingMethodViewFactory->create($shipment, $locale);
45+
$shipmentView->order = $this->orderViewFactory->create($order);
3646

3747
return $shipmentView;
3848
}

src/Repository/OrderRepositoryInterface.php renamed to src/Repository/ShipmentRepositoryInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
namespace Setono\SyliusLagersystemPlugin\Repository;
66

77
use Doctrine\ORM\QueryBuilder;
8-
use Sylius\Component\Core\Repository\OrderRepositoryInterface as BaseOrderRepositoryInterface;
8+
use Sylius\Component\Core\Repository\ShipmentRepositoryInterface as BaseShipmentRepositoryInterface;
99

10-
interface OrderRepositoryInterface extends BaseOrderRepositoryInterface
10+
interface ShipmentRepositoryInterface extends BaseShipmentRepositoryInterface
1111
{
1212
public function createLagersystemListQueryBuilder(): QueryBuilder;
1313
}

src/Repository/OrderRepositoryTrait.php renamed to src/Repository/ShipmentRepositoryTrait.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
use Sylius\Component\Core\OrderPaymentStates;
1010
use Sylius\Component\Core\OrderShippingStates;
1111

12-
trait OrderRepositoryTrait
12+
trait ShipmentRepositoryTrait
1313
{
1414
/**
1515
* @param string $alias
@@ -21,7 +21,9 @@ abstract public function createQueryBuilder($alias, $indexBy = null);
2121

2222
public function createLagersystemListQueryBuilder(): QueryBuilder
2323
{
24-
return $this->createQueryBuilder('o')
24+
return $this->createQueryBuilder('shipment')
25+
->join('shipment.order', 'o')
26+
2527
->andWhere('o.checkoutState in (:checkoutStates)')
2628
->setParameter('checkoutStates', [
2729
OrderCheckoutStates::STATE_COMPLETED,

src/Resources/config/routing/api.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
setono_sylius_lagersystem_api_order_index:
2-
path: /orders
1+
setono_sylius_lagersystem_api_shipment_index:
2+
path: /shipments
33
methods: [GET]
44
defaults:
5-
_controller: setono_sylius_lagersystem.controller.order.order_index_action
5+
_controller: setono_sylius_lagersystem.controller.shipment.shipment_index_action
66

77
setono_sylius_lagersystem_api_product_variant_index:
88
path: /product-variants

src/Resources/config/services/actions.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
<services>
77
<defaults public="true" />
88

9-
<service id="setono_sylius_lagersystem.controller.order.order_index_action"
10-
class="Setono\SyliusLagersystemPlugin\Controller\Order\OrderIndexAction">
9+
<service id="setono_sylius_lagersystem.controller.shipment.shipment_index_action"
10+
class="Setono\SyliusLagersystemPlugin\Controller\Shipment\ShipmentIndexAction">
1111
<argument type="service" id="fos_rest.view_handler" />
12-
<argument type="service" id="setono_sylius_lagersystem.view_repository.order_view_repository" />
12+
<argument type="service" id="setono_sylius_lagersystem.view_repository.shipment_view_repository" />
1313
</service>
1414

1515
<service id="setono_sylius_lagersystem.controller.product.product_variant_index_action"

src/Resources/config/services/factories.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<service id="setono_sylius_lagersystem.factory.shipment_view_factory"
2929
class="Setono\SyliusLagersystemPlugin\Factory\ShipmentViewFactory">
3030
<argument type="service" id="setono_sylius_lagersystem.factory.shipping_method_view_factory"/>
31+
<argument type="service" id="setono_sylius_lagersystem.factory.order_view_factory"/>
3132
<argument type="string">%setono_sylius_lagersystem.view.shipment.class%</argument>
3233
</service>
3334

@@ -46,7 +47,6 @@
4647
class="Setono\SyliusLagersystemPlugin\Factory\Order\OrderViewFactory">
4748
<argument type="service" id="setono_sylius_lagersystem.factory.customer_view_factory"/>
4849
<argument type="service" id="setono_sylius_lagersystem.factory.address_view_factory"/>
49-
<argument type="service" id="setono_sylius_lagersystem.factory.shipment_view_factory"/>
5050
<argument type="service" id="setono_sylius_lagersystem.factory.payment_view_factory"/>
5151
<argument type="service" id="setono_sylius_lagersystem.factory.adjustment_view_factory"/>
5252
<argument type="service" id="setono_sylius_lagersystem.factory.item_view_factory"/>

0 commit comments

Comments
 (0)