From fae287465d6fd8ac69feb41ae229f6107003eb50 Mon Sep 17 00:00:00 2001 From: Igor Mukhin Date: Tue, 10 Mar 2020 16:54:33 +0200 Subject: [PATCH] Replaced: /orders -> /shipments --- .editorconfig | 6 +- .scrutinizer.yml | 2 + README.md | 5 +- .../ShipmentIndexAction.php} | 19 +- src/DependencyInjection/Configuration.php | 7 +- src/Factory/Order/ItemUnitViewFactory.php | 29 --- .../Order/ItemUnitViewFactoryInterface.php | 13 -- src/Factory/Order/ItemViewFactory.php | 55 ----- .../Order/ItemViewFactoryInterface.php | 13 -- src/Factory/Order/OrderViewFactory.php | 28 +-- src/Factory/ShipmentViewFactory.php | 39 ---- .../Shipping/ShipmentUnitViewFactory.php | 47 +++++ .../ShipmentUnitViewFactoryInterface.php | 13 ++ src/Factory/Shipping/ShipmentViewFactory.php | 65 ++++++ .../ShipmentViewFactoryInterface.php | 4 +- .../ShippingMethodViewFactory.php | 4 +- .../ShippingMethodViewFactoryInterface.php | 4 +- ...ce.php => ShipmentRepositoryInterface.php} | 4 +- ...yTrait.php => ShipmentRepositoryTrait.php} | 6 +- src/Resources/config/routing/api.yaml | 6 +- src/Resources/config/services/actions.xml | 6 +- src/Resources/config/services/factories.xml | 26 +-- .../config/services/repositories.xml | 8 +- src/View/Order/ItemUnitView.php | 14 -- src/View/Order/ItemView.php | 25 --- src/View/Order/OrderView.php | 13 +- src/View/PaymentView.php | 2 - src/View/ShipmentView.php | 16 -- src/View/Shipping/ShipmentUnitView.php | 19 ++ src/View/Shipping/ShipmentView.php | 31 +++ .../{ => Shipping}/ShippingMethodView.php | 4 +- .../ShipmentViewRepository.php} | 32 +-- .../ShipmentViewRepositoryInterface.php} | 6 +- .../Repository/OrderRepository.php | 14 -- .../Repository/ShipmentRepository.php | 14 ++ .../Application/config/packages/_sylius.yaml | 6 +- tests/Controller/Order/OrderIndexApiTest.php | 32 --- .../{Order => Shipping}/JsonApiTestCase.php | 14 +- .../Shipping/ShipmentIndexApiTest.php | 44 ++++ tests/DataFixtures/ORM/order.yml | 4 +- .../DependencyInjection/ConfigurationTest.php | 7 +- .../SetonoSyliusLagersystemExtensionTest.php | 7 +- .../Expected/order/order_index_response.json | 190 ----------------- .../shipment/shipment_index_response.json | 191 ++++++++++++++++++ 44 files changed, 527 insertions(+), 567 deletions(-) rename src/Controller/{Order/OrderIndexAction.php => Shipping/ShipmentIndexAction.php} (58%) delete mode 100644 src/Factory/Order/ItemUnitViewFactory.php delete mode 100644 src/Factory/Order/ItemUnitViewFactoryInterface.php delete mode 100644 src/Factory/Order/ItemViewFactory.php delete mode 100644 src/Factory/Order/ItemViewFactoryInterface.php delete mode 100644 src/Factory/ShipmentViewFactory.php create mode 100644 src/Factory/Shipping/ShipmentUnitViewFactory.php create mode 100644 src/Factory/Shipping/ShipmentUnitViewFactoryInterface.php create mode 100644 src/Factory/Shipping/ShipmentViewFactory.php rename src/Factory/{ => Shipping}/ShipmentViewFactoryInterface.php (63%) rename src/Factory/{ => Shipping}/ShippingMethodViewFactory.php (89%) rename src/Factory/{ => Shipping}/ShippingMethodViewFactoryInterface.php (64%) rename src/Repository/{OrderRepositoryInterface.php => ShipmentRepositoryInterface.php} (52%) rename src/Repository/{OrderRepositoryTrait.php => ShipmentRepositoryTrait.php} (90%) delete mode 100644 src/View/Order/ItemUnitView.php delete mode 100644 src/View/Order/ItemView.php delete mode 100644 src/View/ShipmentView.php create mode 100644 src/View/Shipping/ShipmentUnitView.php create mode 100644 src/View/Shipping/ShipmentView.php rename src/View/{ => Shipping}/ShippingMethodView.php (70%) rename src/ViewRepository/{Order/OrderViewRepository.php => Shipment/ShipmentViewRepository.php} (51%) rename src/ViewRepository/{Order/OrderViewRepositoryInterface.php => Shipment/ShipmentViewRepositoryInterface.php} (58%) delete mode 100644 tests/Application/Repository/OrderRepository.php create mode 100644 tests/Application/Repository/ShipmentRepository.php delete mode 100644 tests/Controller/Order/OrderIndexApiTest.php rename tests/Controller/{Order => Shipping}/JsonApiTestCase.php (52%) create mode 100644 tests/Controller/Shipping/ShipmentIndexApiTest.php delete mode 100644 tests/Responses/Expected/order/order_index_response.json create mode 100644 tests/Responses/Expected/shipment/shipment_index_response.json diff --git a/.editorconfig b/.editorconfig index 0b666c6..0bc2f14 100644 --- a/.editorconfig +++ b/.editorconfig @@ -87,4 +87,8 @@ indent_size = 4 [phpunit.xml{,.dist}] indent_style = space -indent_size = 4 \ No newline at end of file +indent_size = 4 + +[tests/Responses/Expected/**/*.json] +indent_style = space +indent_size = 4 diff --git a/.scrutinizer.yml b/.scrutinizer.yml index e6c6037..cfc8105 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -7,6 +7,8 @@ build: environment: variables: COMPOSER_MEMORY_LIMIT: -1 + php: + version: 7.4 filter: excluded_paths: [tests/*, spec/*] diff --git a/README.md b/README.md index 7a93a11..a2a4e39 100644 --- a/README.md +++ b/README.md @@ -62,6 +62,7 @@ imports: Like it was done at: +- [tests/Application/Entity](tests/Application/Entity) - [tests/Application/Repository](tests/Application/Repository) - [tests/Application/config/packages/_sylius.yaml](tests/Application/config/packages/_sylius.yaml) @@ -128,10 +129,10 @@ curl "$SYLIUS_HOST/api/lagersystem/product-variants/$SYLIUS_SOME_PRODUCT_VARIANT -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN" ``` -### Order list enpoint +### Shipments list enpoint ```bash -curl "$SYLIUS_HOST/api/lagersystem/orders?limit=3" \ +curl "$SYLIUS_HOST/api/lagersystem/shipments?locale=en_US&limit=3" \ -H "Authorization: Bearer $SYLIUS_ADMIN_API_ACCESS_TOKEN" ``` diff --git a/src/Controller/Order/OrderIndexAction.php b/src/Controller/Shipping/ShipmentIndexAction.php similarity index 58% rename from src/Controller/Order/OrderIndexAction.php rename to src/Controller/Shipping/ShipmentIndexAction.php index 8879ba2..abcf26e 100644 --- a/src/Controller/Order/OrderIndexAction.php +++ b/src/Controller/Shipping/ShipmentIndexAction.php @@ -2,35 +2,36 @@ declare(strict_types=1); -namespace Setono\SyliusLagersystemPlugin\Controller\Order; +namespace Setono\SyliusLagersystemPlugin\Controller\Shipping; use FOS\RestBundle\View\View; use FOS\RestBundle\View\ViewHandlerInterface; use Setono\SyliusLagersystemPlugin\Model\PaginatorDetails; -use Setono\SyliusLagersystemPlugin\ViewRepository\Order\OrderViewRepositoryInterface; +use Setono\SyliusLagersystemPlugin\ViewRepository\Shipment\ShipmentViewRepositoryInterface; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -final class OrderIndexAction +final class ShipmentIndexAction { /** @var ViewHandlerInterface */ private $viewHandler; - /** @var OrderViewRepositoryInterface */ - private $orderViewRepository; + /** @var ShipmentViewRepositoryInterface */ + private $shipmentViewRepository; public function __construct( ViewHandlerInterface $viewHandler, - OrderViewRepositoryInterface $orderViewRepository + ShipmentViewRepositoryInterface $shipmentViewRepository ) { $this->viewHandler = $viewHandler; - $this->orderViewRepository = $orderViewRepository; + $this->shipmentViewRepository = $shipmentViewRepository; } public function __invoke(Request $request): Response { - $page = $this->orderViewRepository->getAllPaginated( - new PaginatorDetails($request->attributes->get('_route'), $request->query->all()) + $page = $this->shipmentViewRepository->getAllPaginated( + new PaginatorDetails($request->attributes->get('_route'), $request->query->all()), + $request->query->get('locale') ); return $this->viewHandler->handle( diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 7ee922a..f10cc11 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -40,14 +40,13 @@ private function buildViewClassesNode(ArrayNodeDefinition $rootNode): void ->scalarNode('image')->defaultValue(View\Image\ImageView::class)->end() ->scalarNode('customer')->defaultValue(View\Customer\CustomerView::class)->end() ->scalarNode('address')->defaultValue(View\AddressView::class)->end() - ->scalarNode('shipping_method')->defaultValue(View\ShippingMethodView::class)->end() - ->scalarNode('shipment')->defaultValue(View\ShipmentView::class)->end() + ->scalarNode('shipping_method')->defaultValue(View\Shipping\ShippingMethodView::class)->end() + ->scalarNode('shipment')->defaultValue(View\Shipping\ShipmentView::class)->end() + ->scalarNode('shipment_unit')->defaultValue(View\Shipping\ShipmentUnitView::class)->end() ->scalarNode('payment_method')->defaultValue(View\PaymentMethodView::class)->end() ->scalarNode('payment')->defaultValue(View\PaymentView::class)->end() ->scalarNode('adjustment')->defaultValue(View\Order\AdjustmentView::class)->end() ->scalarNode('order')->defaultValue(View\Order\OrderView::class)->end() - ->scalarNode('order_item')->defaultValue(View\Order\ItemView::class)->end() - ->scalarNode('order_item_unit')->defaultValue(View\Order\ItemUnitView::class)->end() ->scalarNode('product_variant')->defaultValue(View\Product\ProductVariantView::class)->end() ->end() ->end() diff --git a/src/Factory/Order/ItemUnitViewFactory.php b/src/Factory/Order/ItemUnitViewFactory.php deleted file mode 100644 index 26dd9b4..0000000 --- a/src/Factory/Order/ItemUnitViewFactory.php +++ /dev/null @@ -1,29 +0,0 @@ -itemUnitViewClass = $itemUnitViewClass; - } - - public function create(OrderItemUnitInterface $itemUnit, string $localeCode): ItemUnitView - { - /** @var ItemUnitView $itemUnitView */ - $itemUnitView = new $this->itemUnitViewClass(); - $itemUnitView->total = $itemUnit->getTotal(); - $itemUnitView->adjustmentsTotal = $itemUnit->getAdjustmentsTotal(); - - return $itemUnitView; - } -} diff --git a/src/Factory/Order/ItemUnitViewFactoryInterface.php b/src/Factory/Order/ItemUnitViewFactoryInterface.php deleted file mode 100644 index d1cb440..0000000 --- a/src/Factory/Order/ItemUnitViewFactoryInterface.php +++ /dev/null @@ -1,13 +0,0 @@ -productVariantViewFactory = $productVariantViewFactory; - $this->itemUnitViewFactory = $itemUnitViewFactory; - $this->itemViewClass = $itemViewClass; - } - - public function create(OrderItemInterface $item, string $localeCode): ItemView - { - /** @var ItemView $itemView */ - $itemView = new $this->itemViewClass(); - $itemView->id = $item->getId(); - $itemView->quantity = $item->getQuantity(); - $itemView->total = $item->getTotal(); - $itemView->variant = $this->productVariantViewFactory->create( - $item->getVariant(), - $localeCode - ); - - /** @var OrderItemUnitInterface $itemUnit */ - foreach ($item->getUnits() as $itemUnit) { - $itemView->units[] = $this->itemUnitViewFactory->create( - $itemUnit, - $localeCode - ); - } - - return $itemView; - } -} diff --git a/src/Factory/Order/ItemViewFactoryInterface.php b/src/Factory/Order/ItemViewFactoryInterface.php deleted file mode 100644 index b4ca892..0000000 --- a/src/Factory/Order/ItemViewFactoryInterface.php +++ /dev/null @@ -1,13 +0,0 @@ -customerViewFactory = $customerViewFactory; $this->addressViewFactory = $addressViewFactory; - $this->shipmentViewFactory = $shipmentViewFactory; $this->paymentViewFactory = $paymentViewFactory; $this->adjustmentViewFactory = $adjustmentViewFactory; - $this->itemFactory = $itemFactory; $this->orderViewClass = $orderViewClass; } @@ -86,22 +73,8 @@ public function create(OrderInterface $order): OrderView $orderView->state = $order->getState(); $orderView->checkoutState = $order->getCheckoutState(); $orderView->checkoutCompletedAt = $checkoutCompletedAt->format('c'); - $orderView->shippingState = $order->getShippingState(); $orderView->paymentState = $order->getPaymentState(); - /** @var OrderItemInterface $item */ - foreach ($order->getItems() as $item) { - $orderView->items[] = $this->itemFactory->create( - $item, - $localeCode - ); - } - - /** @var ShipmentInterface $shipment */ - foreach ($order->getShipments() as $shipment) { - $orderView->shipments[] = $this->shipmentViewFactory->create($shipment, $localeCode); - } - /** @var PaymentInterface $payment */ foreach ($order->getPayments() as $payment) { $orderView->payments[] = $this->paymentViewFactory->create($payment, $localeCode); @@ -128,6 +101,7 @@ public function create(OrderInterface $order): OrderView } $orderView->adjustments = $adjustments; $orderView->adjustmentsTotal = $order->getAdjustmentsTotalRecursively(); + $orderView->itemsTotal = $order->getItemsTotal(); $orderView->total = $order->getTotal(); $orderView->customer = $this->customerViewFactory->create($customer); diff --git a/src/Factory/ShipmentViewFactory.php b/src/Factory/ShipmentViewFactory.php deleted file mode 100644 index 03b86c3..0000000 --- a/src/Factory/ShipmentViewFactory.php +++ /dev/null @@ -1,39 +0,0 @@ -shippingMethodViewFactory = $shippingMethodViewFactory; - $this->shipmentViewClass = $shipmentViewClass; - } - - public function create(ShipmentInterface $shipment, string $locale): ShipmentView - { - /** @var OrderInterface $order */ - $order = $shipment->getOrder(); - - /** @var ShipmentView $shipmentView */ - $shipmentView = new $this->shipmentViewClass(); - $shipmentView->state = $shipment->getState(); - $shipmentView->method = $this->shippingMethodViewFactory->create($shipment, $locale); - - return $shipmentView; - } -} diff --git a/src/Factory/Shipping/ShipmentUnitViewFactory.php b/src/Factory/Shipping/ShipmentUnitViewFactory.php new file mode 100644 index 0000000..3d74956 --- /dev/null +++ b/src/Factory/Shipping/ShipmentUnitViewFactory.php @@ -0,0 +1,47 @@ +shippableViewFactory = $shippableViewFactory; + $this->shipmentUnitViewClass = $shipmentUnitViewClass; + } + + public function create(ShipmentUnitInterface $shipmentUnit, string $locale): ShipmentUnitView + { + /** @var ProductVariantInterface|null $shippable */ + $shippable = $shipmentUnit->getShippable(); + Assert::notNull($shippable); + + /** @var ShipmentUnitView $shipmentUnitView */ + $shipmentUnitView = new $this->shipmentUnitViewClass(); + $shipmentUnitView->shippable = $this->shippableViewFactory->create($shippable, $locale); + + if ($shipmentUnit instanceof OrderItemUnitInterface) { + $shipmentUnitView->total = $shipmentUnit->getTotal(); + $shipmentUnitView->adjustmentsTotal = $shipmentUnit->getAdjustmentsTotal(); + } + + return $shipmentUnitView; + } +} diff --git a/src/Factory/Shipping/ShipmentUnitViewFactoryInterface.php b/src/Factory/Shipping/ShipmentUnitViewFactoryInterface.php new file mode 100644 index 0000000..191dc97 --- /dev/null +++ b/src/Factory/Shipping/ShipmentUnitViewFactoryInterface.php @@ -0,0 +1,13 @@ +shippingMethodViewFactory = $shippingMethodViewFactory; + $this->shipmentUnitViewFactory = $shipmentUnitViewFactory; + $this->orderViewFactory = $orderViewFactory; + $this->shipmentViewClass = $shipmentViewClass; + } + + public function create(ShipmentInterface $shipment, string $locale): ShipmentView + { + /** @var OrderInterface|null $order */ + $order = $shipment->getOrder(); + Assert::notNull($order); + + $shippedAt = $shipment->getShippedAt(); + + /** @var ShipmentView $shipmentView */ + $shipmentView = new $this->shipmentViewClass(); + $shipmentView->id = $shipment->getId(); + $shipmentView->state = $shipment->getState(); + $shipmentView->method = $this->shippingMethodViewFactory->create($shipment, $locale); + + /** @var ShipmentUnitInterface $shipmentUnit */ + foreach ($shipment->getUnits() as $shipmentUnit) { + $shipmentView->units[] = $this->shipmentUnitViewFactory->create($shipmentUnit, $locale); + } + + $shipmentView->order = $this->orderViewFactory->create($order); + $shipmentView->tracking = $shipment->getTracking(); + $shipmentView->shippedAt = null !== $shippedAt ? $shippedAt->format('c') : null; + + return $shipmentView; + } +} diff --git a/src/Factory/ShipmentViewFactoryInterface.php b/src/Factory/Shipping/ShipmentViewFactoryInterface.php similarity index 63% rename from src/Factory/ShipmentViewFactoryInterface.php rename to src/Factory/Shipping/ShipmentViewFactoryInterface.php index 8f243a9..0993a26 100644 --- a/src/Factory/ShipmentViewFactoryInterface.php +++ b/src/Factory/Shipping/ShipmentViewFactoryInterface.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Setono\SyliusLagersystemPlugin\Factory; +namespace Setono\SyliusLagersystemPlugin\Factory\Shipping; -use Setono\SyliusLagersystemPlugin\View\ShipmentView; +use Setono\SyliusLagersystemPlugin\View\Shipping\ShipmentView; use Sylius\Component\Core\Model\ShipmentInterface; interface ShipmentViewFactoryInterface diff --git a/src/Factory/ShippingMethodViewFactory.php b/src/Factory/Shipping/ShippingMethodViewFactory.php similarity index 89% rename from src/Factory/ShippingMethodViewFactory.php rename to src/Factory/Shipping/ShippingMethodViewFactory.php index 5a6b760..5853687 100644 --- a/src/Factory/ShippingMethodViewFactory.php +++ b/src/Factory/Shipping/ShippingMethodViewFactory.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Setono\SyliusLagersystemPlugin\Factory; +namespace Setono\SyliusLagersystemPlugin\Factory\Shipping; -use Setono\SyliusLagersystemPlugin\View\ShippingMethodView; +use Setono\SyliusLagersystemPlugin\View\Shipping\ShippingMethodView; use Sylius\Component\Core\Model\ShipmentInterface; use Webmozart\Assert\Assert; diff --git a/src/Factory/ShippingMethodViewFactoryInterface.php b/src/Factory/Shipping/ShippingMethodViewFactoryInterface.php similarity index 64% rename from src/Factory/ShippingMethodViewFactoryInterface.php rename to src/Factory/Shipping/ShippingMethodViewFactoryInterface.php index 6d96e01..aa8322b 100644 --- a/src/Factory/ShippingMethodViewFactoryInterface.php +++ b/src/Factory/Shipping/ShippingMethodViewFactoryInterface.php @@ -2,9 +2,9 @@ declare(strict_types=1); -namespace Setono\SyliusLagersystemPlugin\Factory; +namespace Setono\SyliusLagersystemPlugin\Factory\Shipping; -use Setono\SyliusLagersystemPlugin\View\ShippingMethodView; +use Setono\SyliusLagersystemPlugin\View\Shipping\ShippingMethodView; use Sylius\Component\Core\Model\ShipmentInterface; interface ShippingMethodViewFactoryInterface diff --git a/src/Repository/OrderRepositoryInterface.php b/src/Repository/ShipmentRepositoryInterface.php similarity index 52% rename from src/Repository/OrderRepositoryInterface.php rename to src/Repository/ShipmentRepositoryInterface.php index d2ec81f..1b907ee 100644 --- a/src/Repository/OrderRepositoryInterface.php +++ b/src/Repository/ShipmentRepositoryInterface.php @@ -5,9 +5,9 @@ namespace Setono\SyliusLagersystemPlugin\Repository; use Doctrine\ORM\QueryBuilder; -use Sylius\Component\Core\Repository\OrderRepositoryInterface as BaseOrderRepositoryInterface; +use Sylius\Component\Core\Repository\ShipmentRepositoryInterface as BaseShipmentRepositoryInterface; -interface OrderRepositoryInterface extends BaseOrderRepositoryInterface +interface ShipmentRepositoryInterface extends BaseShipmentRepositoryInterface { public function createLagersystemListQueryBuilder(): QueryBuilder; } diff --git a/src/Repository/OrderRepositoryTrait.php b/src/Repository/ShipmentRepositoryTrait.php similarity index 90% rename from src/Repository/OrderRepositoryTrait.php rename to src/Repository/ShipmentRepositoryTrait.php index 5879498..156728f 100644 --- a/src/Repository/OrderRepositoryTrait.php +++ b/src/Repository/ShipmentRepositoryTrait.php @@ -9,7 +9,7 @@ use Sylius\Component\Core\OrderPaymentStates; use Sylius\Component\Core\OrderShippingStates; -trait OrderRepositoryTrait +trait ShipmentRepositoryTrait { /** * @param string $alias @@ -21,7 +21,9 @@ abstract public function createQueryBuilder($alias, $indexBy = null); public function createLagersystemListQueryBuilder(): QueryBuilder { - return $this->createQueryBuilder('o') + return $this->createQueryBuilder('shipment') + ->join('shipment.order', 'o') + ->andWhere('o.checkoutState in (:checkoutStates)') ->setParameter('checkoutStates', [ OrderCheckoutStates::STATE_COMPLETED, diff --git a/src/Resources/config/routing/api.yaml b/src/Resources/config/routing/api.yaml index 91bf27f..55d14f4 100644 --- a/src/Resources/config/routing/api.yaml +++ b/src/Resources/config/routing/api.yaml @@ -1,8 +1,8 @@ -setono_sylius_lagersystem_api_order_index: - path: /orders +setono_sylius_lagersystem_api_shipment_index: + path: /shipments methods: [GET] defaults: - _controller: setono_sylius_lagersystem.controller.order.order_index_action + _controller: setono_sylius_lagersystem.controller.shipment.shipment_index_action setono_sylius_lagersystem_api_product_variant_index: path: /product-variants diff --git a/src/Resources/config/services/actions.xml b/src/Resources/config/services/actions.xml index 66ce18e..34ad105 100644 --- a/src/Resources/config/services/actions.xml +++ b/src/Resources/config/services/actions.xml @@ -6,10 +6,10 @@ - + - + + class="Setono\SyliusLagersystemPlugin\Factory\Shipping\ShippingMethodViewFactory"> %setono_sylius_lagersystem.view.shipping_method.class% + + + %setono_sylius_lagersystem.view.shipment_unit.class% + + + class="Setono\SyliusLagersystemPlugin\Factory\Shipping\ShipmentViewFactory"> + + %setono_sylius_lagersystem.view.shipment.class% @@ -46,10 +54,8 @@ class="Setono\SyliusLagersystemPlugin\Factory\Order\OrderViewFactory"> - - %setono_sylius_lagersystem.view.order.class% @@ -58,18 +64,6 @@ %setono_sylius_lagersystem.view.adjustment.class% - - %setono_sylius_lagersystem.view.order_item_unit.class% - - - - - - %setono_sylius_lagersystem.view.order_item.class% - - diff --git a/src/Resources/config/services/repositories.xml b/src/Resources/config/services/repositories.xml index ff1a962..7ee0cde 100644 --- a/src/Resources/config/services/repositories.xml +++ b/src/Resources/config/services/repositories.xml @@ -1,11 +1,11 @@ - - + + - + orderRepository = $orderRepository; + $this->shipmentRepository = $shipmentRepository; $this->pageViewFactory = $pageViewFactory; - $this->orderViewFactory = $orderViewFactory; + $this->shipmentViewFactory = $shipmentViewFactory; } - public function getAllPaginated(PaginatorDetails $paginatorDetails): PageView + public function getAllPaginated(PaginatorDetails $paginatorDetails, ?string $localeCode): PageView { - $queryBuilder = $this->orderRepository->createLagersystemListQueryBuilder(); + Assert::notNull($localeCode); + $queryBuilder = $this->shipmentRepository->createLagersystemListQueryBuilder(); $pagerfanta = new Pagerfanta(new DoctrineORMAdapter($queryBuilder)); $pagerfanta->setMaxPerPage($paginatorDetails->limit()); @@ -43,7 +45,7 @@ public function getAllPaginated(PaginatorDetails $paginatorDetails): PageView $pageView = $this->pageViewFactory->create($pagerfanta, $paginatorDetails->route(), $paginatorDetails->parameters()); foreach ($pagerfanta->getCurrentPageResults() as $currentPageResult) { - $pageView->items[] = $this->orderViewFactory->create($currentPageResult); + $pageView->items[] = $this->shipmentViewFactory->create($currentPageResult, $localeCode); } return $pageView; diff --git a/src/ViewRepository/Order/OrderViewRepositoryInterface.php b/src/ViewRepository/Shipment/ShipmentViewRepositoryInterface.php similarity index 58% rename from src/ViewRepository/Order/OrderViewRepositoryInterface.php rename to src/ViewRepository/Shipment/ShipmentViewRepositoryInterface.php index feeedf4..0334fe0 100644 --- a/src/ViewRepository/Order/OrderViewRepositoryInterface.php +++ b/src/ViewRepository/Shipment/ShipmentViewRepositoryInterface.php @@ -2,12 +2,12 @@ declare(strict_types=1); -namespace Setono\SyliusLagersystemPlugin\ViewRepository\Order; +namespace Setono\SyliusLagersystemPlugin\ViewRepository\Shipment; use Setono\SyliusLagersystemPlugin\Model\PaginatorDetails; use Setono\SyliusLagersystemPlugin\View\PageView; -interface OrderViewRepositoryInterface +interface ShipmentViewRepositoryInterface { - public function getAllPaginated(PaginatorDetails $paginatorDetails): PageView; + public function getAllPaginated(PaginatorDetails $paginatorDetails, ?string $localeCode): PageView; } diff --git a/tests/Application/Repository/OrderRepository.php b/tests/Application/Repository/OrderRepository.php deleted file mode 100644 index 1fc2c29..0000000 --- a/tests/Application/Repository/OrderRepository.php +++ /dev/null @@ -1,14 +0,0 @@ -loadDefaultFixtureFiles(); - $this->client->request('GET', $this->getOrdersIndexUrl(), [], [], self::$acceptHeader); - $response = $this->client->getResponse(); - $this->assertResponseCode($response, Response::HTTP_UNAUTHORIZED); - } - - /** - * @test - */ - public function index_returns_only_open_orders_in_lagersystem_terms(): void - { - $this->loadDefaultFixtureFiles(); - $this->client->request('GET', $this->getOrdersIndexUrl(), [], [], self::$authorizedHeaderWithAccept); - $response = $this->client->getResponse(); - $this->assertResponse($response, 'order/order_index_response', Response::HTTP_OK); - } -} diff --git a/tests/Controller/Order/JsonApiTestCase.php b/tests/Controller/Shipping/JsonApiTestCase.php similarity index 52% rename from tests/Controller/Order/JsonApiTestCase.php rename to tests/Controller/Shipping/JsonApiTestCase.php index 7613c75..bc0694d 100644 --- a/tests/Controller/Order/JsonApiTestCase.php +++ b/tests/Controller/Shipping/JsonApiTestCase.php @@ -2,8 +2,9 @@ declare(strict_types=1); -namespace Tests\Setono\SyliusLagersystemPlugin\Controller\Order; +namespace Tests\Setono\SyliusLagersystemPlugin\Controller\Shipping; +use function Safe\sprintf; use Tests\Setono\SyliusLagersystemPlugin\Controller\JsonApiTestCase as BaseJsonApiTestCase; abstract class JsonApiTestCase extends BaseJsonApiTestCase @@ -19,8 +20,15 @@ abstract class JsonApiTestCase extends BaseJsonApiTestCase 'order.yml', ]; - protected function getOrdersIndexUrl(): string + protected function getShipmentsIndexUrl(?string $localeCode = null): string { - return '/api/lagersystem/orders'; + if (null !== $localeCode) { + return sprintf( + '/api/lagersystem/shipments?locale=%s', + $localeCode + ); + } + + return '/api/lagersystem/shipments'; } } diff --git a/tests/Controller/Shipping/ShipmentIndexApiTest.php b/tests/Controller/Shipping/ShipmentIndexApiTest.php new file mode 100644 index 0000000..943da7e --- /dev/null +++ b/tests/Controller/Shipping/ShipmentIndexApiTest.php @@ -0,0 +1,44 @@ +loadDefaultFixtureFiles(); + $this->client->request('GET', $this->getShipmentsIndexUrl('en_US'), [], [], self::$acceptHeader); + $response = $this->client->getResponse(); + $this->assertResponseCode($response, Response::HTTP_UNAUTHORIZED); + } + + /** + * @test + */ + public function it_returns_an_exception_if_no_locale_provided(): void + { + $this->loadDefaultFixtureFiles(); + $this->client->request('GET', $this->getShipmentsIndexUrl(), [], [], self::$authorizedHeaderWithAccept); + $response = $this->client->getResponse(); + $this->assertResponseCode($response, Response::HTTP_INTERNAL_SERVER_ERROR); + } + + /** + * @test + * @group current + */ + public function index_returns_only_open_orders_in_lagersystem_terms(): void + { + $this->loadDefaultFixtureFiles(); + $this->client->request('GET', $this->getShipmentsIndexUrl('en_US'), [], [], self::$authorizedHeaderWithAccept); + $response = $this->client->getResponse(); + $this->assertResponse($response, 'shipment/shipment_index_response', Response::HTTP_OK); + } +} diff --git a/tests/DataFixtures/ORM/order.yml b/tests/DataFixtures/ORM/order.yml index 448cd84..d28af29 100644 --- a/tests/DataFixtures/ORM/order.yml +++ b/tests/DataFixtures/ORM/order.yml @@ -29,7 +29,8 @@ Sylius\Component\Core\Model\OrderItem: order_1_item_1: variant: "@mug_variant_red" unitPrice: 1999 - units: ["@order_1_item_1_unit_1", "@order_1_item_1_unit_2"] + # Do not pass units like this, otherwise unexpected extra unit will be added + # units: ["@order_1_item_1_unit_1", "@order_1_item_1_unit_2"] adjustments: [] Sylius\Component\Core\Model\Order: @@ -110,6 +111,7 @@ Sylius\Component\Core\Model\Shipment: shipment_1: state: ready method: "@shipping_method_ups" + units: ["@order_1_item_1_unit_1", "@order_1_item_1_unit_2"] shipment_2: state: partially_shipped method: "@shipping_method_ups" diff --git a/tests/DependencyInjection/ConfigurationTest.php b/tests/DependencyInjection/ConfigurationTest.php index d5c2c56..ada1e07 100644 --- a/tests/DependencyInjection/ConfigurationTest.php +++ b/tests/DependencyInjection/ConfigurationTest.php @@ -26,14 +26,13 @@ public function it_has_view_classes(): void 'image' => View\Image\ImageView::class, 'customer' => View\Customer\CustomerView::class, 'address' => View\AddressView::class, - 'shipping_method' => View\ShippingMethodView::class, - 'shipment' => View\ShipmentView::class, + 'shipping_method' => View\Shipping\ShippingMethodView::class, + 'shipment' => View\Shipping\ShipmentView::class, + 'shipment_unit' => View\Shipping\ShipmentUnitView::class, 'payment_method' => View\PaymentMethodView::class, 'payment' => View\PaymentView::class, 'adjustment' => View\Order\AdjustmentView::class, 'order' => View\Order\OrderView::class, - 'order_item' => View\Order\ItemView::class, - 'order_item_unit' => View\Order\ItemUnitView::class, 'product_variant' => View\Product\ProductVariantView::class, ], ], 'view_classes'); diff --git a/tests/DependencyInjection/SetonoSyliusLagersystemExtensionTest.php b/tests/DependencyInjection/SetonoSyliusLagersystemExtensionTest.php index b6d3c71..352eaf0 100644 --- a/tests/DependencyInjection/SetonoSyliusLagersystemExtensionTest.php +++ b/tests/DependencyInjection/SetonoSyliusLagersystemExtensionTest.php @@ -23,14 +23,13 @@ public function it_defines_view_classes_parameters(): void 'image' => View\Image\ImageView::class, 'customer' => View\Customer\CustomerView::class, 'address' => View\AddressView::class, - 'shipping_method' => View\ShippingMethodView::class, - 'shipment' => View\ShipmentView::class, + 'shipping_method' => View\Shipping\ShippingMethodView::class, + 'shipment' => View\Shipping\ShipmentView::class, + 'shipment_unit' => View\Shipping\ShipmentUnitView::class, 'payment_method' => View\PaymentMethodView::class, 'payment' => View\PaymentView::class, 'adjustment' => View\Order\AdjustmentView::class, 'order' => View\Order\OrderView::class, - 'order_item' => View\Order\ItemView::class, - 'order_item_unit' => View\Order\ItemUnitView::class, 'product_variant' => View\Product\ProductVariantView::class, ]; diff --git a/tests/Responses/Expected/order/order_index_response.json b/tests/Responses/Expected/order/order_index_response.json deleted file mode 100644 index c7f2bfd..0000000 --- a/tests/Responses/Expected/order/order_index_response.json +++ /dev/null @@ -1,190 +0,0 @@ -{ - "page": 1, - "limit": 10, - "pages": 1, - "total": 2, - "links": { - "self": "/api/lagersystem/orders?page=1&limit=10", - "first": "/api/lagersystem/orders?page=1&limit=10", - "last": "/api/lagersystem/orders?page=1&limit=10", - "next": "/api/lagersystem/orders?page=1&limit=10" - }, - "items": [ - { - "id": @integer@, - "number": "000000001", - "channel": "US_WEB", - "currencyCode": "USD", - "localeCode": "en_US", - "state": "new", - "checkoutState": "completed", - "checkoutCompletedAt": "@string@.isDateTime()", - "paymentState": "authorized", - "payments": [ - { - "state": "authorized", - "method": { - "code": "cash_on_delivery", - "name": "Cash on delivery", - "description": "@string@" - } - } - ], - "shippingState": "ready", - "shipments": [ - { - "state": "ready", - "method": { - "code": "UPS", - "name": "UPS", - "description": "@string@" - } - } - ], - "shippingAddress": { - "firstName": "Igor", - "lastName": "Mukhin", - "countryCode": "UA", - "street": "Main street", - "city": "Odesa", - "postcode": "65000", - "phoneNumber": "380951234567" - }, - "billingAddress": { - "firstName": "Igor", - "lastName": "Mukhin", - "countryCode": "UA", - "street": "Main street", - "city": "Odesa", - "postcode": "65000", - "phoneNumber": "380951234567" - }, - "items": [ - { - "id": @integer@, - "quantity": 3, - "total": 5799, - "variant": { - "id": @integer@, - "code": "red-mug", - "name": "Red Mug", - "barcode": "7891000074237", - "weight": 125, - "onHand": 7, - "images": [ - { - "type": "thumbnail", - "path": "/pants.jpeg", - "cachedPath": "http://localhost/media/cache/setono_sylius_lagersystem/pants.jpeg" - } - ] - }, - "units": [ - { - "total": 1999, - "adjustmentsTotal": 0 - }, - { - "total": 1900, - "adjustmentsTotal": -99 - }, - { - "total": 1900, - "adjustmentsTotal": -99 - } - ] - } - ], - "adjustments": { - "UPS": { - "amount": 500, - "neutral": false - }, - "TAX_EU": { - "amount": 399, - "neutral": true - }, - "PROMO_UNIT_X": { - "amount": -198, - "neutral": false - } - }, - "total": 6299, - "adjustmentsTotal": 302, - "customer": { - "id": @integer@, - "firstName": "Igor", - "lastName": "Mukhin", - "email": "igor.mukhin@gmail.com", - "birthday": "@string@.isDateTime()", - "gender": "m", - "phoneNumber": "380951234567" - } - }, - { - "id": @integer@, - "number": "000000002", - "channel": "US_WEB", - "currencyCode": "USD", - "localeCode": "en_US", - "state": "fulfilled", - "checkoutState": "completed", - "checkoutCompletedAt": "@string@.isDateTime()", - "paymentState": "paid", - "payments": [ - { - "state": "completed", - "method": { - "code": "cash_on_delivery", - "name": "Cash on delivery", - "description": "@string@" - } - } - ], - "shippingState": "partially_shipped", - "shipments": [ - { - "state": "partially_shipped", - "method": { - "code": "UPS", - "name": "UPS", - "description": "@string@" - } - } - ], - "shippingAddress": { - "firstName": "Joachim", - "lastName": "Loevgaard", - "countryCode": "DK", - "street": "Main street", - "city": "Aalborg", - "postcode": "123456", - "company": "Setono", - "phoneNumber": "4512345678" - }, - "billingAddress": { - "firstName": "Joachim", - "lastName": "Loevgaard", - "countryCode": "DK", - "street": "Main street", - "city": "Aalborg", - "postcode": "123456", - "company": "Setono", - "phoneNumber": "4512345678" - }, - "items": [], - "adjustments": [], - "total": 0, - "adjustmentsTotal": 0, - "customer": { - "id": @integer@, - "firstName": "Igor", - "lastName": "Mukhin", - "email": "igor.mukhin@gmail.com", - "birthday": "@string@.isDateTime()", - "gender": "m", - "phoneNumber": "380951234567" - } - } - ] -} diff --git a/tests/Responses/Expected/shipment/shipment_index_response.json b/tests/Responses/Expected/shipment/shipment_index_response.json new file mode 100644 index 0000000..2bd050a --- /dev/null +++ b/tests/Responses/Expected/shipment/shipment_index_response.json @@ -0,0 +1,191 @@ +{ + "page": 1, + "limit": 10, + "pages": 1, + "total": 2, + "links": { + "self": "/api/lagersystem/shipments?locale=en_US&page=1&limit=10", + "first": "/api/lagersystem/shipments?locale=en_US&page=1&limit=10", + "last": "/api/lagersystem/shipments?locale=en_US&page=1&limit=10", + "next": "/api/lagersystem/shipments?locale=en_US&page=1&limit=10" + }, + "items": [ + { + "id": @integer@, + "state": "ready", + "method": { + "code": "UPS", + "name": "UPS", + "description": "@string@" + }, + "order": { + "id": @integer@, + "number": "000000001", + "channel": "US_WEB", + "currencyCode": "USD", + "localeCode": "en_US", + "state": "new", + "checkoutState": "completed", + "checkoutCompletedAt": "@string@.isDateTime()", + "paymentState": "authorized", + "payments": [ + { + "state": "authorized", + "method": { + "code": "cash_on_delivery", + "name": "Cash on delivery", + "description": "@string@" + } + } + ], + "shippingAddress": { + "firstName": "Igor", + "lastName": "Mukhin", + "countryCode": "UA", + "street": "Main street", + "city": "Odesa", + "postcode": "65000", + "phoneNumber": "380951234567" + }, + "billingAddress": { + "firstName": "Igor", + "lastName": "Mukhin", + "countryCode": "UA", + "street": "Main street", + "city": "Odesa", + "postcode": "65000", + "phoneNumber": "380951234567" + }, + "adjustments": { + "UPS": { + "amount": 500, + "neutral": false + }, + "TAX_EU": { + "amount": 399, + "neutral": true + }, + "PROMO_UNIT_X": { + "amount": -198, + "neutral": false + } + }, + "itemsTotal": 3800, + "total": 4300, + "adjustmentsTotal": 302, + "customer": { + "id": @integer@, + "firstName": "Igor", + "lastName": "Mukhin", + "email": "igor.mukhin@gmail.com", + "birthday": "@string@.isDateTime()", + "gender": "m", + "phoneNumber": "380951234567" + } + }, + "units": [ + { + "shippable": { + "id": @integer@, + "code": "red-mug", + "name": "Red Mug", + "barcode": "7891000074237", + "weight": 125, + "onHand": 7, + "images": [ + { + "type": "thumbnail", + "path": "/pants.jpeg", + "cachedPath": "http://localhost/media/cache/setono_sylius_lagersystem/pants.jpeg" + } + ] + }, + "total": 1900, + "adjustmentsTotal": -99 + }, + { + "shippable": { + "id": @integer@, + "code": "red-mug", + "name": "Red Mug", + "barcode": "7891000074237", + "weight": 125, + "onHand": 7, + "images": [ + { + "type": "thumbnail", + "path": "/pants.jpeg", + "cachedPath": "http://localhost/media/cache/setono_sylius_lagersystem/pants.jpeg" + } + ] + }, + "total": 1900, + "adjustmentsTotal": -99 + } + ] + }, + { + "id": @integer@, + "state": "partially_shipped", + "method": { + "code": "UPS", + "name": "UPS", + "description": "@string@" + }, + "order": { + "id": @integer@, + "number": "000000002", + "channel": "US_WEB", + "currencyCode": "USD", + "localeCode": "en_US", + "state": "fulfilled", + "checkoutState": "completed", + "checkoutCompletedAt": "@string@.isDateTime()", + "paymentState": "paid", + "payments": [ + { + "state": "completed", + "method": { + "code": "cash_on_delivery", + "name": "Cash on delivery", + "description": "@string@" + } + } + ], + "shippingAddress": { + "firstName": "Joachim", + "lastName": "Loevgaard", + "countryCode": "DK", + "street": "Main street", + "city": "Aalborg", + "postcode": "123456", + "company": "Setono", + "phoneNumber": "4512345678" + }, + "billingAddress": { + "firstName": "Joachim", + "lastName": "Loevgaard", + "countryCode": "DK", + "street": "Main street", + "city": "Aalborg", + "postcode": "123456", + "company": "Setono", + "phoneNumber": "4512345678" + }, + "adjustments": [], + "itemsTotal": 0, + "total": 0, + "adjustmentsTotal": 0, + "customer": { + "id": @integer@, + "firstName": "Igor", + "lastName": "Mukhin", + "email": "igor.mukhin@gmail.com", + "birthday": "@string@.isDateTime()", + "gender": "m", + "phoneNumber": "380951234567" + } + } + } + ] +}