Skip to content
Closed
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
bb9ebd5
Add GET /addresses/required-fields API endpoint
luigimassa Mar 5, 2026
645d208
cs fix
luigimassa Mar 9, 2026
60e3ac8
Add GET /carriers API endpoint
luigimassa Mar 9, 2026
e7a1829
Implement GET /carriers API endpoint
luigimassa Mar 9, 2026
1c1c252
Implement GET /carriers/{carrierId} API endpoint
luigimassa Mar 9, 2026
e742901
Implement GET /carriers/{carrierId}/ranges API endpoint
luigimassa Mar 9, 2026
e19bb04
Implement GET /carriers/{carrierId}/ranges API endpoint
luigimassa Mar 9, 2026
3980395
Fix ShopConstraint mapping and ValueObject getValue() in Carrier queries
luigimassa Mar 9, 2026
77e7701
Map CarrierConstraintException to 422 in CarrierRanges endpoint
luigimassa Mar 9, 2026
831c8fa
Add TODO.md with known limitation for GET /carriers/{carrierId}/ranges
luigimassa Mar 9, 2026
fdb1627
Add toggle-status and toggle-is-free endpoints for carriers
luigimassa Mar 10, 2026
9c84ea8
Add BulkToggleCarrierStatusCommand endpoint for carriers
luigimassa Mar 15, 2026
8ba2ce2
Add Assert\Positive validation on carrierIds to prevent invalid IDs
luigimassa Mar 15, 2026
1419281
Fix deserialization: set explicit input class to prevent direct comma…
luigimassa Mar 15, 2026
98dc573
Fix BulkCarriers: remove explicit input override to restore CQRSApiNo…
luigimassa Mar 16, 2026
2b45287
Add Assert\Type numeric validation on carrierIds to prevent 500 errors
luigimassa Mar 17, 2026
093c206
Add DELETE /carriers/{carrierId} endpoint and CarrierList filters map…
luigimassa Mar 17, 2026
d058391
Refactor testGetCarrier to compare full response object
luigimassa Mar 30, 2026
36d9979
Fix QUERY_MAPPING conventions and remove TODO.md
luigimassa Mar 30, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# TODO

## GET /carriers/{carrierId}/ranges — Core limitation

**Stato:** Endpoint implementato ma non funzionante (restituisce 422)

**Causa:** `CarrierRangeRepository::assertShopConstraint()` nel core PrestaShop accetta
solo `ShopConstraint::allShops()`, ma il framework API passa sempre un constraint
shop-specifico (es. `shopId=1`). La funzione `applyShopConstraint()` ha un TODO
irrisolto nel core.

**File coinvolti:**
- Modulo: `src/ApiPlatform/Resources/Carrier/CarrierRanges.php`
- Core PS: `src/Adapter/Carrier/Repository/CarrierRangeRepository.php` (righe 220-237)

**Fix richiesto:**
1. Aprire una issue/PR nel repo `PrestaShop/PrestaShop` per implementare
`CarrierRangeRepository::applyShopConstraint()` con supporto ai constraint shop-specifici
2. Una volta fixato il core, verificare che l'endpoint funzioni correttamente
3. Valutare se rimuovere o mantenere il mapping `CarrierConstraintException → 422`

