Skip to content

Commit

Permalink
docs, Add request with add to cart
Browse files Browse the repository at this point in the history
  • Loading branch information
AdamKasp committed Mar 18, 2021
1 parent e897b80 commit 67a3ddc
Showing 1 changed file with 50 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,56 +30,75 @@ In the response you will see that this product has 2 product options:
With this data you can check all the available product option values for each product option:

.. code-block:: bash
curl -X GET "https://master.demo.sylius.com/api/v2/shop/product-options/dress_size" -H "accept: application/ld+json"
The response with all the available option values would be:
The response with all the available option values would contain:

.. code-block:: json
...
"values": [
"/api/v2/shop/product-option-values/dress_s",
"/api/v2/shop/product-option-values/dress_m",
"/api/v2/shop/product-option-values/dress_l",
"/api/v2/shop/product-option-values/dress_xl",
"/api/v2/shop/product-option-values/dress_xxl"
],
...
{
"values": [
"/api/v2/shop/product-option-values/dress_s",
"/api/v2/shop/product-option-values/dress_m",
"/api/v2/shop/product-option-values/dress_l",
"/api/v2/shop/product-option-values/dress_xl",
"/api/v2/shop/product-option-values/dress_xxl"
],
}
In the same way, you can check values for the other option - ``dress_height``.

Now, with all necessary data, you can find the "Beige strappy summer dress" product's "small" and "petite" variant
You need to call a GET on the product variants collection with parameters: ``productName`` and with the chosen option values:

.. code-block:: bash
curl -X GET "https://master.demo.sylius.com/api/v2/shop/product-variants?product=%2Fapi%2Fv2%2Fshop%2Fproducts%2FBeige_strappy_summer_dress&
optionValues%5B%5D=%2Fapi%2Fv2%2Fshop%2Fproduct-option-values%2Fdress_height_petite&
optionValues%5B%5D=%2Fapi%2Fv2%2Fshop%2Fproduct-option-values%2Fdress_s" -H "accept: application/ld+json"
curl -X GET "https://master.demo.sylius.com/api/v2/shop/product-variants?product=/api/v2/shop/products/Beige_strappy_summer_dress&optionValues[]=/api/v2/shop/product-option-values/dress_height_petite&optionValues[]=/api/v2/shop/product-option-values/dress_s" -H "accept: application/ld+json"
In the response you should get a collection with only one item:

.. code-block:: json
"hydra:member": [
{
"id": 579960,
"code": "Beige_strappy_summer_dress-variant-0",
"product": "/api/v2/shop/products/Beige_strappy_summer_dress",
"optionValues": [
"/api/v2/shop/product-option-values/dress_s",
"/api/v2/shop/product-option-values/dress_height_petite"
],
"translations": {
"en_US": {
"@id": "/api/v2/shop/product-variant-translation/579960",
"@type": "ProductVariantTranslation",
"hydra:member": [
{
"id": 579960,
"name": "S Petite",
"locale": "en_US"
}
},
"price": 7693
"code": "Beige_strappy_summer_dress-variant-0",
"product": "/api/v2/shop/products/Beige_strappy_summer_dress",
"optionValues": [
"/api/v2/shop/product-option-values/dress_s",
"/api/v2/shop/product-option-values/dress_height_petite"
],
"translations": {
"en_US": {
"@id": "/api/v2/shop/product-variant-translation/579960",
"@type": "ProductVariantTranslation",
"id": 579960,
"name": "S Petite",
"locale": "en_US"
}
},
"price": 7693
}
.. warning::
When you search by only some of the product's option values in the response you may get a collection with more than one object.
And with this information, you can add the chosen ``product variant`` to the cart.
And with this information, you can add the chosen ``product variant`` to the cart:
.. code-block:: bash
curl -X PATCH "https://master.demo.sylius.com/api/v2/shop/orders/ORDER_TOKEN/items" -H "accept: application/ld+json" -H "Content-Type: application/merge-patch+json"
with body:
.. code-block:: json
{
"productCode": "Beige_strappy_summer_dress",
"productVariantCode": "Beige_strappy_summer_dress-variant-0",
"quantity": 1
}

0 comments on commit 67a3ddc

Please sign in to comment.