Subida del módulo y tema de PrestaShop

This commit is contained in:
Kaloyan
2026-04-09 18:31:51 +02:00
parent 12c253296f
commit 16b3ff9424
39262 changed files with 7418797 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
<?php
$config = new PrestaShop\CodingStandards\CsFixer\Config();
/** @var \Symfony\Component\Finder\Finder $finder */
$finder = $config->setUsingCache(true)->getFinder();
$finder->in(__DIR__)->exclude('vendor');
return $config;

4568
modules/ps_apiresources/composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?>
<module>
<name>ps_apiresources</name>
<displayName><![CDATA[PrestaShop API Resources]]></displayName>
<version><![CDATA[0.5.0]]></version>
<description><![CDATA[Includes the resources allowing using the API for the PrestaShop domain, all endpoints are based on CQRS commands/queries from the Core and we APIPlatform framework is used as a base.]]></description>
<author><![CDATA[PrestaShop]]></author>
<tab><![CDATA[administration]]></tab>
<is_configurable>0</is_configurable>
<need_instance>0</need_instance>
</module>

View File

@@ -0,0 +1,81 @@
services:
_defaults:
public: false
autowire: true
PrestaShop\Module\APIResources\List\ModuleQueryBuilder:
parent: 'prestashop.core.grid.abstract_query_builder'
autowire: true
prestashop.core.grid.data_factory.hook:
class: '%prestashop.core.grid.data.factory.doctrine_grid_data_factory%'
public: true
arguments:
- '@prestashop.core.api.query_builder.hook'
- '@prestashop.core.hook.dispatcher'
- '@prestashop.core.grid.query.doctrine_query_parser'
- 'hook'
prestashop.core.grid.data_factory.module:
class: PrestaShop\Module\APIResources\List\ModuleGridDataFactory
public: true
arguments:
- '@PrestaShop\Module\APIResources\List\ModuleQueryBuilder'
- '@prestashop.core.hook.dispatcher'
- '@prestashop.core.grid.query.doctrine_query_parser'
- 'module'
PrestaShop\Module\APIResources\Validation\IframeValidationGroupsResolver:
arguments:
- '@prestashop.adapter.legacy.configuration'
PrestaShop\Module\APIResources\Command\GenerateApiTrackingTableCommand:
tags:
- { name: 'console.command' }
# Custom normalizers for commands/queries that are very specific and cannot rely on generic solutions from the core
PrestaShop\Module\APIResources\ApiPlatform\Normalizer\GenerateCombinationsSerializer:
autowire: true
autoconfigure: true
public: false
PrestaShop\Module\APIResources\ApiPlatform\Normalizer\StateIdInterfaceNormalizer:
tags:
- { name: 'serializer.normalizer', priority: 100 }
PrestaShop\Module\APIResources\ApiPlatform\Normalizer\CountryIdNormalizer:
tags:
- { name: 'serializer.normalizer', priority: 100 }
PrestaShop\Module\APIResources\ApiPlatform\Normalizer\CartAddressNormalizer:
autowire: true
public: false
arguments:
$decorated: '@serializer.normalizer.object'
tags:
- { name: 'serializer.normalizer', priority: 300 }
PrestaShop\Module\APIResources\ApiPlatform\Normalizer\OrderAddressNormalizer:
autowire: true
public: false
arguments:
$decorated: '@serializer.normalizer.object'
PrestaShopBundle\ApiPlatform\Serializer\CQRSApiSerializer:
class: PrestaShop\Module\APIResources\Serializer\QueryParameterTypeCastSerializer
decorates: 'api_platform.serializer'
autowire: true
arguments:
$decorated: '@.inner'
PrestaShop\Module\APIResources\ApiPlatform\Processor\BulkCustomersDeleteProcessor:
tags:
- { name: 'api_platform.state_processor' }
arguments:
$commandProcessor: '@PrestaShopBundle\ApiPlatform\Processor\CommandProcessor'
PrestaShop\Module\APIResources\ApiPlatform\Normalizer\BulkDeleteCustomerCommandDenormalizer:
tags:
- { name: 'serializer.normalizer', priority: 100 }
arguments:
$denormalizer: '@PrestaShopBundle\ApiPlatform\Normalizer\CQRSApiNormalizer'

View File

@@ -0,0 +1,45 @@
<?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);
if (!defined('_PS_VERSION_')) {
exit;
}
if (file_exists(__DIR__ . '/vendor/autoload.php')) {
require_once __DIR__ . '/vendor/autoload.php';
}
class Ps_Apiresources extends Module
{
public function __construct()
{
$this->name = 'ps_apiresources';
$this->displayName = $this->trans('PrestaShop API Resources', [], 'Modules.Apiresources.Admin');
$this->description = $this->trans('Includes the resources allowing using the API for the PrestaShop domain, all endpoints are based on CQRS commands/queries from the Core and we APIPlatform framework is used as a base.', [], 'Modules.Apiresources.Admin');
$this->author = 'PrestaShop';
$this->version = '0.5.0';
$this->ps_versions_compliancy = ['min' => '9.0.3', 'max' => _PS_VERSION_];
$this->need_instance = 0;
$this->tab = 'administration';
parent::__construct();
}
}

View File

@@ -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
*/
namespace PrestaShop\Module\APIResources\ApiPlatform\Normalizer;
use PrestaShop\PrestaShop\Core\Domain\Customer\Command\BulkDeleteCustomerCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerDeleteMethod;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
/**
* Custom denormalizer for BulkDeleteCustomerCommand that injects default deleteMethod if not provided
*/
class BulkDeleteCustomerCommandDenormalizer implements DenormalizerInterface
{
public function __construct(
private readonly DenormalizerInterface $denormalizer,
) {
}
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): mixed
{
// If deleteMethod is not provided, add default value
if (is_array($data) && (!isset($data['deleteMethod']) || $data['deleteMethod'] === null || $data['deleteMethod'] === '')) {
$data['deleteMethod'] = CustomerDeleteMethod::ALLOW_CUSTOMER_REGISTRATION;
}
// Delegate to the next denormalizer
return $this->denormalizer->denormalize($data, $type, $format, $context);
}
public function supportsDenormalization(mixed $data, string $type, ?string $format = null, array $context = []): bool
{
return $type === BulkDeleteCustomerCommand::class
&& is_array($data)
&& isset($data['customerIds']);
}
public function getSupportedTypes(?string $format): array
{
return [
BulkDeleteCustomerCommand::class => false,
];
}
}

View File

@@ -0,0 +1,63 @@
<?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\Normalizer;
use PrestaShop\Module\APIResources\ApiPlatform\Resources\Address\CartAddress;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class CartAddressNormalizer implements ContextAwareNormalizerInterface
{
private const NORMALIZED_FLAG = 'cart_address_normalized';
public function __construct(
private readonly NormalizerInterface $decorated,
private readonly RequestStack $requestStack,
) {
}
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
if (!($data instanceof CartAddress)) {
return false;
}
return empty($context[self::NORMALIZED_FLAG]);
}
public function normalize(mixed $object, ?string $format = null, array $context = []): mixed
{
if ($object instanceof CartAddress) {
$request = $this->requestStack->getCurrentRequest();
if (null !== $request) {
$cartId = (int) $request->attributes->get('cartId', 0);
if ($cartId > 0) {
$object->cartId = $cartId;
}
}
}
$context[self::NORMALIZED_FLAG] = true;
return $this->decorated->normalize($object, $format, $context);
}
}

View File

@@ -0,0 +1,66 @@
<?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\Normalizer;
use PrestaShop\PrestaShop\Core\Domain\Country\ValueObject\CountryId;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* Custom normalizer for CountryId to handle the ValueObject serialization and deserialization
*/
class CountryIdNormalizer implements NormalizerInterface, DenormalizerInterface
{
public function normalize(mixed $object, ?string $format = null, array $context = []): int
{
if (!$object instanceof CountryId) {
throw new \InvalidArgumentException('Expected object to be a CountryId');
}
return $object->getValue();
}
public function supportsNormalization(mixed $data, ?string $format = null): bool
{
return $data instanceof CountryId;
}
public function getSupportedTypes(?string $format): array
{
return [
CountryId::class => true,
];
}
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): CountryId
{
if (!is_int($data)) {
throw new \InvalidArgumentException('Expected data to be an integer');
}
return new CountryId($data);
}
public function supportsDenormalization(mixed $data, string $type, ?string $format = null): bool
{
return $type === CountryId::class && is_int($data);
}
}

View File

@@ -0,0 +1,64 @@
<?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\Normalizer;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Command\GenerateProductCombinationsCommand;
use PrestaShop\PrestaShop\Core\Domain\Shop\ValueObject\ShopConstraint;
use PrestaShopBundle\ApiPlatform\Normalizer\ShopConstraintNormalizer;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
class GenerateCombinationsSerializer implements DenormalizerInterface
{
public function __construct(
private readonly ShopConstraintNormalizer $shopConstraintNormalizer,
) {
}
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = [])
{
$groupedAttributes = [];
foreach ($data['groupedAttributes'] as $attributeGroup) {
$groupedAttributes[$attributeGroup['attributeGroupId']] = array_map(static function ($attributeId): int {
return (int) $attributeId;
}, $attributeGroup['attributeIds']);
}
return new GenerateProductCombinationsCommand(
$data['productId'],
$groupedAttributes,
$this->shopConstraintNormalizer->denormalize($data['_context']['shopConstraint'], ShopConstraint::class),
);
}
public function supportsDenormalization(mixed $data, string $type, ?string $format = null)
{
return $type === GenerateProductCombinationsCommand::class;
}
public function getSupportedTypes(?string $format): array
{
return [
GenerateProductCombinationsCommand::class => true,
'object' => null,
'*' => null,
];
}
}

View File

@@ -0,0 +1,63 @@
<?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\Normalizer;
use PrestaShop\Module\APIResources\ApiPlatform\Resources\Address\OrderAddress;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\Serializer\Normalizer\ContextAwareNormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
class OrderAddressNormalizer implements ContextAwareNormalizerInterface
{
private const NORMALIZED_FLAG = 'order_address_normalized';
public function __construct(
private readonly NormalizerInterface $decorated,
private readonly RequestStack $requestStack,
) {
}
public function supportsNormalization(mixed $data, ?string $format = null, array $context = []): bool
{
if (!($data instanceof OrderAddress)) {
return false;
}
return empty($context[self::NORMALIZED_FLAG]);
}
public function normalize(mixed $object, ?string $format = null, array $context = []): mixed
{
if ($object instanceof OrderAddress) {
$request = $this->requestStack->getCurrentRequest();
if (null !== $request) {
$orderId = (int) $request->attributes->get('orderId', 0);
if ($orderId > 0) {
$object->orderId = $orderId;
}
}
}
$context[self::NORMALIZED_FLAG] = true;
return $this->decorated->normalize($object, $format, $context);
}
}

View File

@@ -0,0 +1,73 @@
<?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\Normalizer;
use PrestaShop\PrestaShop\Core\Domain\State\ValueObject\NoStateId;
use PrestaShop\PrestaShop\Core\Domain\State\ValueObject\StateId;
use PrestaShop\PrestaShop\Core\Domain\State\ValueObject\StateIdInterface;
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* Custom normalizer for StateIdInterface to handle the interface serialization and deserialization
*/
class StateIdInterfaceNormalizer implements NormalizerInterface, DenormalizerInterface
{
public function normalize(mixed $object, ?string $format = null, array $context = []): int
{
if (!$object instanceof StateIdInterface) {
throw new \InvalidArgumentException('Expected object to be a StateIdInterface');
}
return $object->getValue();
}
public function supportsNormalization(mixed $data, ?string $format = null): bool
{
return $data instanceof StateIdInterface;
}
public function getSupportedTypes(?string $format): array
{
return [
StateIdInterface::class => true,
];
}
public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []): StateIdInterface
{
if (!is_int($data) && !is_null($data)) {
throw new \InvalidArgumentException('Expected data to be an integer or null');
}
// Handle null or 0 as NoStateId
if ($data === null || $data === 0) {
return new NoStateId();
}
return new StateId($data);
}
public function supportsDenormalization(mixed $data, string $type, ?string $format = null): bool
{
return $type === StateIdInterface::class && (is_int($data) || is_null($data));
}
}

View File

@@ -0,0 +1,58 @@
<?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\Processor;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use PrestaShop\Module\APIResources\ApiPlatform\Resources\Customer\BulkCustomers;
use PrestaShop\PrestaShop\Core\Domain\Customer\Command\BulkDeleteCustomerCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerDeleteMethod;
use PrestaShopBundle\ApiPlatform\Processor\CommandProcessor;
/**
* Custom processor for BulkCustomers DELETE operation that adds default deleteMethod if not provided
*/
class BulkCustomersDeleteProcessor implements ProcessorInterface
{
public function __construct(
private readonly CommandProcessor $commandProcessor,
) {
}
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
{
$CQRSCommandClass = $operation->getExtraProperties()['CQRSCommand'] ?? null;
if ($CQRSCommandClass === BulkDeleteCustomerCommand::class) {
// If deleteMethod is not provided, add default value
if ($data instanceof BulkCustomers) {
if ($data->deleteMethod === null || $data->deleteMethod === '') {
$data->deleteMethod = CustomerDeleteMethod::ALLOW_CUSTOMER_REGISTRATION;
}
} elseif (is_array($data)) {
if (!isset($data['deleteMethod']) || $data['deleteMethod'] === null || $data['deleteMethod'] === '') {
$data['deleteMethod'] = CustomerDeleteMethod::ALLOW_CUSTOMER_REGISTRATION;
}
}
}
return $this->commandProcessor->process($data, $operation, $uriVariables, $context);
}
}

View File

@@ -0,0 +1,51 @@
<?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\Address;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Address\Command\DeleteAddressCommand;
use PrestaShop\PrestaShop\Core\Domain\Address\Exception\AddressConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Address\Exception\AddressNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/addresses/{addressId}',
requirements: ['addressId' => '\d+'],
CQRSCommand: DeleteAddressCommand::class,
scopes: [
'address_write',
],
),
],
exceptionToStatus: [
AddressConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
AddressNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class Address
{
#[ApiProperty(identifier: true)]
public int $addressId;
}

View File

@@ -0,0 +1,70 @@
<?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\Address;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Address\Exception\AddressNotFoundException;
use PrestaShop\PrestaShop\Core\Search\Filters\AddressFilters;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/addresses',
scopes: [
'address_read',
],
ApiResourceMapping: self::MAPPING,
gridDataFactory: 'prestashop.core.grid.data.factory.address',
filtersClass: AddressFilters::class,
filtersMapping: [
'[addressId]' => '[id_address]',
],
),
],
exceptionToStatus: [
AddressNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class AddressList
{
#[ApiProperty(identifier: true)]
public int $addressId;
public string $firstname;
public string $lastname;
public string $address1;
public string $postcode;
public string $city;
public string $country_name;
public const MAPPING = [
'[id_address]' => '[addressId]',
];
}

View File

@@ -0,0 +1,54 @@
<?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\Address;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Address\Command\BulkDeleteAddressCommand;
use PrestaShop\PrestaShop\Core\Domain\Address\Exception\AddressNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/addresses/bulk-delete',
CQRSCommand: BulkDeleteAddressCommand::class,
scopes: [
'address_write',
],
allowEmptyBody: false,
),
],
exceptionToStatus: [
AddressNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkAddresses
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $addressIds;
}

View File

@@ -0,0 +1,131 @@
<?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\Address;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\TypedRegex;
use PrestaShop\PrestaShop\Core\Domain\Address\Command\EditCartAddressCommand;
use PrestaShop\PrestaShop\Core\Domain\Address\Exception\AddressConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Address\Query\GetCustomerAddressForEditing;
use PrestaShop\PrestaShop\Core\Domain\Cart\Exception\CartNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Cart\Exception\InvalidAddressTypeException;
use PrestaShop\PrestaShop\Core\Domain\Country\Exception\CountryConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Country\ValueObject\CountryId;
use PrestaShop\PrestaShop\Core\Domain\State\Exception\StateConstraintException;
use PrestaShop\PrestaShop\Core\Domain\State\ValueObject\StateIdInterface;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new CQRSPartialUpdate(
uriTemplate: '/addresses/carts/{cartId}',
CQRSCommand: EditCartAddressCommand::class,
CQRSQuery: GetCustomerAddressForEditing::class,
scopes: [
'address_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
validationContext: ['groups' => ['Default', 'Update']],
),
],
exceptionToStatus: [
AddressConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
CountryConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
StateConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
InvalidAddressTypeException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
CartNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class CartAddress
{
// Identifiers from URI
#[ApiProperty(identifier: true)]
public int $cartId = 0;
public string $addressType;
// Optional address fields for update
public ?string $addressAlias = null;
public ?string $firstName = null;
public ?string $lastName = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_ADDRESS,
])]
public ?string $address = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_ADDRESS,
])]
public ?string $address2 = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_CITY_NAME,
])]
public ?string $city = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_POST_CODE,
])]
public ?string $postCode = null;
public ?CountryId $countryId = null;
public ?StateIdInterface $stateId = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_PHONE_NUMBER,
])]
public ?string $homePhone = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_PHONE_NUMBER,
])]
public ?string $mobilePhone = null;
public ?string $company = null;
public ?string $vatNumber = null;
public ?string $other = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_DNI_LITE,
])]
public ?string $dni = null;
public const QUERY_MAPPING = [
'[id]' => '[addressId]',
];
public const COMMAND_MAPPING = [
'[postCode]' => '[postcode]',
'[homePhone]' => '[phone]',
'[mobilePhone]' => '[phone_mobile]',
'[vatNumber]' => '[vat_number]',
'[stateId]' => '[id_state]',
];
}

View File