**Workaround attuale:** `CarrierConstraintException` mappata a HTTP 422 invece di 500.
Comment thread
luigimassa marked this conversation as resolved.
Resolved
5 changes: 5 additions & 0 deletions src/ApiPlatform/Resources/Address/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use ApiPlatform\Metadata\NotExposed;
use PrestaShop\PrestaShop\Core\Domain\Address\Command\DeleteAddressCommand;
use PrestaShop\PrestaShop\Core\Domain\Address\Exception\AddressConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Address\Exception\AddressNotFoundException;
Expand All @@ -38,6 +39,10 @@
'address_write',
],
),
new NotExposed(
uriTemplate: '/addresses/{addressId}',
requirements: ['addressId' => '\d+'],
),
Comment thread
luigimassa marked this conversation as resolved.
Resolved
],
exceptionToStatus: [
AddressConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
Expand Down
54 changes: 54 additions & 0 deletions src/ApiPlatform/Resources/Address/AddressRequiredFields.php
Original file line number Diff line number Diff line change
@@ -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
*/

declare(strict_types=1);

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

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Address\Query\GetRequiredFieldsForAddress;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;

#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/addresses/required-fields',
CQRSQuery: GetRequiredFieldsForAddress::class,
scopes: ['address_read'],
CQRSQueryMapping: ['[@index]' => '[requiredFields][@index]'],
),
],
normalizationContext: ['skip_null_values' => false],
)]
class AddressRequiredFields
{
/**
* @var string[]
*/
#[ApiProperty(
openapiContext: [
'type' => 'array',
'items' => ['type' => 'string'],
'example' => ['phone', 'company'],
]
)]
public array $requiredFields = [];
}
65 changes: 65 additions & 0 deletions src/ApiPlatform/Resources/Carrier/BulkCarriers.php
Original file line number Diff line number Diff line change
@@ -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\Carrier;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Carrier\Command\BulkToggleCarrierStatusCommand;
use PrestaShop\PrestaShop\Core\Domain\Carrier\Exception\CarrierConstraintException;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSUpdate;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Validator\Constraints as Assert;

#[ApiResource(
operations: [
new CQRSUpdate(
uriTemplate: '/carriers/bulk-set-status',
output: false,
CQRSCommand: BulkToggleCarrierStatusCommand::class,
CQRSCommandMapping: [
'[enabled]' => '[expectedStatus]',
],
scopes: [
'carrier_write',
],
),
],
exceptionToStatus: [
CarrierConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
],
)]
class BulkCarriers
{
/**
* @var int[]
*/
#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
#[Assert\NotBlank]
#[Assert\All([
new Assert\Type('numeric'),
new Assert\Positive(),
])]
public array $carrierIds;

public bool $enabled;
}
150 changes: 150 additions & 0 deletions src/ApiPlatform/Resources/Carrier/Carrier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
<?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\Carrier;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Carrier\Command\DeleteCarrierCommand;
use PrestaShop\PrestaShop\Core\Domain\Carrier\Command\ToggleCarrierIsFreeCommand;
use PrestaShop\PrestaShop\Core\Domain\Carrier\Command\ToggleCarrierStatusCommand;
use PrestaShop\PrestaShop\Core\Domain\Carrier\Exception\CarrierConstraintException;
use PrestaShop\PrestaShop\Core\Domain\Carrier\Exception\CarrierNotFoundException;
use PrestaShop\PrestaShop\Core\Domain\Carrier\Query\GetCarrierForEditing;
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;

