Problem/Motivation
There is no REST layer which supports Cart interaction for a decoupled Cart.
Proposed resolution
Build a new set of REST resources which will allow interaction with the Cart.
Remaining tasks
Proposed endpoints for RESTful Cart, this list is only a start.
/cart/init - POST
Will create a new order and return the uuid to the user for use with subsequent API calls.
/cart/{order uuid} - POST, GET, DELETE, PATCH
POST - Add one or more purchasable entities to the cart.
GET - Full order retrieve, no prices, no taxes. JSON object to represent purchasable enties and their quantities currently in cart.
DELETE - No parameters, clear cart, with parameters remove purchsable entitiy by uuid from cart.
PATCH - Quantity update given uuid ID. An update to 0 quantity will delete the referenced uuid from the cart.
User interface changes
None
API changes
No changes to existing APIs, only new additions
Looking for feedback on the above!
Comments
Comment #2
mglamanCore doesn't support uuid mapping in API calls. JSON API module provided this.
Comment #3
rszrama commentedfwiw, I think this proposals misunderstands the REST verbs a little bit. Consider the following basic guidelines:
For a cart resource, this means a GET to /carts should return all carts the API consumer has access to and /carts/## should return a single cart assuming the consumer has access to it. A POST to /carts should create a new cart order for the API consumer (and I'm fine with having a shortcut like that versus requiring the consumer to know how to create a cart solely through /orders), but to /carts/## would be nonsensical. The best shorthand you could achieve would be a collection resource whose URI includes the cart ID, like /carts/##/order-items. However, in that case, I tend to think we should really just be submitting a POST to the /order-items resource, and the body should include the ID of the cart order this sucker is goin' on.
I documented a lot of this in the Commerce Services project for Commerce 1.x. That project page includes a link to the indispensable e-book on API design from Apigee with the best practices that guides the above. I also posted a complete API user guide to https://www.drupal.org/node/2043077#comment-10105608, which defines how our resources worked and what they are. I'd expect us to do something equivalent inside Commerce 2.x, though we may need to modify it to conform with the Drupal community's idiosyncrasies here and there. Would need to discuss the differences on a case-by-case basis I'd imagine.
Comment #4
jgrunert commentedThank you for the feedback gents. I see where we need to go with the API. I think I was stuck on building more of a BFF layer than a straight API. I'll rework things accordingly.
Comment #5
mglamanNo patch.
Comment #6
Andreas Radloff commentedIs anyone working on this?
I'm looking into building a headless Drupal Commerce installation which would be shared between multiple D8 sites.
Comment #7
司南 commentedSo, what is the plan to do this job? commerce_services module seems deprecated, last update is 2014, and there is no any plan of Commerce 2.x
Comment #8
司南 commentedis there any guideline for developing of ios/android applications in Commerce 2.x
i found the things may help:
no more ways to do.
Comment #9
jgrunert commentedI'm going to start working on this again.
Comment #10
司南 commentedgood, need help? I'm in
Comment #11
omarlopesinoI want help too. @jgrunert, how can we help you?
Comment #12
mglamanAssigning to myself. I had a good discussion at Florida DrupalCamp about ways forward. I've written a draft proposal that I'm having reviewed before posting here.
Comment #13
jasonyarringtonPing me about this. We can put some time into it too.
Comment #14
司南 commentedI am making production project that need this features right now.
I am planing to complete this features in a week.
@mglaman where can see your draft proposal ? can't you share it to me right now ?
Comment #15
bojanz commented@"164713332@qq.com" and others
https://github.com/mglaman/commerce_cart_api
Comment #16
bojanz commentedChanging the status, since we now have a functional Cart API that needs to be either merged into Commerce or made into a contrib project.
We're currently discussing the implementation with the JSON API team, to see whether cooperation is possible on that side.
Comment #17
mglamanPlease note: if you choose to use that repository, add the following to your composer.json
Be aware it is experimental and will change without notice. Some were bitten by a refactor in a rest.module plugin change (see https://github.com/mglaman/commerce_cart_api/commit/620679f73c085253107d...)
Especially since a goal is to solidify this at DrupalCon.
Sorry for any "silence" on this. Just have not wanted to say "check this out!" then cause breaking changes.
Comment #18
司南 commentedthank you so much.
Comment #19
司南 commentedhttps://github.com/mglaman/commerce_cart_api/pull/10
@mglaman
I found some mistake of the code, I had fixed it, please check my PR.
Im sorry that I forgot to create an new branch.
Comment #20
mglamanIt lives: https://www.drupal.org/project/commerce_cart_api
https://commerceguys.com/blog/introducing-cart-api-drupal-commerce