@@ -0,0 +1,152 @@
<?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\Address;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\TypedRegex;
use PrestaShop\PrestaShop\Core\Domain\Address\Command\AddCustomerAddressCommand;
use PrestaShop\PrestaShop\Core\Domain\Address\Command\EditCustomerAddressCommand;
use PrestaShop\PrestaShop\Core\Domain\Address\Exception\AddressConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Address\Exception\AddressNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Address\Query\GetCustomerAddressForEditing;
use PrestaShop\PrestaShop\Core\Domain\Country\ValueObject\CountryId;
use PrestaShop\PrestaShop\Core\Domain\State\ValueObject\StateIdInterface;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/addresses/customers/{addressId}',
CQRSQuery: GetCustomerAddressForEditing::class,
scopes: [
'address_read',
],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSCreate(
uriTemplate: '/addresses/customers',
CQRSCommand: AddCustomerAddressCommand::class,
CQRSQuery: GetCustomerAddressForEditing::class,
scopes: [
'address_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
validationContext: ['groups' => ['Default', 'Create']],
),
new CQRSPartialUpdate(
uriTemplate: '/addresses/customers/{addressId}',
CQRSCommand: EditCustomerAddressCommand::class,
CQRSQuery: GetCustomerAddressForEditing::class,
scopes: [
'address_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
validationContext: ['groups' => ['Default', 'Update']],
),
],
exceptionToStatus: [
AddressConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
AddressNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class CustomerAddress
{
#[ApiProperty(identifier: true)]
public int $addressId;
public int $customerId;
#[Assert\NotBlank(groups: ['Create'])]
public string $addressAlias;
#[Assert\NotBlank(groups: ['Create'])]
public string $firstName;
#[Assert\NotBlank(groups: ['Create'])]
public string $lastName;
#[Assert\NotBlank(groups: ['Create'])]
#[TypedRegex([
'type' => TypedRegex::TYPE_ADDRESS,
])]
public string $address;
#[TypedRegex([
'type' => TypedRegex::TYPE_ADDRESS,
])]
public ?string $address2;
#[Assert\NotBlank(groups: ['Create'])]
#[TypedRegex([
'type' => TypedRegex::TYPE_CITY_NAME,
])]
public string $city;
#[TypedRegex([
'type' => TypedRegex::TYPE_POST_CODE,
])]
public string $postCode;
#[Assert\NotBlank(groups: ['Create'])]
public CountryId $countryId;
#[TypedRegex([
'type' => TypedRegex::TYPE_DNI_LITE,
])]
public ?string $dni;
public ?string $company;
public ?string $vatNumber;
public StateIdInterface $stateId;
#[TypedRegex([
'type' => TypedRegex::TYPE_PHONE_NUMBER,
])]
public ?string $homePhone;
#[TypedRegex([
'type' => TypedRegex::TYPE_PHONE_NUMBER,
])]
public ?string $mobilePhone;
public ?string $other;
public const QUERY_MAPPING = [
'[id]' => '[addressId]',
];
public const COMMAND_MAPPING = [
'[postCode]' => '[postcode]',
'[homePhone]' => '[phone]',
'[mobilePhone]' => '[phone_mobile]',
'[vatNumber]' => '[vat_number]',
'[stateId]' => '[id_state]',
];
}

View File

@@ -0,0 +1,139 @@
<?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\Address;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\TypedRegex;
use PrestaShop\PrestaShop\Core\Domain\Address\Command\AddManufacturerAddressCommand;
use PrestaShop\PrestaShop\Core\Domain\Address\Command\EditManufacturerAddressCommand;
use PrestaShop\PrestaShop\Core\Domain\Address\Exception\AddressConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Address\Exception\AddressNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Address\Query\GetManufacturerAddressForEditing;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/addresses/manufacturers/{addressId}',
CQRSQuery: GetManufacturerAddressForEditing::class,
scopes: [
'address_read',
],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSCreate(
uriTemplate: '/addresses/manufacturers',
CQRSCommand: AddManufacturerAddressCommand::class,
CQRSQuery: GetManufacturerAddressForEditing::class,
scopes: [
'address_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
validationContext: ['groups' => ['Default', 'Create']],
),
new CQRSPartialUpdate(
uriTemplate: '/addresses/manufacturers/{addressId}',
CQRSCommand: EditManufacturerAddressCommand::class,
CQRSQuery: GetManufacturerAddressForEditing::class,
scopes: [
'address_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
validationContext: ['groups' => ['Default', 'Update']],
),
],
exceptionToStatus: [
AddressConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
AddressNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class ManufacturerAddress
{
#[ApiProperty(identifier: true)]
public int $addressId;
public ?int $manufacturerId = null;
#[Assert\NotBlank(groups: ['Create'])]
public string $lastName;
#[Assert\NotBlank(groups: ['Create'])]
public string $firstName;
#[Assert\NotBlank(groups: ['Create'])]
#[TypedRegex([
'type' => TypedRegex::TYPE_ADDRESS,
])]
public string $address;
#[TypedRegex([
'type' => TypedRegex::TYPE_ADDRESS,
])]
public ?string $address2 = null;
#[Assert\NotBlank(groups: ['Create'])]
#[TypedRegex([
'type' => TypedRegex::TYPE_CITY_NAME,
])]
public string $city;
#[TypedRegex([
'type' => TypedRegex::TYPE_POST_CODE,
])]
public ?string $postCode = null;
#[Assert\NotBlank(groups: ['Create'])]
public int $countryId;
public ?int $stateId = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_PHONE_NUMBER,
])]
public ?string $homePhone = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_PHONE_NUMBER,
])]
public ?string $mobilePhone = null;
public ?string $other = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_DNI_LITE,
])]
public ?string $dni = null;
public const QUERY_MAPPING = [
'[id]' => '[addressId]',
];
public const COMMAND_MAPPING = [
// No remapping needed for manufacturer address command
];
}

View File

@@ -0,0 +1,131 @@
<?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\Address;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\TypedRegex;
use PrestaShop\PrestaShop\Core\Domain\Address\Command\EditOrderAddressCommand;
use PrestaShop\PrestaShop\Core\Domain\Address\Exception\AddressConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Address\Query\GetCustomerAddressForEditing;
use PrestaShop\PrestaShop\Core\Domain\Country\Exception\CountryConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Country\ValueObject\CountryId;
use PrestaShop\PrestaShop\Core\Domain\Order\Exception\InvalidAddressTypeException;
use PrestaShop\PrestaShop\Core\Domain\Order\Exception\OrderNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\State\Exception\StateConstraintException;
use PrestaShop\PrestaShop\Core\Domain\State\ValueObject\StateIdInterface;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new CQRSPartialUpdate(
uriTemplate: '/addresses/orders/{orderId}',
CQRSCommand: EditOrderAddressCommand::class,
CQRSQuery: GetCustomerAddressForEditing::class,
scopes: [
'address_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
validationContext: ['groups' => ['Default', 'Update']],
),
],
exceptionToStatus: [
AddressConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
CountryConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
StateConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
InvalidAddressTypeException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
OrderNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class OrderAddress
{
// Identifiers from URI
#[ApiProperty(identifier: true)]
public int $orderId = 0;
public string $addressType;
// Optional address fields for update
public ?string $addressAlias = null;
public ?string $firstName = null;
public ?string $lastName = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_ADDRESS,
])]
public ?string $address = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_ADDRESS,
])]
public ?string $address2 = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_CITY_NAME,
])]
public ?string $city = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_POST_CODE,
])]
public ?string $postCode = null;
public ?CountryId $countryId = null;
public ?StateIdInterface $stateId = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_PHONE_NUMBER,
])]
public ?string $homePhone = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_PHONE_NUMBER,
])]
public ?string $mobilePhone = null;
public ?string $company = null;
public ?string $vatNumber = null;
public ?string $other = null;
#[TypedRegex([
'type' => TypedRegex::TYPE_DNI_LITE,
])]
public ?string $dni = null;
public const QUERY_MAPPING = [
'[id]' => '[addressId]',
];
public const COMMAND_MAPPING = [
'[postCode]' => '[postcode]',
'[homePhone]' => '[phone]',
'[mobilePhone]' => '[phone_mobile]',
'[vatNumber]' => '[vat_number]',
'[stateId]' => '[id_state]',
];
}

View File

@@ -0,0 +1,109 @@
<?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\ApiClient;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\ApiClient\ApiClientSettings;
use PrestaShop\PrestaShop\Core\Domain\ApiClient\Command\AddApiClientCommand;
use PrestaShop\PrestaShop\Core\Domain\ApiClient\Command\DeleteApiClientCommand;
use PrestaShop\PrestaShop\Core\Domain\ApiClient\Command\EditApiClientCommand;
use PrestaShop\PrestaShop\Core\Domain\ApiClient\Exception\ApiClientConstraintException;
use PrestaShop\PrestaShop\Core\Domain\ApiClient\Exception\ApiClientNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\ApiClient\Query\GetApiClientForEditing;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/api-clients/{apiClientId}',
requirements: ['apiClientId' => '\d+'],
CQRSQuery: GetApiClientForEditing::class,
scopes: ['api_client_read']
),
new CQRSDelete(
uriTemplate: '/api-clients/{apiClientId}',
requirements: ['apiClientId' => '\d+'],
output: false,
CQRSCommand: DeleteApiClientCommand::class,
scopes: ['api_client_write']
),
new CQRSCreate(
uriTemplate: '/api-clients',
validationContext: ['groups' => ['Default', 'Create']],
CQRSCommand: AddApiClientCommand::class,
scopes: ['api_client_write'],
),
new CQRSPartialUpdate(
uriTemplate: '/api-clients/{apiClientId}',
read: false,
CQRSCommand: EditApiClientCommand::class,
CQRSQuery: GetApiClientForEditing::class,
scopes: ['api_client_write']
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [
ApiClientNotFoundException::class => Response::HTTP_NOT_FOUND,
ApiClientConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
],
)]
class ApiClient
{
#[ApiProperty(identifier: true)]
public int $apiClientId;
#[Assert\NotBlank(groups: ['Create'])]
#[Assert\Length(min: 1, max: ApiClientSettings::MAX_CLIENT_ID_LENGTH)]
public string $clientId;
#[Assert\NotBlank(groups: ['Create'])]
#[Assert\Length(min: 1, max: ApiClientSettings::MAX_CLIENT_NAME_LENGTH)]
public string $clientName;
#[Assert\Length(max: ApiClientSettings::MAX_DESCRIPTION_LENGTH)]
public string $description;
public ?string $externalIssuer;
#[Assert\NotNull(groups: ['Create'])]
public bool $enabled;
#[Assert\NotBlank(groups: ['Create'])]
#[Assert\Positive]
public int $lifetime;
public array $scopes;
/**
* Only used for the return of created API Client, it is the only endpoint where the secret is returned.
*
* @var string
*/
public string $secret;
}

View File

@@ -0,0 +1,71 @@
<?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\ApiClient;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Search\Filters\ApiClientFilters;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/api-clients',
scopes: [
'api_client_read',
],
ApiResourceMapping: [
'[id_api_client]' => '[apiClientId]',
'[client_id]' => '[clientId]',
'[client_name]' => '[clientName]',
'[external_issuer]' => '[externalIssuer]',
],
gridDataFactory: 'prestashop.core.grid.data_factory.api_client',
filtersClass: ApiClientFilters::class,
filtersMapping: [
'[apiClientId]' => '[id_api_client]',
'[clientId]' => '[client_id]',
'[clientName]' => '[client_name]',
'[externalIssuer]' => '[external_issuer]',
],
),
],
normalizationContext: ['skip_null_values' => false],
)]
class ApiClientList
{
#[ApiProperty(identifier: true)]
public int $apiClientId;
public string $clientId;
public string $clientName;
public string $description;
public ?string $externalIssuer;
public bool $enabled;
public int $lifetime;
}

View File

@@ -0,0 +1,127 @@
<?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\Attribute;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\DefaultLanguage;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\TypedRegex;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Attribute\Command\AddAttributeCommand;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Attribute\Command\DeleteAttributeCommand;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Attribute\Command\EditAttributeCommand;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Attribute\Exception\AttributeConstraintException;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Attribute\Exception\AttributeNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Attribute\Query\GetAttributeForEditing;
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: '/attributes/attributes/{attributeId}',
CQRSQuery: GetAttributeForEditing::class,
scopes: [
'attribute_read',
],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSCreate(
uriTemplate: '/attributes/attributes',
validationContext: ['groups' => ['Default', 'Create']],
CQRSCommand: AddAttributeCommand::class,
CQRSQuery: GetAttributeForEditing::class,
scopes: [
'attribute_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::CREATE_COMMAND_MAPPING,
),
new CQRSPartialUpdate(
uriTemplate: '/attributes/attributes/{attributeId}',
validationContext: ['groups' => ['Default', 'Update']],
CQRSCommand: EditAttributeCommand::class,
CQRSQuery: GetAttributeForEditing::class,
scopes: [
'attribute_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::UPDATE_COMMAND_MAPPING,
),
new CQRSDelete(
uriTemplate: '/attributes/attributes/{attributeId}',
requirements: ['attributeId' => '\d+'],
CQRSCommand: DeleteAttributeCommand::class,
scopes: [
'attribute_write',
],
),
],
exceptionToStatus: [
AttributeConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
AttributeNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class Attribute
{
#[ApiProperty(identifier: true)]
public int $attributeId;
#[ApiProperty(openapiContext: ['type' => 'integer', 'example' => 1])]
public int $attributeGroupId;
#[LocalizedValue]
#[Assert\NotBlank(groups: ['Create'])]
#[DefaultLanguage(groups: ['Create'], fieldName: 'names')]
#[DefaultLanguage(groups: ['Update'], fieldName: 'names', allowNull: true)]
#[Assert\All(constraints: [
new TypedRegex([
'type' => TypedRegex::TYPE_CATALOG_NAME,
]),
])]
public array $names;
public string $color;
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank(allowNull: true)]
public array $shopIds;
public const QUERY_MAPPING = [
'[localizedNames]' => '[names]',
'[name]' => '[names]',
'[associatedShopIds]' => '[shopIds]',
];
public const CREATE_COMMAND_MAPPING = [
'[names]' => '[localizedNames]',
'[shopIds]' => '[associatedShopIds]',
];
public const UPDATE_COMMAND_MAPPING = [
'[names]' => '[localizedNames]',
'[shopIds]' => '[associatedShopIds]',
];
}

View File

@@ -0,0 +1,134 @@
<?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\Attribute;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\DefaultLanguage;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\TypedRegex;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Command\AddAttributeGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Command\DeleteAttributeGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Command\EditAttributeGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Exception\AttributeGroupConstraintException;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Exception\AttributeGroupNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Query\GetAttributeGroupForEditing;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\ValueObject\AttributeGroupType;
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: '/attributes/groups/{attributeGroupId}',
CQRSQuery: GetAttributeGroupForEditing::class,
scopes: [
'attribute_group_read',
],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSCreate(
uriTemplate: '/attributes/groups',
validationContext: ['groups' => ['Default', 'Create']],
CQRSCommand: AddAttributeGroupCommand::class,
CQRSQuery: GetAttributeGroupForEditing::class,
scopes: [
'attribute_group_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
),
new CQRSPartialUpdate(
uriTemplate: '/attributes/groups/{attributeGroupId}',
requirements: ['attributeGroupId' => '\d+'],
validationContext: ['groups' => ['Default', 'Update']],
CQRSCommand: EditAttributeGroupCommand::class,
CQRSQuery: GetAttributeGroupForEditing::class,
scopes: [
'attribute_group_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
),
new CQRSDelete(
uriTemplate: '/attributes/groups/{attributeGroupId}',
requirements: ['attributeGroupId' => '\d+'],
CQRSCommand: DeleteAttributeGroupCommand::class,
scopes: [
'attribute_group_write',
],
),
],
exceptionToStatus: [
AttributeGroupConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
AttributeGroupNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class AttributeGroup
{
#[ApiProperty(identifier: true)]
public int $attributeGroupId;
#[LocalizedValue]
#[DefaultLanguage(groups: ['Create'], fieldName: 'names')]
#[DefaultLanguage(groups: ['Update'], fieldName: 'names', allowNull: true)]
#[Assert\All(constraints: [
new TypedRegex([
'type' => TypedRegex::TYPE_CATALOG_NAME,
]),
])]
public array $names;
#[LocalizedValue]
#[DefaultLanguage(groups: ['Create'], fieldName: 'publicNames')]
#[DefaultLanguage(groups: ['Update'], fieldName: 'publicNames', allowNull: true)]
#[Assert\All(constraints: [
new TypedRegex([
'type' => TypedRegex::TYPE_CATALOG_NAME,
]),
])]
public array $publicNames;
#[Assert\Choice(choices: [AttributeGroupType::ATTRIBUTE_GROUP_TYPE_COLOR, AttributeGroupType::ATTRIBUTE_GROUP_TYPE_SELECT, AttributeGroupType::ATTRIBUTE_GROUP_TYPE_RADIO])]
public string $type;
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank(allowNull: true)]
public array $shopIds;
public int $position;
public const QUERY_MAPPING = [
'[name]' => '[names]',
'[publicName]' => '[publicNames]',
'[associatedShopIds]' => '[shopIds]',
];
public const COMMAND_MAPPING = [
'[names]' => '[localizedNames]',
'[publicNames]' => '[localizedPublicNames]',
'[shopIds]' => '[associatedShopIds]',
];
}

View File

@@ -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\Attribute;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/attributes/groups',
scopes: [
'attribute_group_read',
],
ApiResourceMapping: self::MAPPING,
gridDataFactory: 'prestashop.core.grid.data.factory.attribute_group_decorator',
filtersMapping: [
'[attributeGroupId]' => '[id_attribute_group]',
],
),
]
)]
class AttributeGroupList
{
#[ApiProperty(identifier: true)]
public int $attributeGroupId;
public string $name;
public int $values;
public int $position;
public const MAPPING = [
'[id_attribute_group]' => '[attributeGroupId]',
];
}

View File

@@ -0,0 +1,42 @@
<?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\Attribute;
use ApiPlatform\Metadata\ApiResource;
use PrestaShopBundle\ApiPlatform\Metadata\PositionCollection;
use PrestaShopBundle\ApiPlatform\Metadata\UpdatePosition;
#[ApiResource(
operations: [
new UpdatePosition(
uriTemplate: '/attributes/groups/positions',
scopes: [
'attribute_group_write',
],
positionDefinition: 'prestashop.core.grid.attribute_group.position_definition',
),
]
)]
class AttributeGroupPosition
{
#[PositionCollection(rowIdField: 'attributeGroupId')]
public array $positions;
}

View File

@@ -0,0 +1,65 @@
<?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\Attribute;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Link;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/attributes/groups/{attributeGroupId}/attributes',
scopes: [
'attribute_read',
],
uriVariables: [
'attributeGroupId' => new Link(
identifiers: ['attributeGroupId']
),
],
ApiResourceMapping: self::MAPPING,
gridDataFactory: 'prestashop.core.grid.data.factory.attribute_decorator',
filtersMapping: [
'[attributeId]' => '[id_attribute]',
],
),
]
)]
class AttributeList
{
#[ApiProperty(identifier: true)]
public int $attributeId;
#[ApiProperty(readable: false, writable: false)]
public int $attributeGroupId;
public string $name;
public int $values;
public int $position;
public const MAPPING = [
'[id_attribute]' => '[attributeId]',
];
}

View File

@@ -0,0 +1,46 @@
<?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\Attribute;
use ApiPlatform\Metadata\ApiResource;
use PrestaShopBundle\ApiPlatform\Metadata\PositionCollection;
use PrestaShopBundle\ApiPlatform\Metadata\UpdatePosition;
#[ApiResource(
operations: [
new UpdatePosition(
uriTemplate: '/attributes/groups/{attributeGroupId}/attributes/positions',
requirements: ['attributeGroupId' => '\d+'],
scopes: [
'attribute_write',
],
positionDefinition: 'prestashop.core.grid.attribute.position_definition',
parentIdField: 'attributeGroupId',
),
],
)]
class AttributePosition
{
public int $attributeGroupId;
#[PositionCollection(rowIdField: 'attributeId')]
public array $positions;
}

View File

@@ -0,0 +1,54 @@
<?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\Attribute;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Attribute\Command\BulkDeleteAttributeCommand;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Attribute\Exception\AttributeNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/attributes/attributes/bulk-delete',
CQRSCommand: BulkDeleteAttributeCommand::class,
scopes: [
'attribute_write',
],
allowEmptyBody: false,
),
],
exceptionToStatus: [
AttributeNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkAttribute
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $attributeIds;
}

View File

