Sylius version affected: 1.x.y
Description
Inside the REST API, it is impossible to patch a variant that has code containing a forward slash.
Example: Patch /api/v2/products/122013424253/variants/36/34
Steps to reproduce
Make product and a variant code with a forward slash
Possible Solution
It seems that Magento had this issue once, but it was fixed. it appears there were some work-arounds.
https://github.com/magento/magento2/issues/8615
In the route definition we are missing the requirement for the code.
https://github.com/Sylius/Sylius/blob/master/src/Sylius/Bundle/AdminApiBundle/Resources/config/routing/product_variant.yml#L59
sylius_admin_api_product_variant_show:
path: /variants/{code}
methods: [GET]
requirements:
code: .+
defaults:
_controller: sylius.controller.product_variant:showAction
_sylius:
serialization_version: $version
section: admin_api
serialization_groups: [Default, Detailed]
repository:
method: findOneByCodeAndProductCode
arguments: [$code, $productCode]
Try to URI encode the code so 36/34 becomes 36%2F34.
Did you try and it worked for you- because this was the very first I tried.
Doesn't work here - check the link I mentioned, it has a bit about encoded URI.
I tried with Sylius 1.4 and it gives me an error if I try to create a variant with such code: Product variant code can only be comprised of letters, numbers, dashes and underscores.
However, I changed it in the database, tried with URI encoded code and got 404 Not Found.
Conclusion: don't use / in codes, use - or _.
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in a week if no further activity occurs. Thank you for your contributions.
Most helpful comment
I tried with Sylius 1.4 and it gives me an error if I try to create a variant with such code:
Product variant code can only be comprised of letters, numbers, dashes and underscores.However, I changed it in the database, tried with URI encoded code and got 404 Not Found.
Conclusion: don't use
/in codes, use-or_.