Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

cart.refresh() should return the cart, rather than the cart ID

See original GitHub issue

Should 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
    commerce.cart.retrieve().then(cart => {
    }).catch(error => console.log(error));

// refreshes cart
    commerce.cart.refresh().then(resp => {
      // 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)
        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:closed
  • Created 4 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

robbieaverillcommented, Dec 4, 2019

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 v2

ScopeyNZcommented, Dec 4, 2019

Ok 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.

Read more comments on GitHub >

github_iconTop 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 -
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found