@@ -0,0 +1,54 @@
<?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\Attribute;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Command\BulkDeleteAttributeGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Exception\AttributeGroupNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/attributes/groups/bulk-delete',
CQRSCommand: BulkDeleteAttributeGroupCommand::class,
scopes: [
'attribute_group_write',
],
allowEmptyBody: false,
),
],
exceptionToStatus: [
AttributeGroupNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkAttributeGroups
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $attributeGroupIds;
}

View File

@@ -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
*/
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Category;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Category\Command\BulkDeleteCategoriesCommand;
use PrestaShop\PrestaShop\Core\Domain\Category\Exception\CategoryNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/categories/bulk-delete/{deleteMode}',
CQRSCommand: BulkDeleteCategoriesCommand::class,
CQRSCommandMapping: [
'[mode]' => '[deleteMode]',
],
openapiContext: [
'summary' => 'Delete a categories using a specific mode',
'parameters' => [
[
'name' => 'mode',
'in' => 'path',
'required' => true,
'schema' => [
'type' => 'string',
'enum' => ['associate_and_disable', 'associate_only', 'remove_associated'],
],
'description' => 'Delete mode: "associate_and_disable" associate products with parent category and disable them, "associate_only" associate products with parent and do not change their status, "remove_associated" remove products that are associated only with category that is being deleted',
],
],
],
scopes: [
'category_write',
],
allowEmptyBody: false,
),
],
exceptionToStatus: [
CategoryNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkDeleteCategories
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $categoryIds;
public string $deleteMode;
}

View File

@@ -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
*/
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Category;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Category\Command\BulkUpdateCategoriesStatusCommand;
use PrestaShop\PrestaShop\Core\Domain\Category\Exception\CategoryNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSUpdate(
uriTemplate: '/categories/bulk-update-status',
output: false,
CQRSCommand: BulkUpdateCategoriesStatusCommand::class,
CQRSCommandMapping: [
'[enabled]' => '[newStatus]',
],
scopes: [
'category_write',
],
),
],
exceptionToStatus: [
CategoryNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkUpdateStatusCategories
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $categoryIds;
public bool $enabled;
}

View File

@@ -0,0 +1,209 @@
<?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\Category;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\Module\APIResources\Validation\IframeValidationGroupsResolver;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\DefaultLanguage;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\TypedRegex;
use PrestaShop\PrestaShop\Core\Domain\Category\Command\AddCategoryCommand;
use PrestaShop\PrestaShop\Core\Domain\Category\Command\DeleteCategoryCoverImageCommand;
use PrestaShop\PrestaShop\Core\Domain\Category\Command\DeleteCategoryThumbnailImageCommand;
use PrestaShop\PrestaShop\Core\Domain\Category\Command\EditCategoryCommand;
use PrestaShop\PrestaShop\Core\Domain\Category\Command\SetCategoryIsEnabledCommand;
use PrestaShop\PrestaShop\Core\Domain\Category\Exception\CategoryConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Category\Exception\CategoryNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Category\Query\GetCategoryForEditing;
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: '/categories/{categoryId}',
CQRSQuery: GetCategoryForEditing::class,
scopes: [
'category_read',
],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSCreate(
uriTemplate: '/categories',
validationContext: [IframeValidationGroupsResolver::class, 'create'],
CQRSCommand: AddCategoryCommand::class,
CQRSQuery: GetCategoryForEditing::class,
scopes: [
'category_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
),
new CQRSPartialUpdate(
uriTemplate: '/categories/{categoryId}',
validationContext: [IframeValidationGroupsResolver::class, 'update'],
CQRSCommand: EditCategoryCommand::class,
CQRSQuery: GetCategoryForEditing::class,
scopes: [
'category_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
),
new CQRSPartialUpdate(
uriTemplate: '/categories/{categoryId}/status',
CQRSCommand: SetCategoryIsEnabledCommand::class,
CQRSQuery: GetCategoryForEditing::class,
scopes: [
'category_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: [
'[enabled]' => '[isEnabled]',
],
),
new CQRSDelete(
uriTemplate: '/categories/{categoryId}/cover',
CQRSCommand: DeleteCategoryCoverImageCommand::class,
scopes: [
'category_write',
],
),
new CQRSDelete(
uriTemplate: '/categories/{categoryId}/thumbnail',
CQRSCommand: DeleteCategoryThumbnailImageCommand::class,
scopes: [
'category_write',
],
),
],
exceptionToStatus: [
CategoryConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
CategoryNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class Category
{
#[ApiProperty(identifier: true)]
public int $categoryId;
public bool $enabled;
#[LocalizedValue]
#[DefaultLanguage(groups: ['Create'], fieldName: 'names')]
#[DefaultLanguage(groups: ['Update'], fieldName: 'names', allowNull: true)]
#[Assert\All(constraints: [
new TypedRegex([
'type' => TypedRegex::TYPE_CATALOG_NAME,
]),
])]
public array $names;
#[LocalizedValue]
#[DefaultLanguage(groups: ['Create'], fieldName: 'descriptions')]
#[DefaultLanguage(groups: ['Update'], fieldName: 'descriptions', allowNull: true)]
#[Assert\All(constraints: [
new TypedRegex([
'type' => TypedRegex::CLEAN_HTML_NO_IFRAME,
'groups' => ['NoIframe'],
]),
new TypedRegex([
'type' => TypedRegex::CLEAN_HTML_ALLOW_IFRAME,
'groups' => ['AllowIframe'],
]),
])]
public array $descriptions;
#[LocalizedValue]
#[DefaultLanguage(groups: ['Create'], fieldName: 'additionalDescriptions')]
#[DefaultLanguage(groups: ['Update'], fieldName: 'additionalDescriptions', allowNull: true)]
#[Assert\All(constraints: [
new TypedRegex([
'type' => TypedRegex::CLEAN_HTML_NO_IFRAME,
'groups' => ['NoIframe'],
]),
new TypedRegex([
'type' => TypedRegex::CLEAN_HTML_NO_IFRAME,
'groups' => ['AllowIframe'],
]),
])]
public array $additionalDescriptions;
#[LocalizedValue]
#[DefaultLanguage(groups: ['Create'], fieldName: 'linkRewrites')]
#[DefaultLanguage(groups: ['Update'], fieldName: 'linkRewrites', allowNull: false)]
#[Assert\All(constraints: [
new TypedRegex([
'type' => TypedRegex::TYPE_URL,
]),
])]
public array $linkRewrites;
#[LocalizedValue]
#[DefaultLanguage(groups: ['Create'], fieldName: 'metaTitles')]
#[DefaultLanguage(groups: ['Update'], fieldName: 'metaTitles', allowNull: true)]
public array $metaTitles;
#[LocalizedValue]
#[DefaultLanguage(groups: ['Create'], fieldName: 'metaDescriptions')]
#[DefaultLanguage(groups: ['Update'], fieldName: 'metaDescriptions', allowNull: true)]
public array $metaDescriptions;
public int $position;
public int $parentId;
public string $redirectType;
public ?int $redirectTarget = null;
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank(allowNull: true)]
public array $shopIds;
public const QUERY_MAPPING = [
'[id]' => '[categoryId]',
'[active]' => '[enabled]',
'[name]' => '[names]',
'[description]' => '[descriptions]',
'[additionalDescription]' => '[additionalDescriptions]',
'[associatedShopIds]' => '[shopIds]',
'[metaTitle]' => '[metaTitles]',
'[metaDescription]' => '[metaDescriptions]',
'[linkRewrite]' => '[linkRewrites]',
];
public const COMMAND_MAPPING = [
'[names]' => '[localizedNames]',
'[enabled]' => '[isEnabled]',
'[descriptions]' => '[localizedDescriptions]',
'[additionalDescriptions]' => '[localizedAdditionalDescriptions]',
'[shopIds]' => '[associatedShopIds]',
'[metaTitles]' => '[localizedMetaTitles]',
'[metaDescriptions]' => '[localizedMetaDescriptions]',
'[linkRewrites]' => '[localizedLinkRewrites]',
];
}

View File

@@ -0,0 +1,75 @@
<?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\Category;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Category\Command\DeleteCategoryCommand;
use PrestaShop\PrestaShop\Core\Domain\Category\Exception\CategoryConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Category\Exception\CategoryNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/categories/{categoryId}/{mode}',
CQRSCommand: DeleteCategoryCommand::class,
scopes: ['category_write'],
openapiContext: [
'summary' => 'Delete a category using a specific mode',
'parameters' => [
[
'name' => 'categoryId',
'in' => 'path',
'required' => true,
'schema' => ['type' => 'integer'],
'description' => 'Category ID to delete',
],
[
'name' => 'mode',
'in' => 'path',
'required' => true,
'schema' => [
'type' => 'string',
'enum' => ['associate_and_disable', 'associate_only', 'remove_associated'],
],
'description' => 'Delete mode: "associate_and_disable" associate products with parent category and disable them, "associate_only" associate products with parent and do not change their status, "remove_associated" remove products that are associated only with category that is being deleted',
],
],
],
CQRSCommandMapping: [
'[deleteMode]' => '[mode]',
],
),
],
exceptionToStatus: [
CategoryConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
CategoryNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class CategoryDelete
{
#[ApiProperty(identifier: true)]
public int $categoryId;
public string $deleteMode;
}

View File

@@ -0,0 +1,66 @@
<?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\Category;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Category\Exception\CategoryNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Shop\Exception\ShopAssociationNotFound;
use PrestaShop\PrestaShop\Core\Search\Filters\CategoryFilters;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
use PrestaShopBundle\ApiPlatform\Provider\QueryListProvider;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/categories',
provider: QueryListProvider::class,
scopes: ['category_read'],
ApiResourceMapping: [
'[id_category]' => '[categoryId]',
'[active]' => '[enabled]',
],
gridDataFactory: 'prestashop.core.grid.data.factory.category_decorator',
filtersClass: CategoryFilters::class,
filtersMapping: [
'[categoryId]' => '[id_category]',
'[enabled]' => '[active]',
],
),
],
exceptionToStatus: [
CategoryNotFoundException::class => Response::HTTP_NOT_FOUND,
ShopAssociationNotFound::class => Response::HTTP_NOT_FOUND,
],
)]
class CategoryList
{
#[ApiProperty(identifier: true)]
public int $categoryId;
public bool $enabled;
public string $name;
}

View File

@@ -0,0 +1,129 @@
<?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\Contact;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\DefaultLanguage;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\TypedRegex;
use PrestaShop\PrestaShop\Core\Domain\Contact\Command\AddContactCommand;
use PrestaShop\PrestaShop\Core\Domain\Contact\Command\EditContactCommand;
use PrestaShop\PrestaShop\Core\Domain\Contact\Exception\ContactConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Contact\Exception\ContactNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Contact\Query\GetContactForEditing;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
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: '/contacts/{contactId}',
CQRSQuery: GetContactForEditing::class,
scopes: [
'contact_read',
],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSCreate(
uriTemplate: '/contacts',
validationContext: ['groups' => ['Default', 'Create']],
CQRSCommand: AddContactCommand::class,
CQRSQuery: GetContactForEditing::class,
scopes: [
'contact_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::CREATE_COMMAND_MAPPING,
),
new CQRSPartialUpdate(
uriTemplate: '/contacts/{contactId}',
validationContext: ['groups' => ['Default', 'Update']],
CQRSCommand: EditContactCommand::class,
CQRSQuery: GetContactForEditing::class,
scopes: [
'contact_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::UPDATE_COMMAND_MAPPING,
),
],
exceptionToStatus: [
ContactConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
ContactNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class Contact
{
#[ApiProperty(identifier: true)]
public int $contactId;
#[LocalizedValue]
#[DefaultLanguage(groups: ['Create'], fieldName: 'names')]
#[DefaultLanguage(groups: ['Update'], fieldName: 'names', allowNull: true)]
#[Assert\All(constraints: [
new TypedRegex([
'type' => TypedRegex::TYPE_CATALOG_NAME,
]),
])]
public array $names;
#[Assert\Email(mode: Assert\Email::VALIDATION_MODE_STRICT)]
public string $email;
#[LocalizedValue]
#[DefaultLanguage(groups: ['Create'], fieldName: 'descriptions', allowNull: true)]
#[DefaultLanguage(groups: ['Update'], fieldName: 'descriptions', allowNull: true)]
#[Assert\All(constraints: [
new TypedRegex([
'type' => TypedRegex::TYPE_CATALOG_NAME,
]),
])]
public array $descriptions;
public bool $messagesSavingEnabled;
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank(allowNull: true)]
public array $shopIds;
public const QUERY_MAPPING = [
'[localisedTitles]' => '[names]',
'[localisedDescription]' => '[descriptions]',
'[messagesSavingEnabled]' => '[isMessagesSavingEnabled]',
'[shopAssociation]' => '[shopIds]',
];
public const CREATE_COMMAND_MAPPING = [
'[names]' => '[localisedTitles]',
'[descriptions]' => '[localisedDescription]',
'[messagesSavingEnabled]' => '[isMessageSavingEnabled]',
];
public const UPDATE_COMMAND_MAPPING = [
'[names]' => '[localisedTitles]',
'[descriptions]' => '[localisedDescription]',
'[messagesSavingEnabled]' => '[isMessagesSavingEnabled]',
];
}

View File

@@ -0,0 +1,58 @@
<?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\Contact;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Search\Filters\ContactFilters;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/contacts',
scopes: [
'contact_read',
],
ApiResourceMapping: self::MAPPING,
gridDataFactory: 'prestashop.core.grid.data_provider.contacts',
filtersClass: ContactFilters::class,
filtersMapping: [
'[contactId]' => '[id_contact]',
],
),
]
)]
class ContactList
{
#[ApiProperty(identifier: true)]
public int $contactId;
public string $name;
public string $email;
public string $description;
public const MAPPING = [
'[id_contact]' => '[contactId]',
];
}

View File

@@ -0,0 +1,188 @@
<?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\Customer;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\Module\APIResources\ApiPlatform\Processor\BulkCustomersDeleteProcessor;
use PrestaShop\PrestaShop\Core\Domain\Customer\Command\BulkDeleteCustomerCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Command\BulkDisableCustomerCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Command\BulkEnableCustomerCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerDeleteMethod;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/customers/bulk-delete',
CQRSCommand: BulkDeleteCustomerCommand::class,
scopes: [
'customer_write',
],
CQRSCommandMapping: self::COMMAND_MAPPING,
validationContext: ['groups' => ['Default', 'BulkDelete']],
processor: BulkCustomersDeleteProcessor::class,
allowEmptyBody: false,
openapiContext: [
'requestBody' => [
'required' => true,
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'required' => ['customerIds'],
'properties' => [
'customerIds' => [
'type' => 'array',
'items' => ['type' => 'integer'],
],
'deleteMethod' => [
'type' => 'string',
'enum' => [
CustomerDeleteMethod::ALLOW_CUSTOMER_REGISTRATION,
CustomerDeleteMethod::DENY_CUSTOMER_REGISTRATION,
],
'description' => 'Method to use for customer deletion. Default: allow_registration_after',
],
],
],
'example' => [
'customerIds' => [1, 2, 3],
'deleteMethod' => 'allow_registration_after',
],
],
],
],
],
),
new CQRSUpdate(
uriTemplate: '/customers/bulk-disable',
// No output 204 code
output: false,
CQRSCommand: BulkDisableCustomerCommand::class,
scopes: [
'customer_write',
],
CQRSCommandMapping: self::ENABLE_DISABLE_COMMAND_MAPPING,
validationContext: ['groups' => ['Default', 'BulkDisable']],
openapiContext: [
'requestBody' => [
'required' => true,
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'required' => ['customerIds'],
'properties' => [
'customerIds' => [
'type' => 'array',
'items' => ['type' => 'integer'],
],
],
],
'example' => [
'customerIds' => [1, 2, 3],
],
],
],
],
],
),
new CQRSUpdate(
uriTemplate: '/customers/bulk-enable',
// No output 204 code
output: false,
CQRSCommand: BulkEnableCustomerCommand::class,
scopes: [
'customer_write',
],
CQRSCommandMapping: self::ENABLE_DISABLE_COMMAND_MAPPING,
validationContext: ['groups' => ['Default', 'BulkEnable']],
openapiContext: [
'requestBody' => [
'required' => true,
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'required' => ['customerIds'],
'properties' => [
'customerIds' => [
'type' => 'array',
'items' => ['type' => 'integer'],
],
],
],
'example' => [
'customerIds' => [1, 2, 3],
],
],
],
],
],
),
],
exceptionToStatus: [
CustomerConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
CustomerNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkCustomers
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 2, 3]])]
#[Assert\NotBlank(groups: ['BulkDelete', 'BulkEnable', 'BulkDisable'])]
public array $customerIds;
#[ApiProperty(openapiContext: [
'type' => 'string',
'enum' => [
CustomerDeleteMethod::ALLOW_CUSTOMER_REGISTRATION,
CustomerDeleteMethod::DENY_CUSTOMER_REGISTRATION,
],
'example' => CustomerDeleteMethod::ALLOW_CUSTOMER_REGISTRATION,
])]
#[Assert\Choice(
choices: [
CustomerDeleteMethod::ALLOW_CUSTOMER_REGISTRATION,
CustomerDeleteMethod::DENY_CUSTOMER_REGISTRATION,
],
message: 'The delete method must be either "allow_registration_after" or "deny_registration_after".',
groups: ['BulkDelete']
)]
public ?string $deleteMethod;
public const COMMAND_MAPPING = [
'[customerIds]' => '[customerIds]',
'[deleteMethod]' => '[deleteMethod]',
];
public const ENABLE_DISABLE_COMMAND_MAPPING = [
'[customerIds]' => '[customerIds]',
];
}

View File