#[ApiResource(
operations: [
new CQRSGet(
uriTemplate: '/carriers/{carrierId}',
requirements: ['carrierId' => '\d+'],
CQRSQuery: GetCarrierForEditing::class,
scopes: ['carrier_read'],
CQRSQueryMapping: self::QUERY_MAPPING,
),
new CQRSUpdate(
uriTemplate: '/carriers/{carrierId}/toggle-status',
requirements: ['carrierId' => '\d+'],
output: false,
allowEmptyBody: true,
CQRSCommand: ToggleCarrierStatusCommand::class,
scopes: ['carrier_write'],
),
new CQRSUpdate(
uriTemplate: '/carriers/{carrierId}/toggle-is-free',
requirements: ['carrierId' => '\d+'],
output: false,
allowEmptyBody: true,
CQRSCommand: ToggleCarrierIsFreeCommand::class,
scopes: ['carrier_write'],
),
new CQRSDelete(
uriTemplate: '/carriers/{carrierId}',
requirements: ['carrierId' => '\d+'],
CQRSCommand: DeleteCarrierCommand::class,
scopes: ['carrier_write'],
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [
CarrierNotFoundException::class => Response::HTTP_NOT_FOUND,
CarrierConstraintException::class => Response::HTTP_UNPROCESSABLE_ENTITY,
],
)]
class Carrier
{
#[ApiProperty(identifier: true)]
public int $carrierId;

public string $name;

public int $grade;

public string $trackingUrl;

public int $position;

public bool $active;

#[LocalizedValue]
public array $delay;

public ?string $logoPath;

public int $maxWidth;

public int $maxHeight;

public int $maxDepth;

public float $maxWeight;

#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
public array $associatedGroupIds;

public bool $hasAdditionalHandlingFee;

public bool $isFree;

public int $shippingMethod;

public int $idTaxRuleGroup;

public int $rangeBehavior;

#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'integer'], 'example' => [1, 3]])]
public array $associatedShopIds;

#[ApiProperty(openapiContext: ['type' => 'array', 'items' => ['type' => 'object']])]
public array $zones;

public int $ordersCount;

public const QUERY_MAPPING = [
Comment thread
luigimassa marked this conversation as resolved.
Resolved
'[_context][shopConstraint]' => '[shopConstraint]',
'[carrierId]' => '[getCarrierId][getValue]',
'[name]' => '[getName]',
'[grade]' => '[getGrade]',
'[trackingUrl]' => '[getTrackingUrl]',
'[position]' => '[getPosition]',
'[active]' => '[isActive]',
'[delay]' => '[getLocalizedDelay]',
'[logoPath]' => '[getLogoPath]',
'[maxWidth]' => '[getMaxWidth]',
'[maxHeight]' => '[getMaxHeight]',
'[maxDepth]' => '[getMaxDepth]',
'[maxWeight]' => '[getMaxWeight]',
'[associatedGroupIds]' => '[getAssociatedGroupIds]',
'[hasAdditionalHandlingFee]' => '[hasAdditionalHandlingFee]',
'[isFree]' => '[isFree]',
Comment thread
luigimassa marked this conversation as resolved.
Resolved
'[shippingMethod]' => '[getShippingMethod][getValue]',
'[idTaxRuleGroup]' => '[getIdTaxRuleGroup]',
'[rangeBehavior]' => '[getRangeBehavior][getValue]',
'[associatedShopIds]' => '[getAssociatedShopIds]',
'[zones]' => '[getZones]',
'[ordersCount]' => '[getOrdersCount]',
];
}
71 changes: 71 additions & 0 deletions src/ApiPlatform/Resources/Carrier/CarrierList.php
Original file line number Diff line number Diff line change
@@ -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\Carrier;

use ApiPlatform\Metadata\ApiProperty;
use ApiPlatform\Metadata\ApiResource;
use PrestaShop\PrestaShop\Core\Domain\Carrier\Exception\CarrierNotFoundException;
use PrestaShop\PrestaShop\Core\Search\Filters\CarrierFilters;
use PrestaShopBundle\ApiPlatform\Metadata\PaginatedList;
use PrestaShopBundle\ApiPlatform\Provider\QueryListProvider;
use Symfony\Component\HttpFoundation\Response;

#[ApiResource(
operations: [
new PaginatedList(
uriTemplate: '/carriers',
provider: QueryListProvider::class,
scopes: ['carrier_read'],
ApiResourceMapping: [
'[id_carrier]' => '[carrierId]',
'[is_free]' => '[isFree]',
],
gridDataFactory: 'prestashop.core.grid.data.factory.carrier',
filtersClass: CarrierFilters::class,
filtersMapping: [
'[carrierId]' => '[id_carrier]',
'[isFree]' => '[is_free]',
],
),
],
exceptionToStatus: [
CarrierNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class CarrierList
{
#[ApiProperty(identifier: true)]
public int $carrierId;

public string $name;

public ?string $delay;

public bool $active;

public bool $isFree;

public int $position;

public ?string $logo;
}
Loading