Skip to content

Commit 4c7e673

Browse files
authored
Merge pull request magento#361 from mslabko/patch-1
Provide option details
2 parents b089037 + 455bc73 commit 4c7e673

File tree

1 file changed

+124
-12
lines changed

1 file changed

+124
-12
lines changed

design-documents/graph-ql/coverage/add-items-to-cart-single-mutation.md

Lines changed: 124 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,126 @@ In order to simplify the flow of adding different type of products to wishlist a
1212
- Options are sets of predefined values that a buyer can add to cart/wishlist in addition to a product.
1313
- The difference between wish list and cart payloads is that all fields in wishlist are optional.
1414

15-
### Examples
15+
### Options
16+
17+
Each product may have options. Option can be of 2 types (see example below):
18+
- `selected_options` - predefined and selected by customer option. E.g. it can be customizable option: `color: green` or bundle option: `Memory: 24M, Warranty: 1y`:
19+
```
20+
"selected_options" : [
21+
"Y3VzdG9tLW9wdGlvbi8yNC80Mg=="
22+
],
23+
```
24+
- `entered_options` - option entered by customer like: text field, image, etc.
25+
```
26+
"entered_options": [
27+
{
28+
id: "Y3VzdG9tLW9wdGlvbi8zMQ==",
29+
value: "Vasia's awesome cup"
30+
}
31+
]
32+
```
33+
34+
We can consider "Selected Option" and "ID for Entered Option" as UUID. They meet the criteria:
35+
36+
- "Selected Option" represents option value, while "ID for Entered Option" represents option
37+
- Must be unique across different options
38+
- Returned from server
39+
- Used by client as is
40+
41+
Selected options can be used for:
42+
- Customizable options such as dropdwon, radiobutton, checkbox, etc
43+
- Configugrable product
44+
- Bundle Product
45+
- Downloadable product
46+
- Groupped product
47+
48+
Entered options:
49+
- Customizable options such as text field, file, etc
50+
- Gift Card (amount)
51+
52+
#### Option implementation
53+
54+
Product schema should be extended in order to provide option identifier (aka first iteration of "UUID").
55+
Until introducing UUID lets name this identifier as *"id_v2"
56+
57+
Option *id_v2* is `base64` encoded string, that encodes details for each option and in most cases can be presented as
58+
`base64("<option-type>/<option-id>/<option-value-id>")`
59+
For example, for customizable drop-down option "Color(id = 1), with values Red(id = 1), Green(id = 2)" id_v2 for Color:Red will looks like `"Y3VzdG9tLW9wdGlvbi8xLzE=" => base64("custom-option/1/1")`
60+
61+
Here is a GQL query that shows how to add a new field "id_v2: String!" to cover existing cases:
62+
63+
64+
``` graphql
65+
query {
66+
products(filter: { price: { from: "0.00001" } }) {
67+
items {
68+
sku
69+
... on CustomizableProductInterface {
70+
options {
71+
option_id
72+
title
73+
... on CustomizableRadioOption {
74+
title
75+
value {
76+
id_v2 # introduce new id_v2 field in CustomizableRadioValue
77+
option_type_id
78+
title
79+
}
80+
}
81+
... on CustomizableDropDownOption {
82+
title
83+
value {
84+
id_v2 # introduce new id_v2 field in CustomizableDropDownValue
85+
# see \Magento\QuoteGraphQl\Model\Cart\BuyRequest\CustomizableOptionsDataProvider
86+
option_type_id
87+
title
88+
}
89+
}
90+
# ... on all other custom options types
91+
}
92+
} ... on ConfigurableProduct {
93+
variants {
94+
attributes {
95+
id_v2 # introduce new id_v2 field in ConfigurableAttributeOption (format: configurable/<attribute-id>/<value_index>)
96+
# see \Magento\ConfigurableProductGraphQl\Model\Cart\BuyRequest\SuperAttributeDataProvider
97+
code
98+
value_index
99+
}
100+
}
101+
} ... on DownloadableProduct {
102+
downloadable_product_links {
103+
id_v2 # introduce new id_v2 field in DownloadableProductLinks (format: downloadable/link/<link_id>)
104+
# see \Magento\DownloadableGraphQl\Model\Cart\BuyRequest\DownloadableLinksDataProvider
105+
title
106+
}
107+
} ... on BundleProduct {
108+
items {
109+
sku
110+
title
111+
options {
112+
id_v2 # introduce new id_v2 field in BundleItemOption (format: bundle/<option-id>/<option-value-id>/<option-quantity>)
113+
# see \Magento\BundleGraphQl\Model\Cart\BuyRequest\BundleDataProvider
114+
id
115+
label
116+
}
117+
}
118+
} ... on GiftCardProduct {
119+
giftcard_amounts {
120+
id_v2 # introduce new id_v2 field in GiftCardAmounts (format: giftcard/...TBD)
121+
# see \Magento\GiftCard\Model\Quote\Item\CartItemProcessor::convertToBuyRequest
122+
value_id
123+
website_id
124+
value
125+
attribute_id
126+
website_value
127+
}
128+
}
129+
}
130+
}
131+
}
132+
```
133+
134+
## Examples
16135

17136
#### Add simple product to cart
18137
```
@@ -21,12 +140,12 @@ In order to simplify the flow of adding different type of products to wishlist a
21140
"sku": "Cup",
22141
"qty": 1,
23142
"selected_options" : [
24-
"Y29uZmlndXJhYmxlLzI0LzQy" //base64_encode('configurable/24/42')
143+
"Y3VzdG9tLW9wdGlvbi8yNC80Mg==" //base64_encode('custom-option/24/42')
25144
],
26145
"entered_options": [
27146
{
28147
id: "Y3VzdG9tLW9wdGlvbi8zMQ==", //base64_encode("custom-option/31")
29-
value: "VmFzaWEncyBhd2Vzb21lIGN1cA==" // base64_encode("Vasia's awesome cup")
148+
value: "Vasia's awesome cup"
30149
}
31150
]
32151
}
@@ -36,20 +155,13 @@ In order to simplify the flow of adding different type of products to wishlist a
36155
In this example we want to add _personalized blue cup to cart_ to cart.
37156

38157
- `selected_options` - predefined and selected by customer options. `base64` encoding will help to use UUID in future.
39-
:warning: The encoded value will be returned from server and should be used by client as is. In order to achieve this:
40-
41-
``` graphql
42-
interface CustomizableOptionInterface {
43-
...
44-
id: ID @doc(description: "Option ID.")
45-
}
46-
```
158+
:warning: The encoded value will be returned from server and should be used by client as is.
47159

48160
In this example values will be following:
49161

50162
| Name | Value | Buyer Selection |
51163
| ------------- | ------------- | ------------- |
52-
| option-type | configurable |
164+
| option-type | custom-option |
53165
| option-id | 24 | color |
54166
| option-value-id | 42 | blue |
55167

0 commit comments

Comments
 (0)