11 KiB
UPGRADE FROM v1.11.X TO v1.12.0
-
The
Sylius\Bundle\ApiBundle\DataProvider\CartShippingMethodsSubresourceDataProviderhas been removed and replaced bySylius\Bundle\ApiBundle\DataProvider\ShippingMethodsCollectionDataProvider. -
The
Sylius\Bundle\ApiBundle\Provider\CustomerProviderInterfacehas been removed and replaced bySylius\Bundle\CoreBundle\Resolver\CustomerResolverInterface. -
The
Sylius\Bundle\ApiBundle\Serializer\ShippingMethodNormalizerlogic and constructor has been changed due to refactor above.public function __construct( private OrderRepositoryInterface $orderRepository, private ShipmentRepositoryInterface $shipmentRepository, private ServiceRegistryInterface $shippingCalculators, + private RequestStack $requestStack, + private ChannelContextInterface $channelContext ) { ... } -
The
GETapi/v2/shop/orders/{token}/shipments/{id}/methodsandapi/v2/shop/shipments/{id}/methodsendpoints have been removed and changed into collection request with 2 parametersapi/v2/shop/shipping-methods?shipmentId={id}&tokenValue={token}. Now when we do not provide parameters in response it returns all availableshippingMethodsin channel. Wrong parameters otherwise cause empty array[]in response and correct parameters returnshippingMethodsavailable for yourshipment.
Here is how the response looks like:{ "@context": "/api/v2/contexts/ShippingMethod", "@id": "/api/v2/shop/shipping-methods", "@type": "hydra:Collection", "hydra:member": [ { "@id": "/api/v2/shop/shipping-methods/ups", "@type": "ShippingMethod", "id": 1, "code": "ups", "position": 0, "name": "UPS", "description": "Quasi perferendis debitis officiis ut inventore exercitationem." } ], "hydra:totalItems": 1, "hydra:search": { "@type": "hydra:IriTemplate", "hydra:template": "/api/v2/shop/shipping-methods{?shipmentId,tokenValue}", "hydra:variableRepresentation": "BasicRepresentation", "hydra:mapping": [ { "@type": "IriTemplateMapping", "variable": "shipmentId", "property": null, "required": false }, { "@type": "IriTemplateMapping", "variable": "tokenValue", "property": null, "required": false } ] } } -
Service
src/Sylius/Bundle/ApiBundle/DataProvider/CartPaymentMethodsSubresourceDataProvider.phphas been removed and logic was replaced bysrc/Sylius/Bundle/ApiBundle/DataProvider/PaymentMethodsCollectionDataProvider.php -
Endpoints
/shop/orders/{tokenValue}/payments/{payments}/methods,/shop/payments/{id}/methodshas been removed and replaced by/shop/payment-methodswith filterpaymentIdandtokenValue/shop/payment-methodsreturns all enable payment methods if filters are not set, payment methods related to payment if filters are filled or empty response if filters ale filled with invalid data. -
Service
Sylius\Bundle\ApiBundle\DataProvider/CartPaymentMethodsSubresourceDataProviderhas been removed and logic was replaced bySylius\Bundle\ApiBundle\DataProvider\PaymentMethodsCollectionDataProvider -
The
GETapi/v2/shop/orders/{tokenValue}/payments/{payments}/methodsandapi/v2/shop/payments/{id}/methodsendpoints have been removed and changed into collection request with 2 parametersapi/v2/shop/payment-methods?paymentId={id}&tokenValue={token}. Now when we do not provide parameters in response it returns all availablepaymentMethodsin channel. Wrong parameters otherwise cause empty array[]in response and correct parameters returnpaymentMethodsavailable for yourpayment. -
All arguments of
src/Sylius/Bundle/ApiBundle/CommandHandler/Account/ResetPasswordHandlerhave been removed and substituted withSylius\Bundle\CoreBundle\Security\UserPasswordResetter. -
The file
src/Sylius/Bundle/ApiBundle/Resources/config/api_resources/ResetPassword.xmlhas been renamed tosrc/Sylius/Bundle/ApiBundle/Resources/config/api_resources/AccountResetPassword.xmland its short name has been changed fromResetPasswordRequesttoAccountResetPasswordRequest. -
Constructor of
Sylius\Bundle\ApiBundle\CommandHandler\Account\RequestResetPasswordTokenHandlerhas been extended withSylius\Calendar\Provider\DateTimeProviderInterfaceargument:public function __construct( private UserRepositoryInterface $userRepository, private MessageBusInterface $commandBus, - private GeneratorInterface $generator + private GeneratorInterface $generator, + private DateTimeProviderInterface $calendar ) { } -
Constructor of
\Sylius\Bundle\ApiBundle\CommandHandler\Account\VerifyCustomerAccountHandlerhas been extended withSylius\Calendar\Provider\DateTimeProviderInterfaceargument:- public function __construct(private RepositoryInterface $shopUserRepository) - { + public function __construct( + private RepositoryInterface $shopUserRepository, + private DateTimeProviderInterface $calendar + ) { } -
The 2nd parameter
localeCodehas been removed fromsrc/Sylius/Bundle/ApiBundle/Command/Cart/PickupCart.phpand now is set automatically bysrc/Sylius/Bundle/ApiBundle/DataTransformer/LocaleCodeAwareInputCommandDataTransformer.php. -
The responses of endpoints
/api/v2/admin/productsand/api/v2/admin/products/{code}have been changed in such a way that the fielddefaultVarianthas been removed. -
The configuration of
config/packages/security.yamlhas to be updated:security: access_control: + - { path: "%sylius.security.new_api_admin_route%/reset-password-requests", role: IS_AUTHENTICATED_ANONYMOUSLY } -
The second argument
$billingAddressofSylius\Bundle\ApiBundle\Modifier\OrderAddressModifierInterface::modifyhas become nullable. -
The
Sylius\Bundle\ApiBundle\Assigner\OrderPromoCodeAssignerInterfacehas been renamed toSylius\Bundle\ApiBundle\Assigner\OrderPromotionCodeAssignerInterface.
API clients refactor
New way of defining the clients
In the 1.12 version we changed the way of defining API clients in our behat contexts.
We extended the Sylius/Behat/Client/ApiClientInterface methods with extra parameter $resource.
- public function index(): Response
+ public function index(string $resource): Response
- public function subResourceIndex(string $subResource, string $id): Response;
+ public function subResourceIndex(string $resource, string $subResource, string $id): Response;
- public function show(string $id): Response;
+ public function show(string $resource, string $id): Response;
- public function delete(string $id): Response;
+ public function delete(string $resource, string $id): Response;
- public function applyTransition(string $id, string $transition, array $content = []): Response;
+ public function applyTransition(string $resource, string $id, string $transition, array $content = []): Response;
- public function customItemAction(string $id, string $type, string $action): Response;
+ public function customItemAction(string $resource, string $id, string $type, string $action): Response;
- public function buildCreateRequest(): void;
+ public function buildCreateRequest(string $resource): void;
- public function buildUpdateRequest(string $id): void;
+ public function buildUpdateRequest(string $resource, string $id): void;
- public function buildUploadRequest(): void;
+ public function buildUploadRequest(string $resource): void;
With this change, we reduced the number of clients from one per resource to only two, one for the shop section and one for the admin. To make a call for a specific resource you must pass it inside the methods shown above.
You can see the actual difference in the example below:
- $this->avatarImagesClient->buildUploadRequest();
+ $this->client->buildUploadRequest(Resources::AVATAR_IMAGES);
The Sylius\Behat\Context\Api\Resources class contains constants for all the defined resources.
We also removed the Sylius\Behat\Client\ApiPlatformIriClient alongside with Sylius\Behat\Client\ApiIriClientInterface as it's no more used.
Changes in contexts
The constructors of the behat contexts have changed in relation to the above improvements.
Here is the example change of the constructor of Sylius\Behat\Context\Api\Admin\ManagingOrdersContext
public function __construct(
private ApiClientInterface $client,
- private ApiClientInterface $shipmentsClient,
- private ApiClientInterface $paymentsClient,
...
)
The list of changed contexts:
Admin:
- Sylius\Behat\Context\Api\Admin\ManagingAdministratorsContext
- Sylius\Behat\Context\Api\Admin\ManagingCatalogPromotionsContext
- Sylius\Behat\Context\Api\Admin\ManagingChannelsContext
- Sylius\Behat\Context\Api\Admin\ManagingCountriesContext
- Sylius\Behat\Context\Api\Admin\ManagingCurrenciesContext
- Sylius\Behat\Context\Api\Admin\ManagingCustomerGroupsContext
- Sylius\Behat\Context\Api\Admin\ManagingExchangeRatesContext
- Sylius\Behat\Context\Api\Admin\ManagingLocalesContext
- Sylius\Behat\Context\Api\Admin\ManagingOrdersContext
- Sylius\Behat\Context\Api\Admin\ManagingPaymentsContext
- Sylius\Behat\Context\Api\Admin\ManagingProductAssociationTypesContext
- Sylius\Behat\Context\Api\Admin\ManagingProductOptionsContext
- Sylius\Behat\Context\Api\Admin\ManagingProductReviewsContext
- Sylius\Behat\Context\Api\Admin\ManagingProductVariantsContext
- Sylius\Behat\Context\Api\Admin\ManagingProductsContext
- Sylius\Behat\Context\Api\Admin\ManagingPromotionsContext
- Sylius\Behat\Context\Api\Admin\ManagingShipmentsContext
- Sylius\Behat\Context\Api\Admin\ManagingShippingCategoriesContext
- Sylius\Behat\Context\Api\Admin\ManagingShippingMethodsContext
- Sylius\Behat\Context\Api\Admin\ManagingTaxCategoriesContext
- Sylius\Behat\Context\Api\Admin\ManagingZonesContext
Shop:
- Sylius\Behat\Context\Api\Shop\AddressContext
- Sylius\Behat\Context\Api\Shop\CartContext
- Sylius\Behat\Context\Api\Shop\ChannelContext
- Sylius\Behat\Context\Api\Shop\CheckoutContext
- Sylius\Behat\Context\Api\Shop\CurrencyContext
- Sylius\Behat\Context\Api\Shop\CustomerContext
- Sylius\Behat\Context\Api\Shop\HomepageContext
- Sylius\Behat\Context\Api\Shop\LocaleContext
- Sylius\Behat\Context\Api\Shop\LoginContext
- Sylius\Behat\Context\Api\Shop\OrderContext
- Sylius\Behat\Context\Api\Shop\OrderItemContext
- Sylius\Behat\Context\Api\Shop\PaymentContext
- Sylius\Behat\Context\Api\Shop\ProductContext
- Sylius\Behat\Context\Api\Shop\ProductReviewContext
- Sylius\Behat\Context\Api\Shop\ProductVariantContext
- Sylius\Behat\Context\Api\Shop\PromotionContext
- Sylius\Behat\Context\Api\Shop\RegistrationContext
- Sylius\Behat\Context\Api\Shop\ShipmentContext