cart.refresh() should return the cart, rather than the cart ID
See original GitHub issueShould we create a getter method within the root commerce.js
class that proxies/returns the cart
instance variable that’s within the Features.Cart
instance created within commerce.js
that’s assigned as this.cart
?
A use-case is: (two methods within a React.Component)
// retrieveCart
retrieveCart(){
commerce.cart.retrieve().then(cart => {
this.setState({
cart
})
}).catch(error => console.log(error));
}
// refreshes cart
refreshCart(){
commerce.cart.refresh().then(resp => {
this.retrieveCart()
// instead of invoking this.retrieveCart to retrieve the new/refreshed cart
// we should avoid an additional request (commerce.cart.retrieve internally invokes commerce.cart.request method, as does commerce.cart.refresh)
// instead we can ref the cart object that's an instance variable in commerce.cart (ex: commerce.cart.cart)
// (it used to only have the cartId ex. commerce.cart.cartId)
this.setState({
cart: commerce.cart.cart
})
}).catch(error => console.log(error))
}
The issue with this is that a developer won’t know the cart
instance variable exist within commerce.cart
unless they debugged, or got into the source code. I think having a getter within the root commerce
class like commerce.cartObject that returns the cart
object instance variable living within commerce.cart
as commerce.cart.cart
.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Cart | Commerce.js docs
Refresh cart. The refresh() method uses GET v1/carts to create a new cart and update the stored cart ID in Commerce.js. Example request...
Read more >How can I prevent the shopping cart item from incrementing ...
Use Post/Redirect/Get Pattern: Submit form with POST method instead of GET; Redirect back to cart page after processing post request.
Read more >Manage a cart with the Storefront API - Shopify.dev
A cart contains the merchandise that a customer intends to purchase, and the estimated cost associated with the cart.
Read more >Configuring Cart Item Refresh Levels - Salesforce Help
Configuring Cart Item Refresh Levels ... As you add items to the cart, the cart contents increase. When the cart page refreshes, the...
Read more >Carts | HTTP API | commercetools Composable Commerce
Update actions that could change the price of items in the cart are not ... However, as soon as quantity is more than...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Make
cart.refresh
return the new cart object rather than the ID? Should be an easy change to make, and we can still do this for v2Ok the issue here is that
refresh
should give you back the cart.I wasn’t implying that
cart.refresh
returning the cart gets into state management, but providing and recommending API that exposes the internal.cart
object would be.