-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multi-device support for customer cart in GraphQL
- Loading branch information
Showing
2 changed files
with
39 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
## Problem statement | ||
|
||
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. | ||
|
||
|
||
## Proposed solution | ||
|
||
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: | ||
```graphql | ||
getMyCartId(): String! | ||
``` | ||
This operation will only work for registered customers (valid customer token must be provided in headers). | ||
|
||
### Scenario | ||
|
||
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): | ||
|
||
| Step | Device | Operation | Headers | Response | | ||
|------|------------|-------------------------------------------------------------------------------|----------------|---------------------------------------------------| | ||
| 1 | Laptop | getMyCartId() | customer-token | 123e4567 | | ||
| 2 | Laptop | addProductsToCart("123e4567", [{"sku": "productA", "quantity": 2}]) {cart_id} | customer-token | 123e4567 | | ||
| 3 | Smartphone | getMyCartId() | customer-token | 123e4567 | | ||
| 4 | Smartphone | getCart("123e4567") {cart_items {sku, quantity}} | customer-token | {cart_items: [{"sku": "productA", "quantity": 2]} | | ||
|
||
|
||
## Alternatives | ||
|
||
- 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. | ||
- guest still need to use `createEmptyCart` to obtain cart ID | ||
- `optional` argument makes semantics less clear |