Skip to content

Updated GraphQl Compare List Proposal #430

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Oct 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions design-documents/graph-ql/coverage/catalog/compare-list.graphqls
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
type ComparableItem {
productId: ID! @doc(description: "Product Id")
name: String! @doc(description: "Product name")
sku: String! @doc(description: "Product SKU")
priceRange: ProductPriceRange! @doc(description: "Product prices")
canonical_url: String @doc(description: "Product URL")
images: [ProductImage]! @doc(description: "Product Images")
values: [ProductAttribute]! @doc(description: "Product comparable attributes")
uid: ID!
product: ProductInterface!
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussion with @cpartica and @melnikovi, decided to return ProductInterface here.

attributes: [ProductAttribute]! @doc(description: "Product comparable attributes")
}

type ComparableAttribute {
uid: ID!
code: String! @doc(description: "Attribute code ")
title: String! @doc(description: "Addibute display title")
label: String! @doc(description: "Attribute label")
}

type CompareList {
Expand All @@ -28,18 +25,31 @@ type Query {
}

type Mutation {
addItemsToCompareList(
uid: ID!
items: [ID!]
createCompareList(input: CreateCompareListInput): CompareList @doc(description: "Creates a new compare list. For a logged in user, the created list is assigned to the user")
addProductsToCompareList(
input: AddProductsToCompareListInput
): CompareList
removeItemsFromCompareList(
uid: ID!
items: [ID!]
removeProductsFromCompareList(
input: RemoveProductsFromCompareListInput
): CompareList
assignCompareListToCustomer(listUid: ID!): Boolean
assignCompareListToCustomer(uid: ID!): CompareList # Customer token needs to be passed
deleteCompareList(uid: ID!): DeleteCompareListOutput
}

schema {
query: Query,
mutation: Mutation
input CreateCompareListInput {
products: [ID!]
}

input AddProductsToCompareListInput {
uid: ID!,
products: [ID!]!
}

input RemoveProductsFromCompareListInput {
uid: ID!,
products: [ID!]!
}

type DeleteCompareListOutput {
result: Boolean!
}
60 changes: 52 additions & 8 deletions design-documents/graph-ql/coverage/catalog/compare-list.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,28 @@
# Use cases

## Guest scenario
## User scenario (Guest/ Logged in)

Use createCompareList mutation to create a new compare list. The server should create a new list with the items added and return the list_id. The clients can use this list_id for futher operations.

# Create Compare List
```graphql
{
mutation {
createCompareList(input: {
products: ["123", "456"]
}) #products optional
} {
list_id
items {
sku
}
}
}
```
* For a guest user, new list will be created
* For a logged in user, exisiting list_id will be returned


* A buyer can create a new compare list for the selected
products by calling mutation `addItemsToCompareList` with
the list of product ids and ID which will identify the list.
Compare list ID is client generated identifier.
```graphql
{
mutation {
Expand All @@ -29,10 +46,11 @@ Compare list ID is client generated identifier.
}
```
* If the registered customer does not have an active list then null will be returned.
This means the client has to generate and send a new ID if the compare list functionality requested.

* If the buyer calls addItemsToCompareList with a new ID the previous list will be abandoned.
For the registered user an active compare list will be replaced with a new one.
```
assignCompareListToCustomer(uid: ID!): CompareList
```
mutation can be used to assign a guest compare list to a registered customer.

* A buyer can modify the existing list by calling mutation:
* `addItemsToCompareList` to add new items to compare list.
Expand Down Expand Up @@ -74,6 +92,10 @@ preconfigured at the backoffice.

* Compare list could be assigned to the registered customer after login or account creation.

## Removing stale comparison list
* Introduce a mutation to removeComparisonList(id: ID!): Boolean, which clients can use to remove the list once the session expires
* A cron job to remove staled entries beyond certain time.

![compare-list.graphqls](compare-list/compare-list.png)

# Non functional requirements:
Expand All @@ -83,3 +105,25 @@ preconfigured at the backoffice.

Guest compare list business logic not implemented yet. Additional development required.

## DB changes

To the existing table structure for compare list, list_id will be added
```
catalog_compare_item
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add new field catalog_compare_list_id.

------------------------------------------------------------------------------
| catalog_compare_item_id | visitor_id | customer_id | product_id | store_id | list_id
==============================================================================
```

This dependency can be solved by managing the compare list state in a new table
```
catalog_compare_list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will only have the following fields: list_id, visitor_id. Not sure we can avoid having here visitor_id, we need somehow to make sure that catalog_compare_item.visitor_id is the same for all items related to a list.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

visitor_id is generated based on Luma's session. so we cannot mock it. But it can be 0, which will imply the record is not created via Luma. And I see your point.We limit the new table to have two columns list_id, additional_data (json) and we can refer it back to the original table.

------------------------------------------------------------------------------
| list_id (varchar) (primary)| visitor_id | customer_id
==============================================================================
```

and adding list_id field to catalog_compare_item table.

* encoded list_id will be used for client communications # \Magento\Framework\Math\Random::getUniqueHash can be used for hashes
* For visitors created via GraphQl, session will be null.