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
60 changes: 60 additions & 0 deletions src/ApiPlatform/Resources/Order/Order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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';
}
74 changes: 74 additions & 0 deletions src/ApiPlatform/Resources/Order/OrderAddress.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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;
}
76 changes: 76 additions & 0 deletions src/ApiPlatform/Resources/Order/OrderCartRule.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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;
}
61 changes: 61 additions & 0 deletions src/ApiPlatform/Resources/Order/OrderCurrency.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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;
}
55 changes: 55 additions & 0 deletions src/ApiPlatform/Resources/Order/OrderDuplicate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Copyright since 2007 PrestaShop SA and Contributors
* PrestaShop is an International Registered Trademark & Property of PrestaShop SA
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License version 3.0
* that is bundled with this package in the file LICENSE.md.
* It is also available through the world-wide-web at this URL:
* https://opensource.org/licenses/AFL-3.0
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* @author PrestaShop SA and Contributors <contact@prestashop.com>
* @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;
}
Loading
Loading