Skip to content

Commit 9d39bbf

Browse files
committed
Multi-device support for customer cart in GraphQL
1 parent d186633 commit 9d39bbf

File tree

2 files changed

+39
-7
lines changed

2 files changed

+39
-7
lines changed

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
**Overview**
22

3+
:warning: Current proposal is deprecated in favor of [add-items-to-cart-single-mutation.md](add-items-to-cart-single-mutation.md)
4+
35
As a Magento developer, I need to manipulate the shopping cart via GraphQL so that I can programmatically create orders on behalf of a shopper.
46

57
GraphQL needs to provide sufficient mutations (ways to create/update/delete data) for a developer to build out the storefront checkout experience for a shopper.
@@ -31,13 +33,13 @@ GraphQL needs to provide sufficient mutations (ways to create/update/delete data
3133

3234
**Proposed schema for adding items to cart:**
3335

34-
- [AddSimpleProductToCart](AddSimpleProductToCart.graphqls)
35-
- [AddBundleProductToCart](AddBundleProductToCart.graphqls)
36-
- [AddConfigurableProductToCart](AddConfigurableProductToCart.graphqls)
37-
- [AddDownloadableProductToCart](AddDownloadableProductToCart.graphqls)
38-
- [AddGiftCardProductToCart](AddGiftCardProductToCart.graphqls)
39-
- [AddGroupedProductToCart](AddGroupedProductToCart.graphqls)
40-
- [AddVirtualProductToCart](AddVirtualProductToCart.graphqls)
36+
- [AddSimpleProductToCart](add-items-to-cart/AddSimpleProductToCart.graphqls)
37+
- [AddBundleProductToCart](add-items-to-cart/AddBundleProductToCart.graphqls)
38+
- [AddConfigurableProductToCart](add-items-to-cart/AddConfigurableProductToCart.graphqls)
39+
- [AddDownloadableProductToCart](add-items-to-cart/AddDownloadableProductToCart.graphqls)
40+
- [AddGiftCardProductToCart](add-items-to-cart/AddGiftCardProductToCart.graphqls)
41+
- [AddGroupedProductToCart](add-items-to-cart/AddGroupedProductToCart.graphqls)
42+
- [AddVirtualProductToCart](add-items-to-cart/AddVirtualProductToCart.graphqls)
4143

4244

4345
**My Account area impacted:**
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Problem statement
2+
3+
Registered customer should be able to work with the same shopping cart using multiple devices. For example, add products to cart using a laptop and complete checkout using a smartphone.
4+
5+
6+
## Proposed solution
7+
8+
To achieve desired behavior there should be a way to retrieve active customer cart ID from the server. Based on the assumption that there could be only one active cart per customer at any given moment this can be done as follows:
9+
```graphql
10+
getMyCartId(): String!
11+
```
12+
This operation will only work for registered customers (valid customer token must be provided in headers).
13+
14+
### Scenario
15+
16+
In the following scenario a logged in user adds a product to the cart. After logging in to his account from the smartphone the cart still contains added product (actual GraphQL queries are replaced with pseudocode for simplicity):
17+
18+
| Step | Device | Operation | Headers | Response |
19+
|------|------------|-------------------------------------------------------------------------------|----------------|---------------------------------------------------|
20+
| 1 | Laptop | getMyCartId() | customer-token | 123e4567 |
21+
| 2 | Laptop | addProductsToCart("123e4567", [{"sku": "productA", "quantity": 2}]) {cart_id} | customer-token | 123e4567 |
22+
| 3 | Smartphone | getMyCartId() | customer-token | 123e4567 |
23+
| 4 | Smartphone | getCart("123e4567") {cart_items {sku, quantity}} | customer-token | {cart_items: [{"sku": "productA", "quantity": 2]} |
24+
25+
26+
## Alternatives
27+
28+
- It is possible to make `cartId` optional argument and rely on `getCart {cart_id}` query for fetching customer cart ID. When used by customer, ID is not required. When used by guest - ID is required.
29+
- guest still need to use `createEmptyCart` to obtain cart ID
30+
- `optional` argument makes semantics less clear

0 commit comments

Comments
 (0)