Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,8 @@ indent_size = 4

[phpunit.xml{,.dist}]
indent_style = space
indent_size = 4
indent_size = 4

[tests/Responses/Expected/**/*.json]
Comment thread
igormukhingmailcom marked this conversation as resolved.
indent_style = space
indent_size = 4
2 changes: 2 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ build:
environment:
variables:
COMPOSER_MEMORY_LIMIT: -1
php:
version: 7.4

filter:
excluded_paths: [tests/*, spec/*]
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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"
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 3 additions & 4 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
29 changes: 0 additions & 29 deletions src/Factory/Order/ItemUnitViewFactory.php

This file was deleted.

13 changes: 0 additions & 13 deletions src/Factory/Order/ItemUnitViewFactoryInterface.php

This file was deleted.

55 changes: 0 additions & 55 deletions src/Factory/Order/ItemViewFactory.php

This file was deleted.

13 changes: 0 additions & 13 deletions src/Factory/Order/ItemViewFactoryInterface.php

This file was deleted.

28 changes: 1 addition & 27 deletions src/Factory/Order/OrderViewFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
use Setono\SyliusLagersystemPlugin\Factory\Address\AddressViewFactoryInterface;
use Setono\SyliusLagersystemPlugin\Factory\Customer\CustomerViewFactoryInterface;
use Setono\SyliusLagersystemPlugin\Factory\PaymentViewFactoryInterface;
use Setono\SyliusLagersystemPlugin\Factory\ShipmentViewFactoryInterface;
use Setono\SyliusLagersystemPlugin\View\Order\OrderView;
use Sylius\Component\Core\Model\AdjustmentInterface;
use Sylius\Component\Core\Model\CustomerInterface;
use Sylius\Component\Core\Model\OrderInterface;
use Sylius\Component\Core\Model\OrderItemInterface;
use Sylius\Component\Core\Model\PaymentInterface;
use Sylius\Component\Core\Model\ShipmentInterface;
use Webmozart\Assert\Assert;

class OrderViewFactory implements OrderViewFactoryInterface
Expand All @@ -25,36 +22,26 @@ class OrderViewFactory implements OrderViewFactoryInterface
/** @var AddressViewFactoryInterface */
protected $addressViewFactory;

/** @var ShipmentViewFactoryInterface */
protected $shipmentViewFactory;

/** @var PaymentViewFactoryInterface */
protected $paymentViewFactory;

/** @var AdjustmentViewFactoryInterface */
protected $adjustmentViewFactory;

/** @var ItemViewFactoryInterface */
protected $itemFactory;

/** @var string */
protected $orderViewClass;

public function __construct(
CustomerViewFactoryInterface $customerViewFactory,
AddressViewFactoryInterface $addressViewFactory,
ShipmentViewFactoryInterface $shipmentViewFactory,
PaymentViewFactoryInterface $paymentViewFactory,
AdjustmentViewFactoryInterface $adjustmentViewFactory,
ItemViewFactoryInterface $itemFactory,
string $orderViewClass
) {
$this->customerViewFactory = $customerViewFactory;
$this->addressViewFactory = $addressViewFactory;
$this->shipmentViewFactory = $shipmentViewFactory;
$this->paymentViewFactory = $paymentViewFactory;
$this->adjustmentViewFactory = $adjustmentViewFactory;
$this->itemFactory = $itemFactory;
$this->orderViewClass = $orderViewClass;
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);

Expand Down
39 changes: 0 additions & 39 deletions src/Factory/ShipmentViewFactory.php

This file was deleted.

47 changes: 47 additions & 0 deletions src/Factory/Shipping/ShipmentUnitViewFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace Setono\SyliusLagersystemPlugin\Factory\Shipping;

use Setono\SyliusLagersystemPlugin\Factory\Product\ProductVariantViewFactoryInterface;
use Setono\SyliusLagersystemPlugin\View\Shipping\ShipmentUnitView;
use Sylius\Component\Core\Model\OrderItemUnitInterface;
use Sylius\Component\Core\Model\ProductVariantInterface;
use Sylius\Component\Shipping\Model\ShipmentUnitInterface;
use Webmozart\Assert\Assert;

class ShipmentUnitViewFactory implements ShipmentUnitViewFactoryInterface
{
/** @var ProductVariantViewFactoryInterface */
protected $shippableViewFactory;

/** @var string */
protected $shipmentUnitViewClass;

public function __construct(
ProductVariantViewFactoryInterface $shippableViewFactory,
string $shipmentUnitViewClass
) {
$this->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;
}
}
Loading