@@ -0,0 +1,196 @@
<?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\Customer;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Customer\Command\AddCustomerCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Command\DeleteCustomerCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Command\EditCustomerCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerException;
use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\DuplicateCustomerEmailException;
use PrestaShop\PrestaShop\Core\Domain\Customer\Query\GetCustomerForEditing;
use PrestaShop\PrestaShop\Core\Domain\Customer\ValueObject\CustomerDeleteMethod;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSCreate(
uriTemplate: '/customers',
CQRSCommand: AddCustomerCommand::class,
CQRSQuery: GetCustomerForEditing::class,
scopes: [
'customer_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
validationContext: ['groups' => ['Default', 'Create']],
),
new CQRSGet(
uriTemplate: '/customers/{customerId}',
requirements: ['customerId' => '\d+'],
CQRSQuery: GetCustomerForEditing::class,
scopes: [
'customer_read',
],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSPartialUpdate(
uriTemplate: '/customers/{customerId}',
requirements: ['customerId' => '\d+'],
read: false,
CQRSCommand: EditCustomerCommand::class,
CQRSCommandMapping: self::COMMAND_MAPPING,
CQRSQuery: GetCustomerForEditing::class,
CQRSQueryMapping: self::QUERY_MAPPING,
scopes: [
'customer_write',
],
),
new CQRSDelete(
uriTemplate: '/customers/{customerId}',
CQRSCommand: DeleteCustomerCommand::class,
scopes: [
'customer_write',
],
CQRSCommandMapping: self::DELETE_COMMAND_MAPPING,
openapiContext: [
'requestBody' => [
'required' => true,
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'required' => ['deleteMethod'],
'properties' => [
'deleteMethod' => [
'type' => 'string',
'enum' => [
CustomerDeleteMethod::ALLOW_CUSTOMER_REGISTRATION,
CustomerDeleteMethod::DENY_CUSTOMER_REGISTRATION,
],
'description' => 'Method to use for customer deletion',
'example' => CustomerDeleteMethod::ALLOW_CUSTOMER_REGISTRATION,
],
],
],
'example' => [
'deleteMethod' => 'allow_registration_after',
],
],
],
'description' => 'Request body specifying the deletion method',
],
],
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [
CustomerConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
CustomerNotFoundException::class => Response::HTTP_NOT_FOUND,
DuplicateCustomerEmailException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
CustomerException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
],
)]
class Customer
{
#[ApiProperty(identifier: true, openapiContext: ['type' => 'integer', 'example' => 1])]
public int $customerId;
#[Assert\NotBlank(groups: ['Create'])]
public string $firstName;
#[Assert\NotBlank(groups: ['Create'])]
public string $lastName;
#[Assert\NotBlank(groups: ['Create'])]
#[Assert\Email(mode: Assert\Email::VALIDATION_MODE_STRICT)]
public string $email;
#[Assert\NotBlank(groups: ['Create'])]
public string $password;
#[Assert\NotBlank(groups: ['Create'])]
#[ApiProperty(openapiContext: ['type' => 'integer', 'example' => 3])]
public int $defaultGroupId;
#[Assert\NotBlank(groups: ['Create'])]
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
public array $groupIds;
#[ApiProperty(openapiContext: ['type' => 'integer', 'example' => 1])]
public ?int $genderId;
#[ApiProperty(openapiContext: ['type' => 'boolean', 'example' => true])]
public bool $enabled;
#[ApiProperty(openapiContext: ['type' => 'boolean', 'example' => false])]
public bool $newsletterSubscribed;
#[ApiProperty(openapiContext: ['type' => 'boolean', 'example' => false])]
public bool $partnerOffersSubscribed;
public ?string $birthday;
public ?string $companyName;
public ?string $siretCode;
public ?string $apeCode;
public ?string $website;
#[ApiProperty(openapiContext: ['type' => 'number', 'format' => 'float', 'example' => 1000.5])]
public ?float $allowedOutstandingAmount;
#[ApiProperty(openapiContext: ['type' => 'integer', 'example' => 30])]
public ?int $maxPaymentDays;
#[ApiProperty(openapiContext: ['type' => 'integer', 'example' => 1])]
public ?int $riskId;
#[ApiProperty(openapiContext: ['type' => 'boolean', 'example' => false])]
public bool $guest;
public ?string $deleteMethod;
public const QUERY_MAPPING = [
'[id]' => '[customerId]',
];
public const COMMAND_MAPPING = [
'[_context][shopId]' => '[shopId]',
'[partnerOffersSubscribed]' => '[isPartnerOffersSubscribed]',
'[guest]' => '[isGuest]',
'[enabled]' => '[isEnabled]',
];
public const DELETE_COMMAND_MAPPING = [
'[deleteMethod]' => '[deleteMethod]',
];
}

View File

@@ -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
*/
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Customer;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Customer\Query\GetCustomerForViewing;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/customers/{customerId}/details',
requirements: ['customerId' => '\d+'],
CQRSQuery: GetCustomerForViewing::class,
scopes: [
'customer_read',
],
CQRSQueryMapping: self::QUERY_MAPPING,
),
],
exceptionToStatus: [
CustomerNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class CustomerDetails
{
#[ApiProperty(identifier: true, openapiContext: ['type' => 'integer', 'example' => 1])]
public int $customerId;
public mixed $personalInformation;
public mixed $ordersInformation;
public array $cartsInformation;
public mixed $productsInformation;
public array $messagesInformation;
public array $discountsInformation;
public array $sentEmailsInformation;
public array $lastConnectionsInformation;
public array $groupsInformation;
public array $addressesInformation;
public mixed $generalInformation;
public const QUERY_MAPPING = [
'[customerId]' => '[customerId]',
];
}

View File

@@ -0,0 +1,117 @@
<?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\Customer;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\Decimal\DecimalNumber;
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Command\AddCustomerGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Command\DeleteCustomerGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Command\EditCustomerGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Exception\GroupNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Query\GetCustomerGroupForEditing;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use PrestaShopBundle\ApiPlatform\Metadata\LocalizedValue;
#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/customers/groups/{customerGroupId}',
CQRSQuery: GetCustomerGroupForEditing::class,
scopes: [
'customer_group_read',
],
// QueryResult format doesn't match with ApiResource, so we can specify a mapping so that it is normalized with extra fields adapted for the ApiResource DTO
CQRSQueryMapping: [
// EditableCustomerGroup::$id is normalized as [customerGroupId]
'[id]' => '[customerGroupId]',
// EditableCustomerGroup::$reduction is normalized as [reductionPercent]
'[reduction]' => '[reductionPercent]',
],
),
new CQRSCreate(
uriTemplate: '/customers/groups',
CQRSCommand: AddCustomerGroupCommand::class,
CQRSQuery: GetCustomerGroupForEditing::class,
scopes: [
'customer_group_write',
],
// Here, we use query mapping to adapt normalized query result for the ApiPlatform DTO
CQRSQueryMapping: [
'[id]' => '[customerGroupId]',
'[reduction]' => '[reductionPercent]',
],
// Here, we use command mapping to adapt the normalized command result for the CQRS query
CQRSCommandMapping: [
'[_context][shopIds]' => '[shopIds]',
'[groupId]' => '[customerGroupId]',
],
),
new CQRSUpdate(
uriTemplate: '/customers/groups/{customerGroupId}',
CQRSCommand: EditCustomerGroupCommand::class,
CQRSQuery: GetCustomerGroupForEditing::class,
scopes: [
'customer_group_write',
],
// Here we use the ApiResource DTO mapping to transform the normalized query result
ApiResourceMapping: [
'[id]' => '[customerGroupId]',
'[reduction]' => '[reductionPercent]',
],
),
new CQRSDelete(
uriTemplate: '/customers/groups/{customerGroupId}',
CQRSCommand: DeleteCustomerGroupCommand::class,
scopes: [
'customer_group_write',
],
// Here, we use query mapping to adapt URI parameters to the expected constructor parameter name
CQRSCommandMapping: [
'[customerGroupId]' => '[groupId]',
],
),
],
exceptionToStatus: [GroupNotFoundException::class => 404],
)]
class CustomerGroup
{
#[ApiProperty(identifier: true)]
public int $customerGroupId;
#[LocalizedValue]
public array $localizedNames;
public DecimalNumber $reductionPercent;
public bool $displayPriceTaxExcluded;
public bool $showPrice;
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer']])]
public array $shopIds;
}

View File

@@ -0,0 +1,57 @@
<?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\Customer;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\Decimal\DecimalNumber;
use PrestaShop\PrestaShop\Core\Domain\Customer\Group\Exception\GroupNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/customers/groups',
gridDataFactory: 'prestashop.core.grid.data.factory.customer_groups',
ApiResourceMapping: [
'[id_group]' => '[customerGroupId]',
'[reduction]' => '[reductionPercent]',
'[show_prices]' => '[showPrice]',
'[members]' => '[customers]',
],
),
],
exceptionToStatus: [GroupNotFoundException::class => 404],
)]
class CustomerGroupList
{
public int $customerGroupId;
public string $name;
public DecimalNumber $reductionPercent;
public int $customers;
public bool $showPrice;
}

View File

@@ -0,0 +1,108 @@
<?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\Customer;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\QueryParameter;
use PrestaShop\PrestaShop\Core\Domain\Customer\Exception\CustomerException;
use PrestaShop\PrestaShop\Core\Domain\Customer\Query\SearchCustomers;
use PrestaShop\PrestaShop\Core\Domain\Shop\Exception\InvalidShopConstraintException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGetCollection;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new CQRSGetCollection(
uriTemplate: '/customers/search',
scopes: [
'customer_read',
],
CQRSQuery: SearchCustomers::class,
CQRSQueryMapping: self::QUERY_MAPPING,
ApiResourceMapping: self::API_RESOURCE_MAPPING,
parameters: [
new QueryParameter(
key: 'phrases',
required: true,
description: 'Array of search phrases to find customers (matches first name, last name, email, company name and id)'
),
],
openapiContext: [
'parameters' => [
[
'name' => 'phrases',
'in' => 'query',
'required' => true,
'schema' => [
'type' => 'array',
'items' => [
'type' => 'string',
],
],
'description' => 'Array of search phrases to find customers (matches first name, last name, email, company name and id)',
'style' => 'form',
'explode' => true,
],
],
],
),
],
exceptionToStatus: [
CustomerException::class => Response::HTTP_BAD_REQUEST,
InvalidShopConstraintException::class => Response::HTTP_BAD_REQUEST,
],
)]
class FoundCustomer
{
#[ApiProperty(identifier: true, openapiContext: ['type' => 'integer', 'example' => 1])]
public int $idCustomer;
public string $firstname;
public string $lastname;
public string $email;
public string $fullnameAndEmail;
#[ApiProperty(openapiContext: ['type' => 'integer', 'example' => 1])]
public int $active;
public ?string $company;
#[ApiProperty(openapiContext: ['type' => 'integer', 'example' => 3])]
public int $idDefaultGroup;
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
public array $groups;
public const QUERY_MAPPING = [
'[phrases]' => '[phrases]',
'[_context][shopConstraint]' => '[shopConstraint]',
];
public const API_RESOURCE_MAPPING = [
'[id_customer]' => '[idCustomer]',
'[fullname_and_email]' => '[fullnameAndEmail]',
'[id_default_group]' => '[idDefaultGroup]',
];
}

View File

@@ -0,0 +1,78 @@
<?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\Discount;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Discount\Command\BulkDeleteDiscountsCommand;
use PrestaShop\PrestaShop\Core\Domain\Discount\Exception\BulkDiscountException;
use PrestaShop\PrestaShop\Core\Domain\Discount\Exception\DiscountConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Discount\Exception\DiscountNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/discounts/bulk-delete',
CQRSCommand: BulkDeleteDiscountsCommand::class,
scopes: [
'discount_write',
],
allowEmptyBody: false,
openapiContext: [
'requestBody' => [
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'properties' => [
'discountIds' => [
'type' => 'array',
'items' => ['type' => 'integer'],
],
],
],
'example' => [
'discountIds' => [1, 3],
],
],
],
],
],
),
],
exceptionToStatus: [
DiscountNotFoundException::class => Response::HTTP_NOT_FOUND,
DiscountConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
BulkDiscountException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
],
)]
class BulkDeleteDiscounts
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $discountIds;
}

View File

@@ -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
*/
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Discount;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Discount\Command\BulkUpdateDiscountsStatusCommand;
use PrestaShop\PrestaShop\Core\Domain\Discount\Exception\BulkDiscountException;
use PrestaShop\PrestaShop\Core\Domain\Discount\Exception\DiscountNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSPartialUpdate(
uriTemplate: '/discounts/bulk-update-status',
output: false,
CQRSCommand: BulkUpdateDiscountsStatusCommand::class,
CQRSCommandMapping: [
'[enabled]' => '[newStatus]',
],
scopes: [
'discount_write',
],
),
],
exceptionToStatus: [
DiscountNotFoundException::class => Response::HTTP_NOT_FOUND,
BulkDiscountException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
],
)]
class BulkUpdateStatusDiscounts
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $discountIds;
public bool $enabled;
}

View File

@@ -0,0 +1,274 @@
<?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\Discount;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\OpenApi\Model\Operation as OpenApiOperation;
use PrestaShop\Decimal\DecimalNumber;
use PrestaShop\PrestaShop\Core\Domain\Discount\Command\AddDiscountCommand;
use PrestaShop\PrestaShop\Core\Domain\Discount\Command\DeleteDiscountCommand;
use PrestaShop\PrestaShop\Core\Domain\Discount\Command\DuplicateDiscountCommand;
use PrestaShop\PrestaShop\Core\Domain\Discount\Command\UpdateDiscountCommand;
use PrestaShop\PrestaShop\Core\Domain\Discount\Exception\DiscountConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Discount\Exception\DiscountNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Discount\Query\GetDiscountForEditing;
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: '/discounts/{discountId}',
requirements: ['discountId' => '\d+'],
CQRSQuery: GetDiscountForEditing::class,
scopes: ['discount_read'],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSCreate(
uriTemplate: '/discounts',
validationContext: ['groups' => ['Default', 'Create']],
CQRSCommand: AddDiscountCommand::class,
CQRSQuery: GetDiscountForEditing::class,
scopes: ['discount_write'],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
),
new CQRSPartialUpdate(
uriTemplate: '/discounts/{discountId}',
requirements: ['discountId' => '\d+'],
CQRSCommand: UpdateDiscountCommand::class,
CQRSQuery: GetDiscountForEditing::class,
scopes: ['discount_write'],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
),
new CQRSDelete(
uriTemplate: '/discounts/{discountId}',
CQRSCommand: DeleteDiscountCommand::class,
scopes: [
'discount_write',
],
),
new CQRSCreate(
uriTemplate: '/discounts/{discountId}/duplicate',
requirements: ['discountId' => '\d+'],
CQRSCommand: DuplicateDiscountCommand::class,
CQRSQuery: GetDiscountForEditing::class,
scopes: ['discount_write'],
CQRSQueryMapping: self::QUERY_MAPPING,
allowEmptyBody: true,
openapi: new OpenApiOperation(
summary: 'Duplicate a Discount resource.',
description: 'Creates a copy of an existing Discount resource.',
)
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [
DiscountNotFoundException::class => Response::HTTP_NOT_FOUND,
DiscountConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
],
)]
class Discount
{
#[ApiProperty(identifier: true)]
public int $discountId;
#[Assert\NotBlank(groups: ['Create'])]
public string $type;
#[Assert\NotBlank(groups: ['Create'])]
#[LocalizedValue]
public array $names;
public string $description;
public string $code;
public bool $enabled;
public ?int $totalQuantity;
public ?int $quantityPerUser;
public ?DecimalNumber $reductionPercent;
#[ApiProperty(
openapiContext: [
'type' => 'object',
'description' => 'Fixed reduction amount',
'properties' => [
'amount' => [
'type' => 'number',
'description' => 'Fixed reduction amount value',
],
'currencyId' => [
'type' => 'integer',
'description' => 'Currency ID for reduction amount',
],
'taxIncluded' => [
'type' => 'boolean',
'Whether reduction amount is tax included',
],
],
]
)]
public ?array $reductionAmount;
public ?int $giftProductId;
public ?int $giftCombinationId;
// Conditions/compatibility values
public bool $cheapestProduct;
#[ApiProperty(
openapiContext: [
'type' => 'array',
'description' => 'Product conditions (rule groups)',
'items' => [
'type' => 'object',
'properties' => [
'quantity' => ['type' => 'integer'],
'rules' => [
'type' => 'array',
'items' => [
'type' => 'object',
'properties' => [
'type' => [
'type' => 'string',
'enum' => [
// We use hard-coded values because the ProductRuleType class is only available
// in 9.1 and using it breaks the parsing of API resources on 9.0
'categories',
'products',
'combinations',
'manufacturers',
'suppliers',
'attributes',
'features',
],
],
'itemIds' => [
'type' => 'array',
'items' => ['type' => 'integer'],
],
'required' => ['type', 'itemIds'],
],
],
],
'type' => [
'type' => 'string',
'enum' => [
// We use hard-coded values because the ProductRuleGroupType class is only available
// in 9.1 and using it breaks the parsing of API resources on 9.0
'all_product_rules',
'at_least_one_product_rule',
],
],
'required' => ['quantity', 'rules'],
],
],
]
)]
public ?array $productConditions;
#[ApiProperty(
openapiContext: [
'type' => 'integer',
'description' => 'Minimum quantity of products required',
'minimum' => 0,
]
)]
public ?int $minimumProductQuantity;
#[ApiProperty(
openapiContext: [
'type' => 'object',
'description' => 'Minimum amount required',
'properties' => [
'amount' => [
'type' => 'number',
'description' => 'Minimum amount value',
],
'currencyId' => [
'type' => 'integer',
'description' => 'Currency ID for minimum amount',
],
'taxIncluded' => [
'type' => 'boolean',
'Whether minimum amount is tax included',
],
'shippingIncluded' => [
'type' => 'boolean',
'description' => 'Whether minimum amount includes shipping',
],
],
]
)]
public ?array $minimumAmount;
public ?int $customerId;
#[ApiProperty(
openapiContext: [
'type' => 'array',
'description' => 'Customer group IDs for which the discount is valid',
'items' => ['type' => 'integer'],
]
)]
public ?array $customerGroupIds;
#[ApiProperty(
openapiContext: [
'type' => 'array',
'description' => 'Carrier IDs for which the discount is valid',
'items' => ['type' => 'integer'],
]
)]
public ?array $carrierIds;
#[ApiProperty(
openapiContext: [
'type' => 'array',
'description' => 'Country IDs for which the discount is valid',
'items' => ['type' => 'integer'],
]
)]
public ?array $countryIds;
#[ApiProperty(
openapiContext: [
'type' => 'array',
'description' => 'Discount Type IDs compatible with the discount',
'items' => ['type' => 'integer'],
]
)]
public ?array $compatibleDiscountTypeIds;
// End of conditions/compatibility values
public bool $highlightInCart;
public bool $allowPartialUse;
public int $priority;
public \DateTimeImmutable $validFrom;
public \DateTimeImmutable $validTo;
protected const QUERY_MAPPING = [
'[localizedNames]' => '[names]',
'[active]' => '[enabled]',
];
protected const COMMAND_MAPPING = [
'[names]' => '[localizedNames]',
'[enabled]' => '[active]',
];
}

View File

@@ -0,0 +1,58 @@
<?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\Discount;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Discount\Exception\DiscountNotFoundException;
use PrestaShop\PrestaShop\Core\Search\Filters\DiscountFilters;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
use PrestaShopBundle\ApiPlatform\Provider\QueryListProvider;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/discounts',
provider: QueryListProvider::class,
scopes: ['discount_read'],
ApiResourceMapping: [
'[id_discount]' => '[discountId]',
'[active]' => '[enabled]',
'[discount_type]' => '[type]',
],
gridDataFactory: 'prestashop.core.grid.data.factory.discount',
filtersClass: DiscountFilters::class,
),
],
exceptionToStatus: [
DiscountNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class DiscountList
{
#[ApiProperty(identifier: true)]
public int $discountId;
public string $type;
public string $name;
public bool $enabled;
public string $code;
}

View File

@@ -0,0 +1,63 @@
<?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\DiscountType;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Discount\Query\GetDiscountTypes;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGetCollection;
use PrestaShopBundle\ApiPlatform\Metadata\LocalizedValue;
#[ApiResource(
operations: [
new CQRSGetCollection(
uriTemplate: '/discount-types',
CQRSQuery: GetDiscountTypes::class,
scopes: ['discount_read'],
CQRSQueryMapping: [],
ApiResourceMapping: [
'[type]' => '[type]',
'[localizedNames]' => '[names]',
'[localizedDescriptions]' => '[descriptions]',
'[core]' => '[core]',
'[enabled]' => '[enabled]',
],
),
],
normalizationContext: ['skip_null_values' => false],
)]
class DiscountTypeList
{
#[ApiProperty(identifier: true)]
public int $discountTypeId;
public string $type;
#[LocalizedValue]
public array $names;
#[LocalizedValue]
public array $descriptions;
public bool $core;
public bool $enabled;
}

