Skip to content
This repository has been archived by the owner on Dec 19, 2019. It is now read-only.

[Cart Operations] Manage Cart Items #37

Closed
misha-kotov opened this issue May 18, 2018 · 9 comments
Closed

[Cart Operations] Manage Cart Items #37

misha-kotov opened this issue May 18, 2018 · 9 comments
Assignees
Labels

Comments

@misha-kotov
Copy link

misha-kotov commented May 18, 2018

As a Magento developer, I need to manipulate the shopping cart via GraphQL so that I can build basic ecommerce experiences for shoppers on the front-end using only GraphQL.

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.

Use cases:

  • Both guest and registered shoppers can add new items to cart
  • Both guest and registered shoppers can update item qty in cart
  • Both guest and registered shoppers can remove items from cart
  • Both guest and registered shoppers can update the configuration (for a configurable product) or quantity of a previously added configurable product in cart
    • Edit Item link > Product page > Update configuration or qty > Update Cart

Acceptance criteria:

  • Cart operations should be useable in both standard Cart and mini-cart
  • GraphQL provides the following mutations:
    • addCartItems
    • updateCartItems
    • removeCartItems
  • updateCartItems mutation allows the cart item quantity to be updated in a shopper's cart
  • All product types are supported in a modular way (e.g. configurable-related schema and resolvers must be declared in ConfigurableProductGraphQl module and the rest of the system should still work if this module is disabled)
  • Depending on token in Authorization header (if any), customer or guest service contract should be used
  • Changes are covered with web API functional tests. See \Magento\GraphQl\TestModule\GraphQlMutationTest::testMutation as an example.

Proposed schema

My Account area impacted:

  • Cart
  • Minicart
@misha-kotov misha-kotov added the for-grooming This issue needs to be discussed before it can be worked on label May 18, 2018
@misha-kotov misha-kotov changed the title Cart operations [Mutations] Cart Operations > Manage Cart Items May 22, 2018
@paliarush paliarush removed the for-grooming This issue needs to be discussed before it can be worked on label Jul 3, 2018
@masodu
Copy link

masodu commented Jul 4, 2018

@misha-kotov a general comment is that normally cart operations are based on a single product selection. AFAICS I am not sure about the use case to add/update more items at the same time.

@masodu
Copy link

masodu commented Jul 4, 2018

@misha-kotov I am not sure about current status of magento cart functionalities but in practice we could have a cart with 2 different cart items having the same sku. A simple use case to visualise this is a promotion with a text like By one and get one for free. Again I am not sure how this is (if) implemented in magento but for a promotion like that the cart could have two cart items, with same sku, where the price for one of the cart items is 0. For this kind of use cases I think it is much safer to modify a cart item based on its internal id.

@masodu
Copy link

masodu commented Jul 4, 2018

@misha-kotov how would be possible to remove just one cart item?

@misha-kotov
Copy link
Author

@masodu updated the description, though I'm not sure where I had described the use case of updating multiple items at the same time. Agreed it should likely be one at a time.
Thanks for pointing out the use case of multiple line items with the same sku. Good scenario to consider.
Not sure if I understand your last question correctly, but you can remove one item at a time from your cart like so:
image

@masodu
Copy link

masodu commented Jul 5, 2018

@misha-kotov my previous comments are based on the following spec:
type Mutation {
carttemsAdd(cartId: String!, items: [CartItemInput!]!): Cart
cartItemsUpdate(cartId: String!, items: [CartItemInput!]!): Cart
cartItemsRemove(cartId: String!): Cart
}
IIUC the cartItemsRemove has as input only the cartId so that's why I wasn't sure how an item can be removed from cart.

A simpler definition could be:
type Mutation {
cartItemAdd(cartId: String!, sku String!, quantity Float!): Cart
cartItemUpdate(cartId: String!, itemId String!, quantity Float!): Cart
cartItemRemove(cartId: String!, itemId String!): Cart
}

Btw what is the scope of the options in cart mutations?

@mhaack
Copy link
Contributor

mhaack commented Jul 6, 2018

@misha-kotov the type Cart & type CartItem we need to make sure this is not an 1:1 mapping of the REST api. A few comments on that.

type Cart should additionally contain all relevant information of an entire cart, like:

  • all relevant price & cost information like totals, tax, discounts, costs for payment or shipping
  • should have a discount attribute (array) to indicate applied discounts for cart or shipping discounts
  • should have a coupon/voucher attribute (array) which contains applied coupons

Related to type CartItem:

  • only one price is not enough, price should be a list to support multiple prices like item price, discounts, strike price, unit price of product, net/gross, etc.
  • should have a discount attribute to indicate applied discounts
  • qty: Float not int? If this is to support cart items like "0.5kg of meat"? If yes then I think the unit is missing.
  • price: Money money is not defined, I guess that already exists?
  • it should be possible to "expand" the product of related to a cart entry to get all product attributes (description, assets, ...) needed to render a cart view without additional calls

@paliarush
Copy link
Contributor

@mhaack thanks for the feedback!

We can design schema of Cart as we think makes the most sense. REST representation served as a starting point and now we can discuss and evolve the schema as needed.

type Cart:

  • It will contain all fields relevant to cart, they will be added in scope of other tasks. Right now there is a comment about that in type declaration

type CartItem:

  • We'll think what price types should be available and update proposed schema
  • Magento allows quantity to be float, it is configurable on product level as far as I remember
  • Money already exists and is used within ProductInterface
  • Regarding "expand" makes sense, we'll see how to represent it taking into account different product types

magento-engcom-team pushed a commit that referenced this issue Aug 11, 2018
MAGETWO-91762: [Magento Cloud] - MYSQL Message queue is fetching mess…
@naydav naydav added this to the Release: 2.3.1 milestone Dec 12, 2018
@naydav naydav changed the title [Mutations] Cart Operations > Manage Cart Items [Cart Operations] Manage Cart Items Dec 12, 2018
@pmclain pmclain self-assigned this Feb 13, 2019
pmclain added a commit to pmclain/graphql-ce that referenced this issue Feb 14, 2019
pmclain added a commit to pmclain/graphql-ce that referenced this issue Feb 24, 2019
@naydav
Copy link
Contributor

naydav commented Mar 1, 2019

#373

@naydav
Copy link
Contributor

naydav commented Mar 8, 2019

#377

@naydav naydav closed this as completed Apr 9, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants