-
Notifications
You must be signed in to change notification settings - Fork 86
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IBX-8947: Add 2 cart REST routes; update Cart examples #2501
Conversation
/api/ibexa/v2/cart/{identifier}/validate /api/ibexa/v2/cart/authorize
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not able to find a way to add a context like JSON does.
<CartCreate>
<name>Default</name>
<currencyCode>EUR</currencyCode>
<context>
<foo>bar</foo>
</context>
</CartCreate>
?xml version="1.0" encoding="UTF-8"?>
<ErrorMessage media-type="application/vnd.ibexa.api.ErrorMessage+xml">
<errorCode>500</errorCode>
<errorMessage>Internal Server Error</errorMessage>
<errorDescription>Array to string conversion</errorDescription>
<trace>…</trace>
<file>/var/www/html/vendor/ibexa/rest/src/lib/Output/Generator/Xml.php</file>
<line>169</line>
</ErrorMessage>
{ | ||
"CartConstraintViolationList": { | ||
"_media-type": "application\/vnd.ibexa.api.CartConstraintViolationList+json", | ||
"violations": [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't manage to insert invalid data on purpose.
I tried to add a product with no stock, it's added without any error. I thought https://github.com/ibexa/cart/blob/main/src/lib/Validation/Constraint/ProductAvailableValidator.php would complain, but no. On the storefront, the product is indicated as Out of stock but if I edit the HTML and remove the disabled
attribute from the "Add to cart" button, I can add it to the cart without error. It seems there is no product availability around there.
I tried to add a product/entry called 'test' to match the example without having configuring proper TVA for the region.
curl "$baseUri/cart/$identifier/entry" \
-b anonymous_cookies.txt -H "X-CSRF-Token: $anonymous_token" \
-H "Content-Type: $mimeTypePrefix.CartEntryAdd+$format" \
--data "@$restRefDir/input/examples/cart/entry/POST/CartEntryAdd.json.example" \
;
The cart is validated on the fly and I get the following error:
<?xml version="1.0" encoding="UTF-8"?>
<ErrorMessage media-type="application/vnd.ibexa.api.ErrorMessage+xml">
<errorCode>406</errorCode>
<errorMessage>Not Acceptable</errorMessage>
<errorDescription>Argument '$entryAddStruct' is invalid: Product "test" has no VAT Category set.</errorDescription>
<trace>…</trace>
<file>/var/www/html/vendor/ibexa/cart/src/lib/Service/CartService.php</file>
<line>239</line>
</ErrorMessage>
I tried to fix the error and reintroduce it later but fail. I had error 500 on every page of the DXP for a region VAT not found.
I stopped my test there.
properties: | ||
violations: | ||
type: array | ||
items: CartConstraintViolation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a CartConstraintViolationWrapper is needed but I didn't manage to product constraint violation to study it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! The script to generate the responses was definitely useful - especially once I got the right xq
executable 😄 (https://github.com/mikefarah/yq worked)
"_media-type": "application/vnd.ibexa.api.Cart+json", | ||
"id": 12, | ||
"identifier": "fafccc4b-cce1-40d7-8d23-29ad41638581", | ||
"_media-type": "application\/vnd.ibexa.api.Cart+json", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: should the slashes be escaped?
I see we sometimes do it and sometimes don't, does it matter?
Examples:
https://github.com/ibexa/documentation-developer/blob/master/docs/api/rest_api/rest_api_reference/input/examples/shipping/methods/identifier/GET/ShippingMethod.json.example#L3
https://github.com/ibexa/documentation-developer/blob/master/docs/api/rest_api/rest_api_reference/input/examples/content/locations/path/GET/Location.json.example#L3
Or maybe it doesn't matter?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I checked on https://www.json.org/json-en.html and further on https://ecma-international.org/publications-and-standards/standards/ecma-404/. The standard's PDF states:
All code points may
be placed within the quotation marks except for the code points that must be escaped: quotation mark
(U+0022), reverse solidus (U+005C), and the control characters U+0000 to U+001F.
[…]
\/
represents the solidus character (U+002F).
So escaping the slash (a.k.a solidus) is optional; it doesn't matter.
% echo '{ "slash": "\/" }' | jq
{
"slash": "/"
}
jq
understands it but considers it's not worth keeping it.
We could status for consistency and open a new PR about this. I would vote for removing them all.
Co-authored-by: Marek Nocoń <mnocon@users.noreply.github.com>
Add two routes:
/api/ibexa/v2/cart/{identifier}/validate
added in ibexa/cart#38 (and asked in IBX-8947)/api/ibexa/v2/cart/authorize
added in ibexa/cart#80Add XML examples and update JSON examples.
Examples generation
Done with
Checklist