Skip to content
Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
23 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
2e478e9
Fix ShopConstraint mapping and ValueObject getValue() in Carrier query
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
d9640f0
Merge pull request #2 from bwlab/add-delete-carrier-endpoint
luigimassa Mar 17, 2026
750cf83
Merge branch 'PrestaShop:dev' into dev
luigimassa Mar 30, 2026
263ef7c
Refactor testGetCarrier to compare full response object
luigimassa Mar 30, 2026
ef0e8b0
Merge branch 'dev' into add-carrier-endpoints
luigimassa Mar 30, 2026
ed167cf
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
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+'],
),
],
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 = [];
}
121 changes: 121 additions & 0 deletions src/ApiPlatform/Resources/Carrier/Carrier.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?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\Domain\Carrier\Query\GetCarrierForEditing;
use PrestaShopBundle\ApiPlatform\Metadata\CQRSGet;
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,
),
],
normalizationContext: ['skip_null_values' => false],
exceptionToStatus: [
CarrierNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
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 = [
'[_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]',
'[shippingMethod]' => '[getShippingMethod][getValue]',
'[idTaxRuleGroup]' => '[getIdTaxRuleGroup]',
'[rangeBehavior]' => '[getRangeBehavior][getValue]',
'[associatedShopIds]' => '[getAssociatedShopIds]',
'[zones]' => '[getZones]',
'[ordersCount]' => '[getOrdersCount]',
];
}
67 changes: 67 additions & 0 deletions src/ApiPlatform/Resources/Carrier/CarrierList.php
Original file line number Diff line number Diff line change
@@ -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
*/

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,
),
],
exceptionToStatus: [
CarrierNotFoundException::class => Response::HTTP_NOT_FOUND,
],
)]
class CarrierList

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need a test for this endpoint.

{
#[ApiProperty(identifier: true)]
public int $carrierId;

public string $name;

public ?string $delay;

public bool $active;

public bool $isFree;

public int $position;

public ?string $logo;
}
18 changes: 18 additions & 0 deletions tests/Integration/ApiPlatform/AddressEndpointTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ public static function tearDownAfterClass(): void

public static function getProtectedEndpoints(): iterable
{
yield 'get address required fields endpoint' => [
'GET',
'/addresses/required-fields',
];

yield 'get customer address endpoint' => [
'GET',
'/addresses/customers/1',
Expand Down Expand Up @@ -498,4 +503,17 @@ public function testAddressValidation(): void
// Use the createItem method but expect it to fail with validation error
$this->createItem('/addresses/customers', $invalidData, ['address_write'], 422);
}

public function testGetAddressRequiredFields(): void
{
$result = $this->getItem('/addresses/required-fields', ['address_read']);
$this->assertArrayHasKey('requiredFields', $result);
$this->assertIsArray($result['requiredFields']);

// Assert some common required fields are present
if (!empty($result['requiredFields'])) {
// Just verifying it's an array of strings
$this->assertIsString($result['requiredFields'][0]);
}
}
}