View File

@@ -0,0 +1,54 @@
<?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\Feature;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Feature\Command\BulkDeleteFeatureValueCommand;
use PrestaShop\PrestaShop\Core\Domain\Feature\Exception\FeatureValueNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/features/values/bulk-delete',
CQRSCommand: BulkDeleteFeatureValueCommand::class,
scopes: [
'feature_value_write',
],
allowEmptyBody: false,
),
],
exceptionToStatus: [
FeatureValueNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkFeatureValues
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $featureValueIds;
}

View File

@@ -0,0 +1,54 @@
<?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\Feature;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Feature\Command\BulkDeleteFeatureCommand;
use PrestaShop\PrestaShop\Core\Domain\Feature\Exception\FeatureNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/features/bulk-delete',
CQRSCommand: BulkDeleteFeatureCommand::class,
scopes: [
'feature_write',
],
allowEmptyBody: false,
),
],
exceptionToStatus: [
FeatureNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkFeatures
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $featureIds;
}

View File

@@ -0,0 +1,117 @@
<?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\Feature;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\DefaultLanguage;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\TypedRegex;
use PrestaShop\PrestaShop\Core\Domain\Feature\Command\AddFeatureCommand;
use PrestaShop\PrestaShop\Core\Domain\Feature\Command\DeleteFeatureCommand;
use PrestaShop\PrestaShop\Core\Domain\Feature\Command\EditFeatureCommand;
use PrestaShop\PrestaShop\Core\Domain\Feature\Exception\FeatureConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Feature\Exception\FeatureNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Feature\Query\GetFeatureForEditing;
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: '/features/{featureId}',
CQRSQuery: GetFeatureForEditing::class,
scopes: [
'feature_read',
],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSCreate(
uriTemplate: '/features',
validationContext: ['groups' => ['Default', 'Create']],
CQRSCommand: AddFeatureCommand::class,
CQRSQuery: GetFeatureForEditing::class,
scopes: [
'feature_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
),
new CQRSPartialUpdate(
uriTemplate: '/features/{featureId}',
validationContext: ['groups' => ['Default', 'Update']],
CQRSCommand: EditFeatureCommand::class,
CQRSQuery: GetFeatureForEditing::class,
scopes: [
'feature_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
),
new CQRSDelete(
uriTemplate: '/features/{featureId}',
requirements: ['featureId' => '\d+'],
CQRSCommand: DeleteFeatureCommand::class,
scopes: [
'feature_write',
],
),
],
exceptionToStatus: [
FeatureConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
FeatureNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class Feature
{
#[ApiProperty(identifier: true)]
public int $featureId;
#[LocalizedValue]
#[DefaultLanguage(groups: ['Create'], fieldName: 'names')]
#[DefaultLanguage(groups: ['Update'], fieldName: 'names', allowNull: true)]
#[Assert\All(constraints: [
new TypedRegex([
'type' => TypedRegex::TYPE_CATALOG_NAME,
]),
])]
public array $names;
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank(allowNull: true)]
public array $shopIds;
public int $position;
public const QUERY_MAPPING = [
'[name]' => '[names]',
'[shopAssociation]' => '[shopIds]',
];
public const COMMAND_MAPPING = [
'[names]' => '[localizedNames]',
'[shopIds]' => '[shopAssociation]',
];
}

View File

@@ -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
*/
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Feature;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Search\Filters\FeatureFilters;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/features',
scopes: [
'feature_read',
],
ApiResourceMapping: self::MAPPING,
gridDataFactory: 'prestashop.core.grid.data.factory.feature',
filtersClass: FeatureFilters::class,
filtersMapping: [
'[featureId]' => '[id_feature]',
],
),
]
)]
class FeatureList
{
#[ApiProperty(identifier: true)]
public int $featureId;
public string $name;
public int $values;
public int $position;
public const MAPPING = [
'[id_feature]' => '[featureId]',
'[name]' => '[name]',
'[values]' => '[values]',
'[position]' => '[position]',
];
}

View File

@@ -0,0 +1,114 @@
<?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\Feature;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\DefaultLanguage;
use PrestaShop\PrestaShop\Core\ConstraintValidator\Constraints\TypedRegex;
use PrestaShop\PrestaShop\Core\Domain\Feature\Command\AddFeatureValueCommand;
use PrestaShop\PrestaShop\Core\Domain\Feature\Command\DeleteFeatureValueCommand;
use PrestaShop\PrestaShop\Core\Domain\Feature\Command\EditFeatureValueCommand;
use PrestaShop\PrestaShop\Core\Domain\Feature\Exception\FeatureValueConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Feature\Exception\FeatureValueNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Feature\Query\GetFeatureValueForEditing;
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: '/features/values/{featureValueId}',
CQRSQuery: GetFeatureValueForEditing::class,
scopes: [
'feature_value_read',
],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSCreate(
uriTemplate: '/features/values',
validationContext: ['groups' => ['Default', 'Create']],
CQRSCommand: AddFeatureValueCommand::class,
CQRSQuery: GetFeatureValueForEditing::class,
scopes: [
'feature_value_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
),
new CQRSPartialUpdate(
uriTemplate: '/features/values/{featureValueId}',
validationContext: ['groups' => ['Default', 'Update']],
CQRSCommand: EditFeatureValueCommand::class,
CQRSQuery: GetFeatureValueForEditing::class,
scopes: [
'feature_value_write',
],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
),
new CQRSDelete(
uriTemplate: '/features/values/{featureValueId}',
CQRSCommand: DeleteFeatureValueCommand::class,
scopes: [
'feature_value_write',
],
),
],
exceptionToStatus: [
FeatureValueConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
FeatureValueNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class FeatureValue
{
#[ApiProperty(identifier: true)]
public int $featureValueId;
#[ApiProperty(openapiContext: ['type' => 'integer', 'example' => 1])]
public int $featureId;
#[LocalizedValue]
#[DefaultLanguage(groups: ['Create'], fieldName: 'values')]
#[DefaultLanguage(groups: ['Update'], fieldName: 'values', allowNull: true)]
#[Assert\All(constraints: [
new TypedRegex([
'type' => TypedRegex::TYPE_CATALOG_NAME,
]),
])]
public array $values;
public int $position;
public const QUERY_MAPPING = [
'[value]' => '[values]',
'[localizedValues]' => '[values]',
];
public const COMMAND_MAPPING = [
'[values]' => '[localizedValues]',
];
}

View File

@@ -0,0 +1,67 @@
<?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\Feature;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\Link;
use PrestaShop\PrestaShop\Core\Search\Filters\FeatureValueFilters;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/features/{featureId}/values',
scopes: [
'feature_value_read',
],
uriVariables: [
'featureId' => new Link(
identifiers: ['featureId']
),
],
ApiResourceMapping: self::MAPPING,
gridDataFactory: 'prestashop.core.grid.data.factory.feature_value',
filtersClass: FeatureValueFilters::class,
filtersMapping: [
'[featureValueId]' => '[id_feature_value]',
],
),
]
)]
class FeatureValueList
{
#[ApiProperty(identifier: true)]
public int $featureValueId;
#[ApiProperty(readable: false, writable: false)]
public int $featureId;
public string $value;
public int $position;
public const MAPPING = [
'[id_feature_value]' => '[featureValueId]',
'[value]' => '[value]',
'[position]' => '[position]',
];
}

View File

@@ -0,0 +1,106 @@
<?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;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Hook\Command\UpdateHookStatusCommand;
use PrestaShop\PrestaShop\Core\Domain\Hook\Exception\HookNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Hook\Query\GetHook;
use PrestaShop\PrestaShop\Core\Domain\Hook\Query\GetHookStatus;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
use PrestaShopBundle\ApiPlatform\Provider\QueryListProvider;
#[ApiResource(
operations: [
new CQRSUpdate(
uriTemplate: '/hooks/{hookId}/status',
CQRSCommand: UpdateHookStatusCommand::class,
CQRSQuery: GetHook::class,
scopes: ['hook_write'],
CQRSQueryMapping: self::QUERY_MAPPING,
CQRSCommandMapping: self::COMMAND_MAPPING,
),
new CQRSGet(
uriTemplate: '/hooks/{hookId}',
requirements: ['hookId' => '\d+'],
exceptionToStatus: [HookNotFoundException::class => 404],
CQRSQuery: GetHook::class,
scopes: ['hook_read'],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSGet(
uriTemplate: '/hooks/{hookId}/status',
requirements: ['hookId' => '\d+'],
exceptionToStatus: [HookNotFoundException::class => 404],
CQRSQuery: GetHookStatus::class,
scopes: ['hook_read'],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new PaginatedList(
uriTemplate: '/hooks',
provider: QueryListProvider::class,
scopes: ['hook_read'],
ApiResourceMapping: self::LIST_MAPPING,
gridDataFactory: 'prestashop.core.grid.data_factory.hook',
filtersMapping: [
'[hookId]' => '[id_hook]',
],
),
],
)]
class Hook
{
#[ApiProperty(identifier: true)]
public int $hookId;
public bool $enabled;
public string $name;
public string $title;
public string $description;
protected const QUERY_MAPPING = [
// Transforms the url hookId parameter into the $id parameter for GetHook
'[hookId]' => '[id]',
// Transforms the query result Hook::getId into the Api resource hookId
'[id]' => '[hookId]',
'[active]' => '[enabled]',
];
protected const LIST_MAPPING = [
'[id_hook]' => '[hookId]',
'[active]' => '[enabled]',
];
protected const COMMAND_MAPPING = [
// Transforms the url hookId parameter into the $id parameter for UpdateHookStatusCommand
'[hookId]' => '[id]',
'[enabled]' => '[active]',
];
}

View File

@@ -0,0 +1,65 @@
<?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\Module;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Module\Command\BulkToggleModuleStatusCommand;
use PrestaShop\PrestaShop\Core\Domain\Module\Command\BulkUninstallModuleCommand;
use PrestaShop\PrestaShop\Core\Domain\Module\Exception\ModuleNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
#[ApiResource(
operations: [
new CQRSUpdate(
uriTemplate: '/modules/bulk-update-status',
output: false,
CQRSCommand: BulkToggleModuleStatusCommand::class,
scopes: [
'module_write',
],
CQRSCommandMapping: [
'[enabled]' => '[expectedStatus]',
],
),
new CQRSUpdate(
uriTemplate: '/modules/bulk-uninstall',
output: false,
CQRSCommand: BulkUninstallModuleCommand::class,
scopes: [
'module_write',
],
),
],
exceptionToStatus: [ModuleNotFoundException::class => 404],
)]
class BulkModules
{
/**
* @var string[]
*/
public array $modules;
public bool $enabled;
public bool $deleteFiles;
}

View File

@@ -0,0 +1,90 @@
<?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\Module;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Module\Command\InstallModuleCommand;
use PrestaShop\PrestaShop\Core\Domain\Module\Command\UpdateModuleStatusCommand;
use PrestaShop\PrestaShop\Core\Domain\Module\Exception\AlreadyInstalledModuleException;
use PrestaShop\PrestaShop\Core\Domain\Module\Exception\ModuleNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Module\Exception\ModuleNotInstalledException;
use PrestaShop\PrestaShop\Core\Domain\Module\Query\GetModuleInfos;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/modules/{technicalName}',
CQRSQuery: GetModuleInfos::class,
scopes: [
'module_read',
],
),
new CQRSUpdate(
uriTemplate: '/modules/{technicalName}/status',
CQRSCommand: UpdateModuleStatusCommand::class,
CQRSQuery: GetModuleInfos::class,
scopes: [
'module_write',
],
),
new CQRSUpdate(
uriTemplate: '/modules/{technicalName}/install',
CQRSCommand: InstallModuleCommand::class,
CQRSQuery: GetModuleInfos::class,
scopes: [
'module_write',
],
allowEmptyBody: true,
),
new PaginatedList(
uriTemplate: '/modules',
scopes: [
'module_read',
],
gridDataFactory: 'prestashop.core.grid.data_factory.module',
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [
ModuleNotFoundException::class => 404,
ModuleNotInstalledException::class => 403,
AlreadyInstalledModuleException::class => 403,
],
)]
class Module
{
public ?int $moduleId;
public string $technicalName;
public string $moduleVersion;
public ?string $installedVersion;
public bool $enabled;
public bool $installed;
}

View File

@@ -0,0 +1,50 @@
<?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\Module;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Module\Command\ResetModuleCommand;
use PrestaShop\PrestaShop\Core\Domain\Module\Exception\ModuleNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Module\Exception\ModuleNotInstalledException;
use PrestaShop\PrestaShop\Core\Domain\Module\Query\GetModuleInfos;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
#[ApiResource(
operations: [
new CQRSPartialUpdate(
uriTemplate: '/modules/{technicalName}/reset',
CQRSCommand: ResetModuleCommand::class,
CQRSQuery: GetModuleInfos::class,
scopes: [
'module_write',
],
allowEmptyBody: true,
),
],
exceptionToStatus: [
ModuleNotFoundException::class => 404,
ModuleNotInstalledException::class => 403,
],
)]
class ResetModule extends Module
{
public bool $keepData;
}

View File

@@ -0,0 +1,49 @@
<?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\Module;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Module\Command\UninstallModuleCommand;
use PrestaShop\PrestaShop\Core\Domain\Module\Exception\ModuleNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Module\Exception\ModuleNotInstalledException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
#[ApiResource(
operations: [
new CQRSUpdate(
uriTemplate: '/modules/{technicalName}/uninstall',
output: false,
CQRSCommand: UninstallModuleCommand::class,
scopes: [
'module_write',
],
allowEmptyBody: true,
),
],
exceptionToStatus: [
ModuleNotFoundException::class => 404,
ModuleNotInstalledException::class => 403,
],
)]
class UninstallModule extends Module
{
public bool $deleteFiles = false;
}

View File

@@ -0,0 +1,45 @@
<?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\Module;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Module\Command\UpgradeModuleCommand;
use PrestaShop\PrestaShop\Core\Domain\Module\Query\GetModuleInfos;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
#[ApiResource(
operations: [
new CQRSUpdate(
uriTemplate: '/modules/{technicalName}/upgrade',
CQRSCommand: UpgradeModuleCommand::class,
CQRSQuery: GetModuleInfos::class,
scopes: [
'module_write',
],
allowEmptyBody: true,
),
],
)]
class UpgradeModule extends Module
{
}

View File

@@ -0,0 +1,62 @@
<?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\Module;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Module\Command\UploadModuleCommand;
use PrestaShop\PrestaShop\Core\Domain\Module\Exception\ModuleNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Module\Query\GetModuleInfos;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use Symfony\Component\HttpFoundation\File\File;
#[ApiResource(
operations: [
new CQRSCreate(
uriTemplate: '/modules/upload-source',
CQRSCommand: UploadModuleCommand::class,
CQRSQuery: GetModuleInfos::class,
scopes: [
'module_write',
],
),
new CQRSCreate(
uriTemplate: '/modules/upload-archive',
inputFormats: ['multipart' => ['multipart/form-data']],
read: false,
CQRSCommand: UploadModuleCommand::class,
CQRSQuery: GetModuleInfos::class,
scopes: [
'module_write',
],
CQRSCommandMapping: [
'[archive].pathName' => '[source]',
],
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [ModuleNotFoundException::class => 404],
)]
class UploadModule extends Module
{
public string $source;
public File $archive;
}

View File

@@ -0,0 +1,101 @@
<?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\Product;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\Decimal\DecimalNumber;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Exception\CombinationNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Query\GetCombinationForEditing;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/products/combinations/{combinationId}',
CQRSQuery: GetCombinationForEditing::class,
scopes: [
'product_read',
],
CQRSQueryMapping: self::QUERY_MAPPING,
),
],
exceptionToStatus: [
CombinationNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class Combination
{
public int $productId;
#[ApiProperty(identifier: true)]
public int $combinationId;
public string $name;
public bool $default;
public string $gtin;
public string $isbn;
public string $mpn;
public string $reference;
public string $upc;
public string $coverThumbnailUrl;
#[ApiProperty(openapiContext: ['type' => 'array', 'description' => 'List of image IDs', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
public array $imageIds;
public DecimalNumber $impactOnPriceTaxExcluded;
public DecimalNumber $impactOnPriceTaxIncluded;
public DecimalNumber $impactOnUnitPrice;
public DecimalNumber $impactOnUnitPriceTaxIncluded;
public DecimalNumber $ecotaxTaxExcluded;
public DecimalNumber $ecotaxTaxIncluded;
public DecimalNumber $impactOnWeight;
public DecimalNumber $wholesalePrice;
public DecimalNumber $productTaxRate;
public DecimalNumber $productPriceTaxExcluded;
public DecimalNumber $productEcotaxTaxExcluded;
public int $quantity;
public const QUERY_MAPPING = [
'[_context][shopConstraint]' => '[shopConstraint]',
'[details][gtin]' => '[gtin]',
'[details][isbn]' => '[isbn]',
'[details][mpn]' => '[mpn]',
'[details][reference]' => '[reference]',
'[details][upc]' => '[upc]',
'[details][impactOnWeight]' => '[impactOnWeight]',
'[prices][impactOnPrice]' => '[impactOnPriceTaxExcluded]',
'[prices][impactOnPriceTaxIncluded]' => '[impactOnPriceTaxIncluded]',
'[prices][impactOnUnitPrice]' => '[impactOnUnitPriceTaxExcluded]',
'[prices][impactOnUnitPriceTaxIncluded]' => '[impactOnUnitPriceTaxIncluded]',
'[prices][ecotax]' => '[ecotaxTaxExcluded]',
'[prices][ecotaxTaxIncluded]' => '[ecotaxTaxIncluded]',
'[prices][wholesalePrice]' => '[wholesalePrice]',
'[prices][productTaxRate]' => '[productTaxRate]',
'[prices][productPrice]' => '[productPriceTaxExcluded]',
'[prices][productEcotax]' => '[productEcotaxTaxExcluded]',
'[stock][quantity]' => '[quantity]',
];
}

View File

@@ -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\Product;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Query\GetCombinationIds;
use PrestaShop\PrestaShop\Core\Domain\Product\Exception\ProductNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/products/{productId}/combination-ids',
CQRSQuery: GetCombinationIds::class,
scopes: [
'product_read',
],
CQRSQueryMapping: [
'[_context][shopConstraint]' => '[shopConstraint]',
'[@index][combinationId]' => '[combinationIds][@index]',
],
),
],
exceptionToStatus: [
ProductNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class CombinationIdList
{
public int $productId;
#[ApiProperty(openapiContext: ['type' => 'array', 'description' => 'List of combination IDs', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
public array $combinationIds;
}

View File

@@ -0,0 +1,88 @@
<?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\Product;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\Decimal\DecimalNumber;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Query\GetEditableCombinationsList;
use PrestaShop\PrestaShop\Core\Domain\Product\Exception\ProductNotFoundException;
use PrestaShop\PrestaShop\Core\Search\Filters\ProductCombinationFilters;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPaginate;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new CQRSPaginate(
uriTemplate: '/products/{productId}/combinations',
CQRSQuery: GetEditableCombinationsList::class,
scopes: [
'product_read',
],
CQRSQueryMapping: [
'[_context][langId]' => '[languageId]',
'[_context][shopConstraint]' => '[shopConstraint]',
],
ApiResourceMapping: [
'[combinationName]' => '[name]',
'[attributesInformation]' => '[attributes]',
'[impactOnPrice]' => '[impactOnPriceTaxExcluded]',
],
filtersClass: ProductCombinationFilters::class,
filtersMapping: [
'[_context][shopId]' => '[shopId]',
],
itemsField: 'combinations',
countField: 'totalCombinationsCount',
),
],
exceptionToStatus: [
ProductNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class CombinationList
{
public int $productId;
public int $combinationId;
public string $name;
public bool $default;
public string $reference;
public DecimalNumber $impactOnPriceTaxExcluded;
public DecimalNumber $ecoTax;
public int $quantity;
public string $imageUrl;
#[ApiProperty(
openapiContext: [
'type' => 'array',
'description' => 'Combination attributes',
'items' => [
'type' => 'object',
'properties' => [
'attributeGroupId' => ['type' => 'integer'],
'attributeGroupName' => ['type' => 'string'],
'attributeId' => ['type' => 'integer'],
'attributeName' => ['type' => 'string'],
],
],
]
)]
public array $attributes;
}

