From 67a3ddcb0c394ac8b2c18d74f932183aac7cba3b Mon Sep 17 00:00:00 2001 From: Adam Kasperczak Date: Wed, 17 Mar 2021 21:50:21 +0100 Subject: [PATCH] docs, Add request with add to cart --- ...cart_product_chosen_by_product_options.rst | 81 ++++++++++++------- 1 file changed, 50 insertions(+), 31 deletions(-) diff --git a/docs/api/unified_api/add_to_cart_product_chosen_by_product_options.rst b/docs/api/unified_api/add_to_cart_product_chosen_by_product_options.rst index 6cbe8722792..aa3cbf3e2fd 100644 --- a/docs/api/unified_api/add_to_cart_product_chosen_by_product_options.rst +++ b/docs/api/unified_api/add_to_cart_product_chosen_by_product_options.rst @@ -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 + }