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
59 changes: 59 additions & 0 deletions src/ApiPlatform/Resources/OrderState/BulkDeleteOrderStates.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?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\OrderState;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\OrderState\Command\BulkDeleteOrderStateCommand;
use PrestaShop\PrestaShop\Core\Domain\OrderState\Exception\BulkDeleteOrderStateException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;

#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/order-states/bulk-delete',
CQRSCommand: BulkDeleteOrderStateCommand::class,
scopes: [
'order_state_write',
],
allowEmptyBody: false,
),
],
exceptionToStatus: [
// The handler catches every OrderStateException (including "not found") and rethrows a
// single BulkDeleteOrderStateException carrying the ids it could not delete, so a
// partial failure is unprocessable rather than a 404.
BulkDeleteOrderStateException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
],
)]
class BulkDeleteOrderStates
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $orderStateIds;
}
146 changes: 146 additions & 0 deletions src/ApiPlatform/Resources/OrderState/OrderState.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?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
*/

namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\OrderState;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\DefaultLanguage;
use PrestaShop\PrestaShop\Core\Domain\OrderState\Command\AddOrderStateCommand;
use PrestaShop\PrestaShop\Core\Domain\OrderState\Command\DeleteOrderStateCommand;
use PrestaShop\PrestaShop\Core\Domain\OrderState\Command\EditOrderStateCommand;
use PrestaShop\PrestaShop\Core\Domain\OrderState\Exception\DuplicateOrderStateNameException;
use PrestaShop\PrestaShop\Core\Domain\OrderState\Exception\OrderStateConstraintException;
use PrestaShop\PrestaShop\Core\Domain\OrderState\Exception\OrderStateNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\OrderState\Query\GetOrderStateForEditing;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
use PrestaShopBundle\ApiPlatform\Metadata\LocalizedValue;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;

#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/order-states/{orderStateId}',
requirements: ['orderStateId' => '\d+'],
CQRSQuery: GetOrderStateForEditing::class,
scopes: [
'order_state_read',
],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSCreate(
uriTemplate: '/order-states',
validationContext: ['groups' => ['Default', 'Create']],
CQRSCommand: AddOrderStateCommand::class,
CQRSQuery: GetOrderStateForEditing::class,
scopes: [
'order_state_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::CREATE_COMMAND_MAPPING,
),
new CQRSPartialUpdate(
uriTemplate: '/order-states/{orderStateId}',
requirements: ['orderStateId' => '\d+'],
read: false,
CQRSCommand: EditOrderStateCommand::class,
CQRSQuery: GetOrderStateForEditing::class,
scopes: [
'order_state_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::UPDATE_COMMAND_MAPPING,
),
new CQRSDelete(
uriTemplate: '/order-states/{orderStateId}',
requirements: ['orderStateId' => '\d+'],
output: false,
CQRSCommand: DeleteOrderStateCommand::class,
scopes: [
'order_state_write',
],
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [
OrderStateNotFoundException::class => Response::HTTP_NOT_FOUND,
OrderStateConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
DuplicateOrderStateNameException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
],
)]
class OrderState
{
#[ApiProperty(identifier: true)]
public int $orderStateId;

#[LocalizedValue]
#[DefaultLanguage(groups: ['Create'], fieldName: 'names')]
#[DefaultLanguage(groups: ['Update'], fieldName: 'names', allowNull: true)]
public array $names;

#[LocalizedValue]
public array $templates;

#[Assert\NotBlank(groups: ['Create'])]
public string $color;

public bool $loggable;

public bool $invoice;

public bool $hidden;

public bool $sendEmail;

public bool $pdfInvoice;

public bool $pdfDelivery;

public bool $shipped;

public bool $paid;

public bool $delivery;

/**
* Read only: order states are soft deleted, EditableOrderState exposes isDeleted().
*/
public bool $deleted;

public const QUERY_MAPPING = [
'[localizedNames]' => '[names]',
'[localizedTemplates]' => '[templates]',
'[sendEmailEnabled]' => '[sendEmail]',
];

public const CREATE_COMMAND_MAPPING = [
'[names]' => '[localizedNames]',
'[templates]' => '[localizedTemplates]',
];

public const UPDATE_COMMAND_MAPPING = [
'[names]' => '[name]',
'[templates]' => '[template]',
];
}
56 changes: 56 additions & 0 deletions src/ApiPlatform/Resources/OrderState/OrderStateList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?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
*/

namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\OrderState;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Search\Filters\OrderStatesFilters;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;

#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/order-states',
scopes: [
'order_state_read',
],
ApiResourceMapping: self::MAPPING,
gridDataFactory: 'prestashop.core.grid.data_provider.order_states',
filtersClass: OrderStatesFilters::class,
filtersMapping: [
'[orderStateId]' => '[id_order_state]',
],
),
]
)]
class OrderStateList
{
#[ApiProperty(identifier: true)]
public int $orderStateId;

public string $name;

public string $color;

public const MAPPING = [
'[id_order_state]' => '[orderStateId]',
];
}
Loading
Loading