View File

@@ -0,0 +1,131 @@
<?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\Product;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\QueryParameter;
use PrestaShop\PrestaShop\Core\Domain\Product\Query\SearchProducts;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGetCollection;
#[ApiResource(
operations: [
new CQRSGetCollection(
uriTemplate: '/products/search',
scopes: [
'product_read',
],
CQRSQuery: SearchProducts::class,
parameters: [
new QueryParameter(
key: 'phrase',
required: true,
description: 'Search phrase to find products'
),
new QueryParameter(
key: 'resultsLimit',
schema: ['type' => 'integer', 'default' => 20],
required: true,
description: 'Maximum number of results to return'
),
new QueryParameter(
key: 'isoCode',
required: true,
description: 'Currency ISO code (e.g., EUR, USD)'
),
new QueryParameter(
key: 'orderId',
schema: ['type' => 'integer'],
required: false,
description: 'Optional order ID for context-specific pricing'
),
],
openapiContext: [
'parameters' => [
[
'name' => 'phrase',
'in' => 'query',
'required' => true,
'schema' => [
'type' => 'string',
],
'description' => 'Search phrase to find products',
],
[
'name' => 'resultsLimit',
'in' => 'query',
'required' => true,
'schema' => [
'type' => 'integer',
'default' => 20,
],
'description' => 'Maximum number of results to return',
],
[
'name' => 'isoCode',
'in' => 'query',
'required' => true,
'schema' => [
'type' => 'string',
],
'description' => 'Currency ISO code (e.g., EUR, USD)',
],
[
'name' => 'orderId',
'in' => 'query',
'required' => false,
'schema' => [
'type' => 'integer',
],
'description' => 'Optional order ID for context-specific pricing',
],
],
]
),
],
)]
class FoundProduct
{
#[ApiProperty(identifier: true)]
public int $productId;
public bool $availableOutOfStock;
public string $name;
public float $taxRate;
public string $formattedPrice;
public float $priceTaxIncl;
public float $priceTaxExcl;
public int $stock;
public string $location;
public array $combinations;
public array $customizationFields;
}

View File

@@ -0,0 +1,86 @@
<?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\Product;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Product\Combination\Command\GenerateProductCombinationsCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\Exception\ProductNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new CQRSCreate(
uriTemplate: '/products/{productId}/generate-combinations',
CQRSCommand: GenerateProductCombinationsCommand::class,
scopes: [
'product_write',
],
ApiResourceMapping: [
// Used to denormalize the command result
'[@index][combinationId]' => '[newCombinationIds][@index]',
],
),
],
exceptionToStatus: [
ProductNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class GenerateCombinations
{
public int $productId;
#[ApiProperty(
openapiContext: [
'type' => 'array',
'description' => 'List of new generated combination IDs',
'items' => [
'type' => 'integer',
'description' => 'Combination ID',
],
]
)]
public array $newCombinationIds = [];
#[ApiProperty(
openapiContext: [
'type' => 'array',
'items' => [
'type' => 'object',
'description' => 'List of attributes grouped by their attribute group',
'properties' => [
'attributeGroupId' => [
'type' => 'number',
'description' => 'Attribute group ID',
],
'attributeIds' => [
'type' => 'array',
'items' => [
'type' => 'integer',
'description' => 'Attribute ID',
],
],
],
],
],
)]
public array $groupedAttributes;
}

View File

@@ -0,0 +1,81 @@
<?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\Product;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Product\Exception\ProductNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Product\Image\Command\AddProductImageCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\Image\Query\GetProductImage;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use PrestaShopBundle\ApiPlatform\Metadata\LocalizedValue;
use Symfony\Component\HttpFoundation\File\File;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new CQRSCreate(
uriTemplate: '/products/{productId}/images',
inputFormats: ['multipart' => ['multipart/form-data']],
requirements: ['productId' => '\d+'],
read: false,
CQRSCommand: AddProductImageCommand::class,
CQRSQuery: GetProductImage::class,
scopes: [
'product_write',
],
CQRSQueryMapping: NewProductImage::QUERY_MAPPING,
CQRSCommandMapping: [
'[_context][shopConstraint]' => '[shopConstraint]',
'[image].pathName' => '[pathName]',
],
),
],
exceptionToStatus: [
ProductNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class NewProductImage
{
public int $productId;
public int $imageId;
public string $imageUrl;
public string $thumbnailUrl;
#[LocalizedValue]
public array $legends;
public bool $cover;
public int $position;
public array $shopIds;
public File $image;
public const QUERY_MAPPING = [
'[_context][shopConstraint]' => '[shopConstraint]',
'[localizedLegends]' => '[legends]',
];
}

View File

@@ -0,0 +1,325 @@
<?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\Product;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\Decimal\DecimalNumber;
use PrestaShop\PrestaShop\Core\Domain\Product\Command\AddProductCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\Command\DeleteProductCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\Command\UpdateProductCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\Exception\ProductNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Product\Query\GetProductForEditing;
use PrestaShop\PrestaShop\Core\Domain\Shop\Exception\ShopAssociationNotFound;
use PrestaShop\PrestaShop\Core\Util\DateTime\DateImmutable;
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;
#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/products/{productId}',
CQRSQuery: GetProductForEditing::class,
scopes: [
'product_read',
],
CQRSQueryMapping: Product::QUERY_MAPPING,
),
new CQRSCreate(
uriTemplate: '/products',
CQRSCommand: AddProductCommand::class,
CQRSQuery: GetProductForEditing::class,
scopes: [
'product_write',
],
CQRSQueryMapping: Product::QUERY_MAPPING,
CQRSCommandMapping: self::CREATE_MAPPING,
),
new CQRSPartialUpdate(
uriTemplate: '/products/{productId}',
CQRSCommand: UpdateProductCommand::class,
CQRSQuery: GetProductForEditing::class,
scopes: [
'product_write',
],
CQRSQueryMapping: Product::QUERY_MAPPING,
CQRSCommandMapping: Product::UPDATE_MAPPING,
),
new CQRSDelete(
uriTemplate: '/products/{productId}',
CQRSCommand: DeleteProductCommand::class,
scopes: [
'product_write',
],
CQRSCommandMapping: [
'[_context][shopConstraint]' => '[shopConstraint]',
]
),
],
exceptionToStatus: [
ProductNotFoundException::class => Response::HTTP_NOT_FOUND,
ShopAssociationNotFound::class => Response::HTTP_NOT_FOUND,
],
)]
class Product
{
#[ApiProperty(identifier: true)]
public int $productId;
public string $type;
public bool $enabled;
#[LocalizedValue]
public array $names;
#[LocalizedValue]
public array $descriptions;
#[LocalizedValue]
public array $shortDescriptions;
#[LocalizedValue]
public array $tags;
public DecimalNumber $priceTaxExcluded;
public DecimalNumber $priceTaxIncluded;
public DecimalNumber $ecotaxTaxExcluded;
public DecimalNumber $ecotaxTaxIncluded;
public int $taxRulesGroupId;
public bool $onSale;
public DecimalNumber $wholesalePrice;
public DecimalNumber $unitPriceTaxExcluded;
public DecimalNumber $unitPriceTaxIncluded;
public string $unity;
public DecimalNumber $unitPriceRatio;
public string $visibility;
public bool $availableForOrder;
public bool $onlineOnly;
public bool $showPrice;
public string $condition;
public bool $showCondition;
public int $manufacturerId;
public string $isbn;
public string $upc;
public string $gtin;
public string $mpn;
public string $reference;
public DecimalNumber $width;
public DecimalNumber $height;
public DecimalNumber $depth;
public DecimalNumber $weight;
public DecimalNumber $additionalShippingCost;
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
public array $carrierReferenceIds;
public int $deliveryTimeNoteType;
#[LocalizedValue]
public array $deliveryTimeInStockNotes;
#[LocalizedValue]
public array $deliveryTimeOutOfStockNotes;
#[LocalizedValue]
public array $metaTitles;
#[LocalizedValue]
public array $metaDescriptions;
#[LocalizedValue]
public array $linkRewrites;
public string $redirectType;
public ?int $redirectTarget = null;
public int $packStockType;
public int $outOfStockType;
public int $quantity;
public int $minimalQuantity;
public int $lowStockThreshold;
public bool $lowStockAlertEnabled;
#[LocalizedValue]
public array $availableNowLabels;
public string $location;
#[LocalizedValue]
public array $availableLaterLabels;
public ?DateImmutable $availableDate = null;
public string $coverThumbnailUrl;
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
public array $shopIds;
#[ApiProperty(openapiContext: [
'type' => 'array',
'items' => [
'type' => 'object',
'properties' => [
'categoryId' => ['type' => 'integer'],
'name' => ['type' => 'string'],
'displayName' => ['type' => 'string'],
],
],
'example' => [
[
'categoryId' => 2,
'name' => 'Home',
'displayName' => 'Home',
],
]])
]
public array $categories;
public int $defaultCategoryId;
public const QUERY_MAPPING = [
'[_context][shopConstraint]' => '[shopConstraint]',
'[_context][langId]' => '[displayLanguageId]',
'[active]' => '[enabled]',
'[basicInformation][localizedNames]' => '[names]',
'[basicInformation][localizedDescriptions]' => '[descriptions]',
'[basicInformation][localizedShortDescriptions]' => '[shortDescriptions]',
'[basicInformation][localizedTags]' => '[tags]',
'[pricesInformation][price]' => '[priceTaxExcluded]',
'[pricesInformation][priceTaxIncluded]' => '[priceTaxIncluded]',
'[pricesInformation][ecotax]' => '[ecotaxTaxExcluded]',
'[pricesInformation][ecotaxTaxIncluded]' => '[ecotaxTaxIncluded]',
'[pricesInformation][taxRulesGroupId]' => '[taxRulesGroupId]',
'[pricesInformation][onSale]' => '[onSale]',
'[pricesInformation][wholesalePrice]' => '[wholesalePrice]',
'[pricesInformation][unitPrice]' => '[unitPriceTaxExcluded]',
'[pricesInformation][unitPriceTaxIncluded]' => '[unitPriceTaxIncluded]',
'[pricesInformation][unity]' => '[unity]',
'[pricesInformation][unitPriceRatio]' => '[unitPriceRatio]',
'[options][visibility]' => '[visibility]',
'[options][availableForOrder]' => '[availableForOrder]',
'[options][onlineOnly]' => '[onlineOnly]',
'[options][showPrice]' => '[showPrice]',
'[options][condition]' => '[condition]',
'[options][showCondition]' => '[showCondition]',
'[options][manufacturerId]' => '[manufacturerId]',
'[details][isbn]' => '[isbn]',
'[details][upc]' => '[upc]',
'[details][gtin]' => '[gtin]',
'[details][mpn]' => '[mpn]',
'[details][reference]' => '[reference]',
'[shippingInformation][width]' => '[width]',
'[shippingInformation][height]' => '[height]',
'[shippingInformation][depth]' => '[depth]',
'[shippingInformation][weight]' => '[weight]',
'[shippingInformation][additionalShippingCost]' => '[additionalShippingCost]',
'[shippingInformation][carrierReferences]' => '[carrierReferenceIds]',
'[shippingInformation][deliveryTimeNoteType]' => '[deliveryTimeNoteType]',
'[shippingInformation][localizedDeliveryTimeInStockNotes]' => '[deliveryTimeInStockNotes]',
'[shippingInformation][localizedDeliveryTimeOutOfStockNotes]' => '[deliveryTimeOutOfStockNotes]',
'[productSeoOptions][localizedMetaTitles]' => '[metaTitles]',
'[productSeoOptions][localizedMetaDescriptions]' => '[metaDescriptions]',
'[productSeoOptions][localizedLinkRewrites]' => '[linkRewrites]',
'[productSeoOptions][redirectType]' => '[redirectType]',
'[productSeoOptions][redirectTarget][id]' => '[redirectTarget]',
'[stockInformation][packStockType]' => '[packStockType]',
'[stockInformation][outOfStockType]' => '[outOfStockType]',
'[stockInformation][quantity]' => '[quantity]',
'[stockInformation][minimalQuantity]' => '[minimalQuantity]',
'[stockInformation][lowStockThreshold]' => '[lowStockThreshold]',
'[stockInformation][lowStockAlertEnabled]' => '[lowStockAlertEnabled]',
'[stockInformation][localizedAvailableNowLabels]' => '[availableNowLabels]',
'[stockInformation][localizedAvailableLaterLabels]' => '[availableLaterLabels]',
'[stockInformation][location]' => '[location]',
'[stockInformation][availableDate]' => '[availableDate]',
// Transform each field one by one (instead of the whole array) to avoid having an extra id field in the target
'[categoriesInformation][categoriesInformation][@index][id]' => '[categories][@index][categoryId]',
'[categoriesInformation][categoriesInformation][@index][name]' => '[categories][@index][name]',
'[categoriesInformation][categoriesInformation][@index][displayName]' => '[categories][@index][displayName]',
'[categoriesInformation][defaultCategoryId]' => '[defaultCategoryId]',
];
public const CREATE_MAPPING = [
'[_context][shopId]' => '[shopId]',
'[type]' => '[productType]',
'[names]' => '[localizedNames]',
'[enabled]' => '[active]',
];
public const UPDATE_MAPPING = [
'[_context][shopConstraint]' => '[shopConstraint]',
'[type]' => '[productType]',
'[enabled]' => '[active]',
'[names]' => '[localizedNames]',
'[descriptions]' => '[localizedDescriptions]',
'[shortDescriptions]' => '[localizedShortDescriptions]',
'[metaTitles]' => '[localizedMetaTitles]',
'[metaDescriptions]' => '[localizedMetaDescriptions]',
'[linkRewrites]' => '[localizedLinkRewrites]',
'[deliveryTimeInStockNotes]' => '[localizedDeliveryTimeInStockNotes]',
'[deliveryTimeOutOfStockNotes]' => '[localizedDeliveryTimeOutOfStockNotes]',
'[availableNowLabels]' => '[localizedAvailableNowLabels]',
'[availableLaterLabels]' => '[localizedAvailableLaterLabels]',
'[priceTaxExcluded]' => '[price]',
'[unitPriceTaxExcluded]' => '[unitPrice]',
'[ecotaxTaxExcluded]' => '[ecotax]',
];
}

View File

@@ -0,0 +1,100 @@
<?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\Product;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Product\Image\Command\DeleteProductImageCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\Image\Command\UpdateProductImageCommand;
use PrestaShop\PrestaShop\Core\Domain\Product\Image\Exception\ProductImageNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Product\Image\Query\GetProductImage;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use PrestaShopBundle\ApiPlatform\Metadata\LocalizedValue;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/products/images/{imageId}',
CQRSQuery: GetProductImage::class,
scopes: [
'product_read',
],
CQRSQueryMapping: ProductImage::QUERY_MAPPING,
),
new CQRSUpdate(
// We have to force POST request, because we cannot use PUT with files AND data
method: CQRSUpdate::METHOD_POST,
uriTemplate: '/products/images/{imageId}',
inputFormats: ['multipart' => ['multipart/form-data']],
status: Response::HTTP_OK,
// Form data value are all string so we disable type enforcement
denormalizationContext: [ObjectNormalizer::DISABLE_TYPE_ENFORCEMENT => true],
CQRSCommand: UpdateProductImageCommand::class,
CQRSQuery: GetProductImage::class,
scopes: [
'product_write',
],
CQRSQueryMapping: ProductImage::QUERY_MAPPING,
CQRSCommandMapping: [
'[_context][shopConstraint]' => '[shopConstraint]',
'[image].pathName' => '[filePath]',
'[legends]' => '[localizedLegends]',
'[cover]' => '[isCover]',
]
),
new CQRSDelete(
uriTemplate: '/products/images/{imageId}',
CQRSCommand: DeleteProductImageCommand::class,
),
],
exceptionToStatus: [
ProductImageNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class ProductImage
{
#[ApiProperty(identifier: true)]
public int $imageId;
public string $imageUrl;
public string $thumbnailUrl;
#[LocalizedValue]
public array $legends;
public bool $cover;
public int $position;
public array $shopIds;
public const QUERY_MAPPING = [
'[_context][shopConstraint]' => '[shopConstraint]',
'[localizedLegends]' => '[legends]',
];
}

View File

@@ -0,0 +1,70 @@
<?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\Product;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Product\Exception\ProductNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Product\Image\Query\GetProductImages;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGetCollection;
use PrestaShopBundle\ApiPlatform\Metadata\LocalizedValue;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new CQRSGetCollection(
uriTemplate: '/products/{productId}/images',
CQRSQuery: GetProductImages::class,
scopes: [
'product_read',
],
CQRSQueryMapping: [
'[_context][shopConstraint]' => '[shopConstraint]',
],
ApiResourceMapping: [
'[localizedLegends]' => '[legends]',
],
),
],
exceptionToStatus: [
ProductNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class ProductImageList
{
public int $productId;
public int $imageId;
public string $imageUrl;
public string $thumbnailUrl;
#[LocalizedValue]
public array $legends;
public bool $cover;
public int $position;
public array $shopIds;
}

View File

@@ -0,0 +1,82 @@
<?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\Product;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\Decimal\DecimalNumber;
use PrestaShop\PrestaShop\Adapter\Product\Grid\Data\Factory\ProductGridDataFactoryDecorator;
use PrestaShop\PrestaShop\Core\Domain\Product\Exception\ProductNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Shop\Exception\ShopAssociationNotFound;
use PrestaShop\PrestaShop\Core\Search\Filters\ProductFilters;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
use PrestaShopBundle\ApiPlatform\Provider\QueryListProvider;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/products',
provider: QueryListProvider::class,
scopes: ['product_read'],
ApiResourceMapping: [
'[id_product]' => '[productId]',
'[price_tax_excluded_decimal_value]' => '[priceTaxExcluded]',
'[price_tax_included_decimal_value]' => '[priceTaxIncluded]',
'[active]' => '[enabled]',
],
gridDataFactory: ProductGridDataFactoryDecorator::class,
filtersClass: ProductFilters::class,
filtersMapping: [
'[productId]' => '[id_product]',
'[priceTaxExcluded]' => '[final_price_tax_excluded]',
'[priceTaxIncluded]' => '[final_price_tax_included]',
'[enabled]' => '[active]',
],
),
],
exceptionToStatus: [
ProductNotFoundException::class => Response::HTTP_NOT_FOUND,
ShopAssociationNotFound::class => Response::HTTP_NOT_FOUND,
],
)]
class ProductList
{
#[ApiProperty(identifier: true)]
public int $productId;
public string $type;
public bool $enabled;
public string $name;
public int $quantity;
public DecimalNumber $priceTaxExcluded;
public DecimalNumber $priceTaxIncluded;
public string $category;
}

