diff --git a/src/ApiPlatform/Resources/Order/Order.php b/src/ApiPlatform/Resources/Order/Order.php new file mode 100644 index 00000000..8d1cecb3 --- /dev/null +++ b/src/ApiPlatform/Resources/Order/Order.php @@ -0,0 +1,60 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Order; + +use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderConstraintException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException; +use PrestaShop\PrestaShop\Core\Domain\Order\Query\GetOrderForViewing; +use PrestaShop\PrestaShop\Core\Domain\Order\Query\GetOrderPreview; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet; +use Symfony\Component\HttpFoundation\Response; + +#[ApiResource( + operations: [ + new CQRSGet( + uriTemplate: '/orders/{orderId}', + requirements: ['orderId' => '\d+'], + CQRSQuery: GetOrderForViewing::class, + scopes: ['order_read'], + ), + new CQRSGet( + uriTemplate: '/orders/{orderId}/previews', + requirements: ['orderId' => '\d+'], + CQRSQuery: GetOrderPreview::class, + scopes: ['order_read'], + ), + ], + exceptionToStatus: [ + OrderNotFoundException::class => Response::HTTP_NOT_FOUND, + OrderConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ], +)] +class Order +{ + #[ApiProperty(identifier: true)] + public int $orderId; + + public string $productsSorting = 'ASC'; +} diff --git a/src/ApiPlatform/Resources/Order/OrderAddress.php b/src/ApiPlatform/Resources/Order/OrderAddress.php new file mode 100644 index 00000000..81f19bbb --- /dev/null +++ b/src/ApiPlatform/Resources/Order/OrderAddress.php @@ -0,0 +1,74 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Order; + +use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\ChangeOrderDeliveryAddressCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\ChangeOrderInvoiceAddressCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\CannotUpdateOrderException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\InvalidAddressTypeException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderConstraintException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Validator\Constraints as Assert; + +#[ApiResource( + operations: [ + new CQRSUpdate( + uriTemplate: '/orders/{orderId}/delivery-addresses', + requirements: ['orderId' => '\d+'], + output: false, + CQRSCommand: ChangeOrderDeliveryAddressCommand::class, + scopes: ['order_write'], + CQRSCommandMapping: [ + '[addressId]' => '[newDeliveryAddressId]', + ], + ), + new CQRSUpdate( + uriTemplate: '/orders/{orderId}/invoice-addresses', + requirements: ['orderId' => '\d+'], + output: false, + CQRSCommand: ChangeOrderInvoiceAddressCommand::class, + scopes: ['order_write'], + CQRSCommandMapping: [ + '[addressId]' => '[newInvoiceAddressId]', + ], + ), + ], + exceptionToStatus: [ + OrderNotFoundException::class => Response::HTTP_NOT_FOUND, + OrderConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + CannotUpdateOrderException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + InvalidAddressTypeException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ], +)] +class OrderAddress +{ + #[ApiProperty(identifier: true)] + public int $orderId; + + #[Assert\NotBlank] + public int $addressId; +} diff --git a/src/ApiPlatform/Resources/Order/OrderCartRule.php b/src/ApiPlatform/Resources/Order/OrderCartRule.php new file mode 100644 index 00000000..4e68f7b8 --- /dev/null +++ b/src/ApiPlatform/Resources/Order/OrderCartRule.php @@ -0,0 +1,76 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Order; + +use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\AddCartRuleToOrderCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\DeleteCartRuleFromOrderCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\CannotUpdateOrderException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderConstraintException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Validator\Constraints as Assert; + +#[ApiResource( + operations: [ + new CQRSCreate( + uriTemplate: '/orders/{orderId}/cart-rules', + requirements: ['orderId' => '\d+'], + output: false, + CQRSCommand: AddCartRuleToOrderCommand::class, + scopes: ['order_write'], + ), + new CQRSDelete( + uriTemplate: '/orders/{orderId}/cart-rules/{orderCartRuleId}', + requirements: ['orderId' => '\d+', 'orderCartRuleId' => '\d+'], + CQRSCommand: DeleteCartRuleFromOrderCommand::class, + scopes: ['order_write'], + ), + ], + exceptionToStatus: [ + OrderNotFoundException::class => Response::HTTP_NOT_FOUND, + OrderConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + CannotUpdateOrderException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ], +)] +class OrderCartRule +{ + #[ApiProperty(identifier: true)] + public int $orderId; + + public int $orderCartRuleId; + + #[Assert\NotBlank] + public string $cartRuleName; + + #[Assert\NotBlank] + #[Assert\Choice(choices: ['discount_percent', 'discount_amount', 'free_shipping'])] + public string $cartRuleType; + + public ?string $value = null; + + public ?int $orderInvoiceId = null; +} diff --git a/src/ApiPlatform/Resources/Order/OrderCurrency.php b/src/ApiPlatform/Resources/Order/OrderCurrency.php new file mode 100644 index 00000000..5e092baa --- /dev/null +++ b/src/ApiPlatform/Resources/Order/OrderCurrency.php @@ -0,0 +1,61 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Order; + +use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\ChangeOrderCurrencyCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\CannotUpdateOrderException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderConstraintException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Validator\Constraints as Assert; + +#[ApiResource( + operations: [ + new CQRSUpdate( + uriTemplate: '/orders/{orderId}/currencies', + requirements: ['orderId' => '\d+'], + output: false, + CQRSCommand: ChangeOrderCurrencyCommand::class, + scopes: ['order_write'], + CQRSCommandMapping: [ + '[currencyId]' => '[newCurrencyId]', + ], + ), + ], + exceptionToStatus: [ + OrderNotFoundException::class => Response::HTTP_NOT_FOUND, + OrderConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + CannotUpdateOrderException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ], +)] +class OrderCurrency +{ + #[ApiProperty(identifier: true)] + public int $orderId; + + #[Assert\NotBlank] + public int $currencyId; +} diff --git a/src/ApiPlatform/Resources/Order/OrderDuplicate.php b/src/ApiPlatform/Resources/Order/OrderDuplicate.php new file mode 100644 index 00000000..4d21d6c0 --- /dev/null +++ b/src/ApiPlatform/Resources/Order/OrderDuplicate.php @@ -0,0 +1,55 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Order; + +use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\DuplicateOrderCartCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\DuplicateOrderCartException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderConstraintException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate; +use Symfony\Component\HttpFoundation\Response; + +#[ApiResource( + operations: [ + new CQRSCreate( + uriTemplate: '/orders/{orderId}/duplicate-carts', + requirements: ['orderId' => '\d+'], + CQRSCommand: DuplicateOrderCartCommand::class, + scopes: ['order_write'], + ), + ], + exceptionToStatus: [ + OrderNotFoundException::class => Response::HTTP_NOT_FOUND, + OrderConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + DuplicateOrderCartException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ], +)] +class OrderDuplicate +{ + #[ApiProperty(identifier: true)] + public int $orderId; + + public ?int $cartId = null; +} diff --git a/src/ApiPlatform/Resources/Order/OrderEmail.php b/src/ApiPlatform/Resources/Order/OrderEmail.php new file mode 100644 index 00000000..a49d338d --- /dev/null +++ b/src/ApiPlatform/Resources/Order/OrderEmail.php @@ -0,0 +1,71 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Order; + +use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\ResendOrderEmailCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\SendProcessOrderEmailCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderConstraintException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderEmailSendException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Validator\Constraints as Assert; + +#[ApiResource( + operations: [ + new CQRSCreate( + uriTemplate: '/orders/{orderId}/resend-emails', + requirements: ['orderId' => '\d+'], + output: false, + CQRSCommand: ResendOrderEmailCommand::class, + scopes: ['order_write'], + ), + new CQRSCreate( + uriTemplate: '/orders/{cartId}/send-process-order-emails', + requirements: ['cartId' => '\d+'], + output: false, + CQRSCommand: SendProcessOrderEmailCommand::class, + scopes: ['order_write'], + ), + ], + exceptionToStatus: [ + OrderNotFoundException::class => Response::HTTP_NOT_FOUND, + OrderConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + OrderEmailSendException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ], +)] +class OrderEmail +{ + #[ApiProperty(identifier: true)] + public int $orderId; + + public int $cartId; + + #[Assert\NotBlank] + public int $orderStatusId; + + #[Assert\NotBlank] + public int $orderHistoryId; +} diff --git a/src/ApiPlatform/Resources/Order/OrderFromBackOffice.php b/src/ApiPlatform/Resources/Order/OrderFromBackOffice.php new file mode 100644 index 00000000..419679a8 --- /dev/null +++ b/src/ApiPlatform/Resources/Order/OrderFromBackOffice.php @@ -0,0 +1,61 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Order; + +use ApiPlatform\Metadata\ApiResource; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\AddOrderFromBackOfficeCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderConstraintException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Validator\Constraints as Assert; + +#[ApiResource( + operations: [ + new CQRSCreate( + uriTemplate: '/orders', + CQRSCommand: AddOrderFromBackOfficeCommand::class, + scopes: ['order_write'], + ), + ], + exceptionToStatus: [ + OrderNotFoundException::class => Response::HTTP_NOT_FOUND, + OrderConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ], +)] +class OrderFromBackOffice +{ + #[Assert\NotBlank] + public int $cartId; + + #[Assert\NotBlank] + public int $employeeId; + + public string $orderMessage = ''; + + #[Assert\NotBlank] + public string $paymentModuleName; + + #[Assert\NotBlank] + public int $orderStateId; +} diff --git a/src/ApiPlatform/Resources/Order/OrderNote.php b/src/ApiPlatform/Resources/Order/OrderNote.php new file mode 100644 index 00000000..438eeafd --- /dev/null +++ b/src/ApiPlatform/Resources/Order/OrderNote.php @@ -0,0 +1,58 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Order; + +use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\SetInternalOrderNoteCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\CannotUpdateOrderException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderConstraintException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Validator\Constraints as Assert; + +#[ApiResource( + operations: [ + new CQRSUpdate( + uriTemplate: '/orders/{orderId}/notes', + requirements: ['orderId' => '\d+'], + output: false, + CQRSCommand: SetInternalOrderNoteCommand::class, + scopes: ['order_write'], + ), + ], + exceptionToStatus: [ + OrderNotFoundException::class => Response::HTTP_NOT_FOUND, + OrderConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + CannotUpdateOrderException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ], +)] +class OrderNote +{ + #[ApiProperty(identifier: true)] + public int $orderId; + + #[Assert\NotBlank] + public string $internalNote; +} diff --git a/src/ApiPlatform/Resources/Order/OrderProductCancel.php b/src/ApiPlatform/Resources/Order/OrderProductCancel.php new file mode 100644 index 00000000..2d4d029a --- /dev/null +++ b/src/ApiPlatform/Resources/Order/OrderProductCancel.php @@ -0,0 +1,63 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Order; + +use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\CancelOrderProductCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\CancelProductFromOrderException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\InvalidCancelProductException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderConstraintException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Validator\Constraints as Assert; + +#[ApiResource( + operations: [ + new CQRSCreate( + uriTemplate: '/orders/{orderId}/cancel-products', + requirements: ['orderId' => '\d+'], + output: false, + CQRSCommand: CancelOrderProductCommand::class, + scopes: ['order_write'], + ), + ], + exceptionToStatus: [ + OrderNotFoundException::class => Response::HTTP_NOT_FOUND, + OrderConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + CancelProductFromOrderException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + InvalidCancelProductException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ], +)] +class OrderProductCancel +{ + #[ApiProperty(identifier: true)] + public int $orderId; + + /** + * @var array Array of [orderDetailId => quantity] + */ + #[Assert\NotBlank] + public array $cancelledProducts; +} diff --git a/src/ApiPlatform/Resources/Order/OrderProducts.php b/src/ApiPlatform/Resources/Order/OrderProducts.php new file mode 100644 index 00000000..364ec744 --- /dev/null +++ b/src/ApiPlatform/Resources/Order/OrderProducts.php @@ -0,0 +1,57 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Order; + +use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderConstraintException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException; +use PrestaShop\PrestaShop\Core\Domain\Order\Query\GetOrderProductsForViewing; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet; +use Symfony\Component\HttpFoundation\Response; + +#[ApiResource( + operations: [ + new CQRSGet( + uriTemplate: '/orders/{orderId}/products', + requirements: ['orderId' => '\d+'], + CQRSQuery: GetOrderProductsForViewing::class, + scopes: ['order_read'], + ), + ], + exceptionToStatus: [ + OrderNotFoundException::class => Response::HTTP_NOT_FOUND, + OrderConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ], +)] +class OrderProducts +{ + #[ApiProperty(identifier: true)] + public int $orderId; + + public int $offset = 0; + + public int $limit = 10; + + public string $productsSorting = 'ASC'; +} diff --git a/src/ApiPlatform/Resources/Order/OrderRefund.php b/src/ApiPlatform/Resources/Order/OrderRefund.php new file mode 100644 index 00000000..39f6885c --- /dev/null +++ b/src/ApiPlatform/Resources/Order/OrderRefund.php @@ -0,0 +1,92 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Order; + +use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\IssuePartialRefundCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\IssueReturnProductCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\IssueStandardRefundCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\InvalidAmountException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\InvalidRefundException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderConstraintException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\ReturnProductDisabledException; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Validator\Constraints as Assert; + +#[ApiResource( + operations: [ + new CQRSCreate( + uriTemplate: '/orders/{orderId}/refunds/standards', + requirements: ['orderId' => '\d+'], + output: false, + CQRSCommand: IssueStandardRefundCommand::class, + scopes: ['order_write'], + ), + new CQRSCreate( + uriTemplate: '/orders/{orderId}/refunds/partials', + requirements: ['orderId' => '\d+'], + output: false, + CQRSCommand: IssuePartialRefundCommand::class, + scopes: ['order_write'], + ), + new CQRSCreate( + uriTemplate: '/orders/{orderId}/refunds/returns', + requirements: ['orderId' => '\d+'], + output: false, + CQRSCommand: IssueReturnProductCommand::class, + scopes: ['order_write'], + ), + ], + exceptionToStatus: [ + OrderNotFoundException::class => Response::HTTP_NOT_FOUND, + OrderConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + InvalidRefundException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + InvalidAmountException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ReturnProductDisabledException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ], +)] +class OrderRefund +{ + #[ApiProperty(identifier: true)] + public int $orderId; + + #[Assert\NotBlank] + public array $orderDetailRefunds; + + public bool $refundShippingCost = false; + + public string $shippingCostRefundAmount = '0'; + + public bool $restockRefundedProducts = false; + + public bool $generateCreditSlip = false; + + public bool $generateVoucher = false; + + public int $voucherRefundType = 0; + + public ?string $voucherRefundAmount = null; +} diff --git a/src/ApiPlatform/Resources/Order/OrderShipping.php b/src/ApiPlatform/Resources/Order/OrderShipping.php new file mode 100644 index 00000000..04979e5e --- /dev/null +++ b/src/ApiPlatform/Resources/Order/OrderShipping.php @@ -0,0 +1,63 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Order; + +use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\UpdateOrderShippingDetailsCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\CannotUpdateOrderException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderConstraintException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Validator\Constraints as Assert; + +#[ApiResource( + operations: [ + new CQRSUpdate( + uriTemplate: '/orders/{orderId}/shippings', + requirements: ['orderId' => '\d+'], + output: false, + CQRSCommand: UpdateOrderShippingDetailsCommand::class, + scopes: ['order_write'], + ), + ], + exceptionToStatus: [ + OrderNotFoundException::class => Response::HTTP_NOT_FOUND, + OrderConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + CannotUpdateOrderException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ], +)] +class OrderShipping +{ + #[ApiProperty(identifier: true)] + public int $orderId; + + #[Assert\NotBlank] + public int $currentOrderCarrierId; + + #[Assert\NotBlank] + public int $newCarrierId; + + public ?string $trackingNumber = null; +} diff --git a/src/ApiPlatform/Resources/Order/OrderStatus.php b/src/ApiPlatform/Resources/Order/OrderStatus.php new file mode 100644 index 00000000..d39102ee --- /dev/null +++ b/src/ApiPlatform/Resources/Order/OrderStatus.php @@ -0,0 +1,79 @@ + + * @copyright Since 2007 PrestaShop SA and Contributors + * @license https://opensource.org/licenses/AFL-3.0 Academic Free License version 3.0 + */ + +declare(strict_types=1); + +namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Order; + +use ApiPlatform\Metadata\ApiProperty; +use ApiPlatform\Metadata\ApiResource; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\BulkChangeOrderStatusCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Command\UpdateOrderStatusCommand; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\ChangeOrderStatusException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\InvalidOrderStateException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderConstraintException; +use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException; +use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate; +use Symfony\Component\HttpFoundation\Response; +use Symfony\Component\Validator\Constraints as Assert; + +#[ApiResource( + operations: [ + new CQRSUpdate( + uriTemplate: '/orders/{orderId}/status', + requirements: ['orderId' => '\d+'], + output: false, + CQRSCommand: UpdateOrderStatusCommand::class, + scopes: ['order_write'], + CQRSCommandMapping: [ + '[orderStatusId]' => '[newOrderStatusId]', + ], + ), + new CQRSUpdate( + uriTemplate: '/orders/bulk-update-status', + output: false, + CQRSCommand: BulkChangeOrderStatusCommand::class, + scopes: ['order_write'], + CQRSCommandMapping: [ + '[orderStatusId]' => '[newOrderStatusId]', + ], + ), + ], + exceptionToStatus: [ + OrderNotFoundException::class => Response::HTTP_NOT_FOUND, + OrderConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ChangeOrderStatusException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + InvalidOrderStateException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ], +)] +class OrderStatus +{ + #[ApiProperty(identifier: true)] + public int $orderId; + + /** + * @var int[] + */ + #[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])] + public array $orderIds; + + #[Assert\NotBlank] + public int $orderStatusId; +}