View File

@@ -0,0 +1,58 @@
<?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\Product;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Product\Exception\ProductNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Product\Query\GetProductForEditing;
use PrestaShop\PrestaShop\Core\Domain\Product\Shop\Command\SetProductShopsCommand;
use PrestaShop\PrestaShop\Core\Domain\Shop\Exception\ShopAssociationNotFound;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new CQRSPartialUpdate(
uriTemplate: '/products/{productId}/shops',
CQRSCommand: SetProductShopsCommand::class,
CQRSQuery: GetProductForEditing::class,
scopes: [
'product_write',
],
CQRSQueryMapping: Product::QUERY_MAPPING,
CQRSCommandMapping: [
'[associatedShopIds]' => '[shopIds]',
],
),
],
exceptionToStatus: [
ProductNotFoundException::class => Response::HTTP_NOT_FOUND,
ShopAssociationNotFound::class => Response::HTTP_NOT_FOUND,
],
)]
class ProductShops extends Product
{
public int $sourceShopId;
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer']])]
public array $associatedShopIds;
}

View File

@@ -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\SearchAlias;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Alias\Command\BulkDeleteSearchTermsAliasesCommand;
use PrestaShop\PrestaShop\Core\Domain\Alias\Exception\AliasNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/search-aliases/bulk-delete',
CQRSCommand: BulkDeleteSearchTermsAliasesCommand::class,
scopes: ['search_alias_write'],
CQRSCommandMapping: [
'[searchTerms]' => '[searchTerms]',
],
allowEmptyBody: false,
experimentalOperation: true,
),
],
exceptionToStatus: [
AliasNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkDeleteSearchAliases
{
#[ApiProperty(
openapiContext: [
'type' => 'array',
'items' => ['type' => 'string'],
]
)]
public array $searchTerms = [];
}

View File

@@ -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\SearchAlias;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Alias\Command\DeleteSearchTermAliasesCommand;
use PrestaShop\PrestaShop\Core\Domain\Alias\Exception\AliasConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Alias\Exception\AliasNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSDelete(
// Usually the identifier would be in the URL, but since here it is a string this would conflict
// with the bulk url /search-aliases/bulk-delete (bulk-delete would be considered the identifier,
// vice versa) So the searchTerm will need to be passed in the JSON body
uriTemplate: '/search-aliases',
requirements: ['searchTerm' => '\d+'],
CQRSCommand: DeleteSearchTermAliasesCommand::class,
scopes: ['search_alias_write'],
allowEmptyBody: false,
experimentalOperation: true,
),
],
exceptionToStatus: [
AliasNotFoundException::class => Response::HTTP_NOT_FOUND,
AliasConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
],
)]
class DeleteSearchAlias
{
#[ApiProperty(identifier: true)]
#[Assert\NotBlank]
#[Assert\Length(min: 1, max: 255)]
public string $searchTerm;
}

View File

@@ -0,0 +1,106 @@
<?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\SearchAlias;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Alias\Command\AddSearchTermAliasesCommand;
use PrestaShop\PrestaShop\Core\Domain\Alias\Exception\AliasConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Alias\Exception\AliasNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Alias\Query\GetAliasesBySearchTermForEditing;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/search-aliases/{searchTerm}',
CQRSQuery: GetAliasesBySearchTermForEditing::class,
scopes: ['search_alias_read'],
exceptionToStatus: [AliasNotFoundException::class => 404],
CQRSQueryMapping: self::QUERY_MAPPING,
experimentalOperation: true,
),
new CQRSCreate(
uriTemplate: '/search-aliases',
validationContext: ['groups' => ['Default', 'Create']],
CQRSCommand: AddSearchTermAliasesCommand::class,
scopes: ['search_alias_write'],
CQRSCommandMapping: self::CREATE_COMMAND_MAPPING,
output: false,
experimentalOperation: true,
),
],
exceptionToStatus: [
AliasNotFoundException::class => Response::HTTP_NOT_FOUND,
AliasConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
],
)]
class SearchAlias
{
#[ApiProperty(identifier: true)]
#[Assert\NotBlank]
#[Assert\Length(min: 1, max: 255)]
public string $searchTerm = '';
#[Assert\NotBlank]
#[Assert\Count(min: 1)]
#[Assert\All(
constraints: [
new Assert\Collection(
fields: [
'alias' => new Assert\NotBlank(),
'enabled' => new Assert\Type(type: 'bool'),
// Add active because after normalization both active and enabled are present
'active' => new Assert\Type(type: 'bool'),
],
),
],
)]
#[ApiProperty(
openapiContext: [
'type' => 'array',
'items' => [
'type' => 'object',
'properties' => [
'alias' => ['type' => 'string'],
'enabled' => ['type' => 'boolean'],
],
],
]
)]
public array $aliases = [];
protected const QUERY_MAPPING = [
'[aliases][@index][alias]' => '[aliases][@index][alias]',
'[aliases][@index][active]' => '[aliases][@index][enabled]',
];
protected const CREATE_COMMAND_MAPPING = [
'[aliases][@index][alias]' => '[aliases][@index][alias]',
'[aliases][@index][enabled]' => '[aliases][@index][active]',
];
}

View File

@@ -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\SearchAlias;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
use PrestaShopBundle\ApiPlatform\Provider\QueryListProvider;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/search-aliases',
provider: QueryListProvider::class,
scopes: ['search_alias_read'],
gridDataFactory: 'prestashop.core.grid.data_provider.alias_decorator',
experimentalOperation: true,
),
],
)]
class SearchAliasList
{
#[ApiProperty(identifier: true)]
public string $search = '';
#[ApiProperty(
openapiContext: [
'type' => 'array',
'items' => [
'type' => 'object',
'properties' => [
'id_alias' => ['type' => 'integer'],
'alias' => ['type' => 'string'],
'enabled' => ['type' => 'boolean'],
],
],
]
)]
public array $aliases = [];
}

View File

@@ -0,0 +1,94 @@
<?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\SearchAlias;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Alias\Command\UpdateSearchTermAliasesCommand;
use PrestaShop\PrestaShop\Core\Domain\Alias\Exception\AliasConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Alias\Exception\AliasNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Alias\Query\GetAliasesBySearchTermForEditing;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSUpdate(
uriTemplate: '/search-aliases/{searchTerm}',
CQRSCommand: UpdateSearchTermAliasesCommand::class,
CQRSQuery: GetAliasesBySearchTermForEditing::class,
scopes: ['search_alias_write'],
CQRSCommandMapping: self::UPDATE_COMMAND_MAPPING,
output: false,
experimentalOperation: true,
),
],
exceptionToStatus: [
AliasNotFoundException::class => Response::HTTP_NOT_FOUND,
AliasConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
],
)]
class UpdateSearchAlias
{
#[ApiProperty(identifier: true)]
#[Assert\NotBlank]
#[Assert\Length(min: 1, max: 255)]
public string $searchTerm;
#[Assert\All(
constraints: [
new Assert\Collection(
fields: [
'alias' => new Assert\NotBlank(),
'enabled' => new Assert\Type(type: 'bool'),
// Add active because after normalization both active and enabled are present
'active' => new Assert\Type(type: 'bool'),
],
),
],
)]
#[ApiProperty(
openapiContext: [
'type' => 'array',
'items' => [
'type' => 'object',
'properties' => [
'alias' => ['type' => 'string'],
'enabled' => ['type' => 'boolean'],
],
],
]
)]
public array $aliases = [];
#[Assert\Length(min: 1, max: 255)]
public ?string $newSearchTerm = null;
protected const UPDATE_COMMAND_MAPPING = [
'[searchTerm]' => '[oldSearchTerm]',
'[aliases][@index][alias]' => '[aliases][@index][alias]',
'[aliases][@index][enabled]' => '[aliases][@index][active]',
];
}

View File

@@ -0,0 +1,69 @@
<?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\ShowcaseCard;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\Command\CloseShowcaseCardCommand;
use PrestaShop\PrestaShop\Core\Domain\ShowcaseCard\Query\GetShowcaseCardIsClosed;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/showcase-cards/{showcaseCardName}/{employeeId}',
requirements: [
'showcaseCardName' => '[a-z_-]+',
'employeeId' => '\d+',
],
CQRSQuery: GetShowcaseCardIsClosed::class,
CQRSQueryMapping: [
'[_queryResult]' => '[closed]',
],
scopes: ['showcase_card_read'],
),
new CQRSUpdate(
uriTemplate: '/showcase-cards/{showcaseCardName}/{employeeId}/close',
requirements: [
'showcaseCardName' => '[a-z_-]+',
'employeeId' => '\d+',
],
allowEmptyBody: true,
CQRSCommand: CloseShowcaseCardCommand::class,
CQRSQuery: GetShowcaseCardIsClosed::class,
CQRSQueryMapping: [
'[_queryResult]' => '[closed]',
],
scopes: ['showcase_card_write'],
),
],
)]
class ShowcaseCard
{
public string $showcaseCardName;
public int $employeeId;
public bool $closed;
}

View File

@@ -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
*/
declare(strict_types=1);
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Store;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Store\Command\BulkDeleteStoreCommand;
use PrestaShop\PrestaShop\Core\Domain\Store\Exception\StoreNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/stores/bulk-delete',
CQRSCommand: BulkDeleteStoreCommand::class,
scopes: [
'store_write',
],
allowEmptyBody: false,
),
],
exceptionToStatus: [
StoreNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkDeleteStores
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $storeIds;
}

View File

@@ -0,0 +1,62 @@
<?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\Store;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Store\Command\BulkUpdateStoreStatusCommand;
use PrestaShop\PrestaShop\Core\Domain\Store\Exception\StoreNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSUpdate(
uriTemplate: '/stores/bulk-update-status',
// No output 204 code
output: false,
CQRSCommand: BulkUpdateStoreStatusCommand::class,
CQRSCommandMapping: [
'[enabled]' => '[expectedStatus]',
],
scopes: [
'store_write',
],
),
],
exceptionToStatus: [
StoreNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkUpdateStatusStores
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $storeIds;
public bool $enabled;
}

View File

@@ -0,0 +1,82 @@
<?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\Store;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Store\Command\DeleteStoreCommand;
use PrestaShop\PrestaShop\Core\Domain\Store\Command\ToggleStoreStatusCommand;
use PrestaShop\PrestaShop\Core\Domain\Store\Exception\StoreNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Store\Query\GetStoreForEditing;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/stores/{storeId}',
requirements: ['storeId' => '\d+'],
output: false,
CQRSCommand: DeleteStoreCommand::class,
scopes: ['store_write']
),
new CQRSGet(
uriTemplate: '/stores/{storeId}',
requirements: ['storeId' => '\d+'],
CQRSQuery: GetStoreForEditing::class,
scopes: ['store_read'],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSUpdate(
uriTemplate: '/stores/{storeId}/toggle-status',
requirements: ['storeId' => '\d+'],
output: false,
allowEmptyBody: true,
CQRSCommand: ToggleStoreStatusCommand::class,
scopes: ['store_write'],
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [
StoreNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class Store
{
#[ApiProperty(identifier: true)]
public int $storeId;
#[Assert\NotNull(groups: ['Create'])]
public bool $enabled;
public const COMMAND_MAPPING = [
'[enabled]' => '[active]',
];
public const QUERY_MAPPING = [
'[active]' => '[enabled]',
];
}

View File

@@ -0,0 +1,75 @@
<?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\Supplier;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Supplier\Command\BulkDeleteSupplierCommand;
use PrestaShop\PrestaShop\Core\Domain\Supplier\Command\BulkDisableSupplierCommand;
use PrestaShop\PrestaShop\Core\Domain\Supplier\Command\BulkEnableSupplierCommand;
use PrestaShop\PrestaShop\Core\Domain\Supplier\Exception\SupplierNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/suppliers/bulk-delete',
CQRSCommand: BulkDeleteSupplierCommand::class,
scopes: [
'supplier_write',
],
allowEmptyBody: false,
),
new CQRSUpdate(
uriTemplate: '/suppliers/bulk-disable',
// No output 204 code
output: false,
CQRSCommand: BulkDisableSupplierCommand::class,
scopes: [
'supplier_write',
],
),
new CQRSUpdate(
uriTemplate: '/suppliers/bulk-enable',
// No output 204 code
output: false,
CQRSCommand: BulkEnableSupplierCommand::class,
scopes: [
'supplier_write',
],
),
],
exceptionToStatus: [
SupplierNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkSuppliers
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $supplierIds;
}

View File

@@ -0,0 +1,155 @@
<?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\Supplier;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Supplier\Command\AddSupplierCommand;
use PrestaShop\PrestaShop\Core\Domain\Supplier\Command\DeleteSupplierCommand;
use PrestaShop\PrestaShop\Core\Domain\Supplier\Command\DeleteSupplierLogoImageCommand;
use PrestaShop\PrestaShop\Core\Domain\Supplier\Command\EditSupplierCommand;
use PrestaShop\PrestaShop\Core\Domain\Supplier\Command\ToggleSupplierStatusCommand;
use PrestaShop\PrestaShop\Core\Domain\Supplier\Exception\SupplierNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Supplier\Query\GetSupplierForEditing;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use PrestaShopBundle\ApiPlatform\Metadata\LocalizedValue;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSCreate(
uriTemplate: '/suppliers',
validationContext: ['groups' => ['Default', 'Create']],
CQRSCommand: AddSupplierCommand::class,
scopes: ['supplier_write'],
CQRSCommandMapping: self::COMMAND_MAPPING,
),
new CQRSDelete(
uriTemplate: '/suppliers/{supplierId}',
requirements: ['supplierId' => '\d+'],
output: false,
CQRSCommand: DeleteSupplierCommand::class,
scopes: ['supplier_write']
),
new CQRSDelete(
uriTemplate: '/suppliers/{supplierId}/logo',
requirements: ['supplierId' => '\d+'],
output: false,
CQRSCommand: DeleteSupplierLogoImageCommand::class,
scopes: ['supplier_write']
),
new CQRSGet(
uriTemplate: '/suppliers/{supplierId}',
requirements: ['supplierId' => '\d+'],
CQRSQuery: GetSupplierForEditing::class,
scopes: ['supplier_read'],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSPartialUpdate(
uriTemplate: '/suppliers/{supplierId}',
requirements: ['supplierId' => '\d+'],
read: false,
CQRSCommand: EditSupplierCommand::class,
CQRSCommandMapping: self::COMMAND_MAPPING,
CQRSQuery: GetSupplierForEditing::class,
CQRSQueryMapping: self::QUERY_MAPPING,
scopes: ['supplier_write'],
),
new CQRSUpdate(
uriTemplate: '/suppliers/{supplierId}/toggle-status',
requirements: ['supplierId' => '\d+'],
output: false,
allowEmptyBody: true,
CQRSCommand: ToggleSupplierStatusCommand::class,
scopes: ['supplier_write'],
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [
SupplierNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class Supplier
{
#[ApiProperty(identifier: true)]
public int $supplierId;
#[Assert\NotBlank(groups: ['Create'])]
#[Assert\Length(min: 1, max: 64)]
public string $name;
public string $address;
public ?string $address2;
public ?string $postCode;
public string $city;
public ?int $stateId;
public int $countryId;
public ?string $phone;
public ?string $mobilePhone;
public ?string $dni;
#[Assert\NotNull(groups: ['Create'])]
public bool $enabled;
#[LocalizedValue]
public array $descriptions;
#[LocalizedValue]
public array $metaTitles;
#[LocalizedValue]
public array $metaDescriptions;
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank(allowNull: true)]
public array $shopIds;
public ?array $logoImage;
public const COMMAND_MAPPING = [
'[descriptions]' => '[localizedDescriptions]',
'[metaTitles]' => '[localizedMetaTitles]',
'[metaDescriptions]' => '[localizedMetaDescriptions]',
'[shopIds]' => '[shopAssociation]',
];
public const QUERY_MAPPING = [
'[localizedDescriptions]' => '[descriptions]',
'[localizedMetaTitles]' => '[metaTitles]',
'[localizedMetaDescriptions]' => '[metaDescriptions]',
'[associatedShops]' => '[shopIds]',
];
}

View File

@@ -0,0 +1,64 @@
<?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\Supplier;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Supplier\Exception\SupplierNotFoundException;
use PrestaShop\PrestaShop\Core\Search\Filters\SupplierFilters;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
use PrestaShopBundle\ApiPlatform\Provider\QueryListProvider;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/suppliers',
provider: QueryListProvider::class,
scopes: ['supplier_read'],
ApiResourceMapping: [
'[id_supplier]' => '[supplierId]',
'[active]' => '[enabled]',
'[products_count]' => '[productsCount]',
],
gridDataFactory: 'prestashop.core.grid.factory.supplier_decorator',
filtersClass: SupplierFilters::class,
),
],
exceptionToStatus: [
SupplierNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class SupplierList
{
#[ApiProperty(identifier: true)]
public int $supplierId;
public string $name;
public bool $enabled;
public int $productsCount;
public ?string $logo;
}

View File

@@ -0,0 +1,51 @@
<?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\Tab;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Tab\Command\UpdateTabStatusByClassNameCommand;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSUpdate(
uriTemplate: '/tabs/{className}',
read: false,
CQRSCommand: UpdateTabStatusByClassNameCommand::class,
scopes: ['tab_write'],
CQRSCommandMapping: [
'[enabled]' => '[status]',
],
),
],
normalizationContext: ['skip_null_values' => false],
)]
class Tab
{
#[Assert\NotBlank()]
public string $className;
#[Assert\NotNull()]
public bool $enabled;
}

View File

@@ -0,0 +1,50 @@
<?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\Tax;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Tax\Command\BulkDeleteTaxCommand;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSUpdate(
uriTemplate: '/taxes/bulk-delete',
// No output 204 code
output: false,
CQRSCommand: BulkDeleteTaxCommand::class,
scopes: [
'tax_write',
],
),
],
)]
class BulkTaxDelete
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $taxIds;
}

View File

@@ -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
*/
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Tax;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Tax\Command\BulkToggleTaxStatusCommand;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSUpdate(
uriTemplate: '/taxes/bulk-set-status',
// No output 204 code
output: false,
CQRSCommand: BulkToggleTaxStatusCommand::class,
CQRSCommandMapping: [
'[enabled]' => '[expectedStatus]',
],
scopes: [
'tax_write',
],
),
],
)]
class BulkTaxToggleStatus
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $taxIds;
public bool $enabled;
}

View File

@@ -0,0 +1,104 @@
<?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\Tax;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Tax\Command\AddTaxCommand;
use PrestaShop\PrestaShop\Core\Domain\Tax\Command\DeleteTaxCommand;
use PrestaShop\PrestaShop\Core\Domain\Tax\Command\EditTaxCommand;
use PrestaShop\PrestaShop\Core\Domain\Tax\Exception\TaxNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Tax\Query\GetTaxForEditing;
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 CQRSCreate(
uriTemplate: '/taxes',
validationContext: ['groups' => ['Default', 'Create']],
CQRSCommand: AddTaxCommand::class,
scopes: ['tax_write'],
CQRSCommandMapping: self::COMMAND_MAPPING,
),
new CQRSDelete(
uriTemplate: '/taxes/{taxId}',
requirements: ['taxId' => '\d+'],
output: false,
CQRSCommand: DeleteTaxCommand::class,
scopes: ['tax_write']
),
new CQRSGet(
uriTemplate: '/taxes/{taxId}',
requirements: ['taxId' => '\d+'],
CQRSQuery: GetTaxForEditing::class,
scopes: ['tax_read'],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSPartialUpdate(
uriTemplate: '/taxes/{taxId}',
requirements: ['taxId' => '\d+'],
read: false,
CQRSCommand: EditTaxCommand::class,
CQRSCommandMapping: self::COMMAND_MAPPING,
CQRSQuery: GetTaxForEditing::class,
CQRSQueryMapping: self::QUERY_MAPPING,
scopes: ['tax_write'],
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [
TaxNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class Tax
{
#[ApiProperty(identifier: true)]
public int $taxId;
#[LocalizedValue]
#[DefaultLanguage(groups: ['Create'], fieldName: 'names')]
#[DefaultLanguage(groups: ['Update'], fieldName: 'names', allowNull: true)]
public array $names;
#[Assert\NotNull(groups: ['Create'])]
public float $rate;
#[Assert\NotNull(groups: ['Create'])]
public bool $enabled;
public const COMMAND_MAPPING = [
'[enabled]' => '[active]',
'[names]' => '[localizedNames]',
];
public const QUERY_MAPPING = [
'[active]' => '[enabled]',
'[localizedNames]' => '[names]',
];
}

View File

@@ -0,0 +1,68 @@
<?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\Tax;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Search\Filters\TaxFilters;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
use PrestaShopBundle\ApiPlatform\Provider\QueryListProvider;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/taxes',
scopes: ['tax_read'],
ApiResourceMapping: [
'[id_tax]' => '[taxId]',
'[active]' => '[enabled]',
],
gridDataFactory: 'prestashop.core.grid.data_factory.tax',
provider: QueryListProvider::class,
filtersClass: TaxFilters::class,
filtersMapping: [
'[taxId]' => '[id_tax]',
'[enabled]' => '[active]',
],
),
],
normalizationContext: ['skip_null_values' => false],
)]
class TaxList
{
#[ApiProperty(identifier: true)]
public int $taxId;
public string $name;
public float $rate;
public bool $enabled;
public function setRate(string $rate): self
{
$this->rate = (float) $rate;
return $this;
}
}

View File

@@ -0,0 +1,54 @@
<?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\TaxRulesGroup;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Command\BulkDeleteTaxRulesGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Exception\TaxRulesGroupException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/tax-rules-groups/bulk-delete',
CQRSCommand: BulkDeleteTaxRulesGroupCommand::class,
scopes: [
'tax_rules_group_write',
],
allowEmptyBody: false,
),
],
exceptionToStatus: [
TaxRulesGroupException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkDeleteTaxRulesGroup
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $taxRulesGroupIds;
}

View File

@@ -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
*/
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\TaxRulesGroup;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Command\BulkSetTaxRulesGroupStatusCommand;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Exception\TaxRulesGroupException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSUpdate(
uriTemplate: '/tax-rules-groups/bulk-update-status',
// No output 204 code
output: false,
CQRSCommand: BulkSetTaxRulesGroupStatusCommand::class,
CQRSCommandMapping: [
'[enabled]' => '[expectedStatus]',
],
scopes: [
'tax_rules_group_write',
],
),
],
exceptionToStatus: [
TaxRulesGroupException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkUpdateStatusTaxRulesGroup
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $taxRulesGroupIds;
public bool $enabled;
}

View File

@@ -0,0 +1,104 @@
<?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\TaxRulesGroup;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Command\AddTaxRulesGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Command\DeleteTaxRulesGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Command\EditTaxRulesGroupCommand;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Exception\CannotAddTaxRulesGroupException;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Exception\TaxRulesGroupNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Query\GetTaxRulesGroupForEditing;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSCreate(
uriTemplate: '/tax-rules-groups',
validationContext: ['groups' => ['Default', 'Create']],
CQRSCommand: AddTaxRulesGroupCommand::class,
scopes: ['tax_rules_group_write'],
CQRSCommandMapping: self::COMMAND_MAPPING,
),
new CQRSDelete(
uriTemplate: '/tax-rules-groups/{taxRulesGroupId}',
requirements: ['taxRulesGroupId' => '\d+'],
output: false,
CQRSCommand: DeleteTaxRulesGroupCommand::class,
scopes: ['tax_rules_group_write']
),
new CQRSGet(
uriTemplate: '/tax-rules-groups/{taxRulesGroupId}',
requirements: ['taxRulesGroupId' => '\d+'],
CQRSQuery: GetTaxRulesGroupForEditing::class,
scopes: ['tax_rules_group_read'],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSPartialUpdate(
uriTemplate: '/tax-rules-groups/{taxRulesGroupId}',
requirements: ['taxRulesGroupId' => '\d+'],
read: false,
CQRSCommand: EditTaxRulesGroupCommand::class,
CQRSCommandMapping: self::COMMAND_MAPPING,
CQRSQuery: GetTaxRulesGroupForEditing::class,
CQRSQueryMapping: self::QUERY_MAPPING,
scopes: ['tax_rules_group_write'],
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [
CannotAddTaxRulesGroupException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
TaxRulesGroupNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class TaxRulesGroup
{
#[ApiProperty(identifier: true)]
public int $taxRulesGroupId;
#[Assert\NotBlank(groups: ['Create'])]
#[Assert\Length(min: 1, max: 64)]
public string $name;
#[Assert\NotNull(groups: ['Create'])]
public bool $enabled;
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank(allowNull: true)]
public array $shopIds;
public const COMMAND_MAPPING = [
'[shopIds]' => '[shopAssociation]',
];
public const QUERY_MAPPING = [
'[active]' => '[enabled]',
'[shopAssociationIds]' => '[shopIds]',
];
}

View File

@@ -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\TaxRulesGroup;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\TaxRulesGroup\Exception\TaxRulesGroupNotFoundException;
use PrestaShop\PrestaShop\Core\Search\Filters\TaxRulesGroupFilters;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
use PrestaShopBundle\ApiPlatform\Provider\QueryListProvider;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/tax-rules-groups',
provider: QueryListProvider::class,
scopes: ['tax_rules_group_read'],
ApiResourceMapping: [
'[id_tax_rules_group]' => '[taxRulesGroupId]',
'[active]' => '[enabled]',
],
gridDataFactory: 'prestashop.core.grid.data.factory.tax_rules_group',
filtersClass: TaxRulesGroupFilters::class,
),
],
exceptionToStatus: [
TaxRulesGroupNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class TaxRulesGroupList
{
#[ApiProperty(identifier: true)]
public int $taxRulesGroupId;
public string $name;
public bool $enabled;
}

View File

@@ -0,0 +1,54 @@
<?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\Title;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Title\Command\BulkDeleteTitleCommand;
use PrestaShop\PrestaShop\Core\Domain\Title\Exception\TitleNotFoundException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/titles/bulk-delete',
CQRSCommand: BulkDeleteTitleCommand::class,
scopes: [
'title_write',
],
allowEmptyBody: false,
),
],
exceptionToStatus: [
TitleNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkDeleteTitles
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $titleIds;
}

View File

@@ -0,0 +1,117 @@
<?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\Title;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Title\Command\AddTitleCommand;
use PrestaShop\PrestaShop\Core\Domain\Title\Command\DeleteTitleCommand;
use PrestaShop\PrestaShop\Core\Domain\Title\Command\EditTitleCommand;
use PrestaShop\PrestaShop\Core\Domain\Title\Exception\TitleConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Title\Exception\TitleNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Title\Query\GetTitleForEditing;
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\File\File;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
#[ApiResource(
operations: [
new CQRSCreate(
uriTemplate: '/titles',
CQRSCommand: AddTitleCommand::class,
CQRSCommandMapping: self::COMMAND_MAPPING,
scopes: ['title_write'],
inputFormats: ['multipart' => ['multipart/form-data']],
// Form data value are all string so we disable type enforcement
denormalizationContext: [ObjectNormalizer::DISABLE_TYPE_ENFORCEMENT => true],
),
new CQRSDelete(
uriTemplate: '/titles/{titleId}',
requirements: ['titleId' => '\d+'],
output: false,
CQRSCommand: DeleteTitleCommand::class,
scopes: ['title_write']
),
new CQRSGet(
uriTemplate: '/titles/{titleId}',
requirements: ['titleId' => '\d+'],
CQRSQuery: GetTitleForEditing::class,
CQRSQueryMapping: self::QUERY_MAPPING,
scopes: ['title_read'],
),
new CQRSPartialUpdate(
uriTemplate: '/titles/{titleId}',
requirements: ['titleId' => '\d+'],
read: false,
CQRSCommand: EditTitleCommand::class,
CQRSCommandMapping: self::COMMAND_MAPPING,
CQRSQuery: GetTitleForEditing::class,
CQRSQueryMapping: self::QUERY_MAPPING,
scopes: ['title_write']
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [
TitleNotFoundException::class => Response::HTTP_NOT_FOUND,
TitleConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
],
)]
class Title
{
#[ApiProperty(identifier: true)]
public int $titleId;
#[LocalizedValue]
#[Assert\NotBlank(groups: ['Create'])]
public array $names;
public int $gender;
public ?File $imgFile;
public ?int $width;
public ?int $height;
public const QUERY_MAPPING = [
'[localizedNames]' => '[names]',
];
public const COMMAND_MAPPING = [
'[names]' => '[localizedNames]',
'[width]' => '[imgWidth]',
'[height]' => '[imgHeight]',
];
public function setGender(string|int $gender): self
{
$this->gender = (int) $gender;
return $this;
}
}

View File

@@ -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\Title;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Title\Exception\TitleNotFoundException;
use PrestaShop\PrestaShop\Core\Search\Filters\TitleFilters;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
use PrestaShopBundle\ApiPlatform\Provider\QueryListProvider;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/titles',
provider: QueryListProvider::class,
scopes: ['title_read'],
ApiResourceMapping: [
'[id_gender]' => '[titleId]',
'[type]' => '[gender]',
],
gridDataFactory: 'prestashop.core.grid.data.factory.title',
filtersClass: TitleFilters::class,
),
],
exceptionToStatus: [
TitleNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class TitleList
{
#[ApiProperty(identifier: true)]
public int $titleId;
public string $name;
public int $gender;
}

View File

@@ -0,0 +1,153 @@
<?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\WebserviceKey;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Webservice\Command\AddWebserviceKeyCommand;
use PrestaShop\PrestaShop\Core\Domain\Webservice\Command\EditWebserviceKeyCommand;
use PrestaShop\PrestaShop\Core\Domain\Webservice\Exception\WebserviceConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Webservice\Exception\WebserviceKeyNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Webservice\Query\GetWebserviceKeyForEditing;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSPartialUpdate;
use PrestaShopBundle\Form\Admin\Type\FormattedTextareaType;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSCreate(
uriTemplate: '/webservice-keys',
validationContext: ['groups' => ['Default', 'Create']],
CQRSCommand: AddWebserviceKeyCommand::class,
scopes: ['webservice_key_write'],
CQRSCommandMapping: [
'[shopIds]' => '[associatedShops]',
'[enabled]' => '[status]',
],
),
new CQRSGet(
uriTemplate: '/webservice-keys/{webserviceKeyId}',
requirements: ['webserviceKeyId' => '\d+'],
CQRSQuery: GetWebserviceKeyForEditing::class,
scopes: ['webservice_key_read'],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSPartialUpdate(
uriTemplate: '/webservice-keys/{webserviceKeyId}',
read: false,
CQRSCommand: EditWebserviceKeyCommand::class,
CQRSQuery: GetWebserviceKeyForEditing::class,
scopes: ['webservice_key_write'],
CQRSCommandMapping: [
'[shopIds]' => '[shopAssociation]',
'[enabled]' => '[status]',
],
CQRSQueryMapping: self::QUERY_MAPPING,
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [
WebserviceKeyNotFoundException::class => Response::HTTP_NOT_FOUND,
WebserviceConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
],
)]
class WebserviceKey
{
#[ApiProperty(identifier: true)]
public int $webserviceKeyId;
#[Assert\NotBlank(groups: ['Create'])]
#[Assert\Length(min: 32, max: 32)]
public string $key;
#[Assert\NotBlank(groups: ['Create'])]
#[Assert\Length(min: 1, max: FormattedTextareaType::LIMIT_MEDIUMTEXT_UTF8_MB4)]
public string $description;
#[Assert\NotNull(groups: ['Create'])]
public bool $enabled;
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'array']])]
#[Assert\Collection(
fields: [
'DELETE' => new Assert\All(
constraints: [
new Assert\Type(type: 'string'),
],
groups: ['Create']
),
'GET' => new Assert\All(
constraints: [
new Assert\Type(type: 'string'),
],
groups: ['Create']
),
'HEAD' => new Assert\All(
constraints: [
new Assert\Type(type: 'string'),
],
groups: ['Create']
),
'PATCH' => new Assert\All(
constraints: [
new Assert\Type(type: 'string'),
],
groups: ['Create']
),
'PUT' => new Assert\All(
constraints: [
new Assert\Type(type: 'string'),
],
groups: ['Create']
),
'POST' => new Assert\All(
constraints: [
new Assert\Type(type: 'string'),
],
groups: ['Create']
),
],
allowMissingFields: true,
groups: ['Create'])]
public array $permissions;
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank(allowNull: true)]
public array $shopIds;
public const QUERY_MAPPING = [
'[status]' => '[enabled]',
'[resourcePermissions]' => '[permissions]',
'[associatedShops]' => '[shopIds]',
];
public function setEnabled(string|bool $enabled): self
{
$this->enabled = (bool) $enabled;
return $this;
}
}

View File

@@ -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\WebserviceKey;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Webservice\Exception\WebserviceKeyNotFoundException;
use PrestaShop\PrestaShop\Core\Search\Filters\WebserviceKeyFilters;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
use PrestaShopBundle\ApiPlatform\Provider\QueryListProvider;
use Symfony\Component\HttpFoundation\Response;
#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/webservice-keys',
provider: QueryListProvider::class,
scopes: ['webservice_key_read'],
ApiResourceMapping: [
'[id_webservice_account]' => '[webserviceKeyId]',
'[active]' => '[enabled]',
],
gridDataFactory: 'prestashop.core.grid.data_factory.webservice_key',
filtersClass: WebserviceKeyFilters::class,
),
],
exceptionToStatus: [
WebserviceKeyNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class WebserviceKeyList
{
#[ApiProperty(identifier: true)]
public int $webserviceKeyId;
public string $key;
public string $description;
public bool $enabled;
}

View File

@@ -0,0 +1,54 @@
<?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\Zone;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Exception\ZoneNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Zone\Command\BulkDeleteZoneCommand;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSDelete(
uriTemplate: '/zones/bulk-delete',
CQRSCommand: BulkDeleteZoneCommand::class,
scopes: [
'zone_write',
],
allowEmptyBody: false,
),
],
exceptionToStatus: [
ZoneNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkDeleteZones
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $zoneIds;
}

View File

@@ -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
*/
namespace PrestaShop\Module\APIResources\ApiPlatform\Resources\Zone;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\AttributeGroup\Exception\ZoneNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Zone\Command\BulkToggleZoneStatusCommand;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSUpdate(
uriTemplate: '/zones/bulk-update-status',
output: false,
CQRSCommand: BulkToggleZoneStatusCommand::class,
CQRSCommandMapping: [
'[enabled]' => '[expectedStatus]',
],
scopes: [
'zone_write',
],
),
],
exceptionToStatus: [
ZoneNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class BulkUpdateStatusZone
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
public array $zoneIds;
public bool $enabled;
}

View File

@@ -0,0 +1,110 @@
<?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\Zone;
use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Zone\Command\AddZoneCommand;
use PrestaShop\PrestaShop\Core\Domain\Zone\Command\DeleteZoneCommand;
use PrestaShop\PrestaShop\Core\Domain\Zone\Command\EditZoneCommand;
use PrestaShop\PrestaShop\Core\Domain\Zone\Command\ToggleZoneStatusCommand;
use PrestaShop\PrestaShop\Core\Domain\Zone\Exception\ZoneNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Zone\Query\GetZoneForEditing;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSCreate;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSDelete;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;
#[ApiResource(
operations: [
new CQRSCreate(
uriTemplate: '/zones',
validationContext: ['groups' => ['Default', 'Create']],
CQRSCommand: AddZoneCommand::class,
scopes: ['zone_write'],
CQRSCommandMapping: self::COMMAND_MAPPING,
),
new CQRSDelete(
uriTemplate: '/zones/{zoneId}',
requirements: ['zoneId' => '\d+'],
output: false,
CQRSCommand: DeleteZoneCommand::class,
scopes: ['zone_write']
),
new CQRSGet(
uriTemplate: '/zones/{zoneId}',
requirements: ['zoneId' => '\d+'],
CQRSQuery: GetZoneForEditing::class,
scopes: ['zone_read'],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSUpdate(
uriTemplate: '/zones/{zoneId}/toggle-status',
requirements: ['zoneId' => '\d+'],
output: false,
allowEmptyBody: true,
CQRSCommand: ToggleZoneStatusCommand::class,
scopes: ['zone_write'],
),
new CQRSUpdate(
uriTemplate: '/zones/{zoneId}',
requirements: ['zoneId' => '\d+'],
read: false,
CQRSCommand: EditZoneCommand::class,
CQRSQuery: GetZoneForEditing::class,
scopes: ['zone_write'],
CQRSCommandMapping: self::COMMAND_MAPPING,
CQRSQueryMapping: self::QUERY_MAPPING,
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [
ZoneNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class Zone
{
#[ApiProperty(identifier: true)]
public int $zoneId;
#[Assert\NotBlank(groups: ['Create'])]
#[Assert\Length(min: 1, max: 64)]
public string $name;
#[Assert\NotNull(groups: ['Create'])]
public bool $enabled;
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank(allowNull: true)]
public array $shopIds;
public const COMMAND_MAPPING = [
'[shopIds]' => '[shopAssociation]',
];
public const QUERY_MAPPING = [
'[associatedShops]' => '[shopIds]',
];
}

Some files were not shown because too many files have changed in this diff Show More