Retrieve Cart in Storefront

In this guide, you'll learn how to retrieve a cart's details in your storefront.

Assuming you stored the cart's ID in the localStorage as explained in the Create Cart guide, you can retrieve a cart by sending a request to the Get a Cart API route.

For example:

In this example, you retrieve a cart by sending a request to the Get a Cart API route.

The response of the Get a Cart API route has a cart field, which is a cart object.

Format Prices#

When displaying the cart's totals or line item's price, make sure to format the price as implemented in the formatPrice function shown in the above snippet:

Code
1const formatPrice = (amount: number): string => {2  return new Intl.NumberFormat("en-US", {3    style: "currency",4    currency: cart?.currency_code,5  })6  .format(amount)7}

Since this is the same function used to format the prices of product variants, you can define the function in one place and re-use it where necessary. In that case, make sure to pass the currency code as a parameter to the formatPrice function.

Was this page helpful?
Ask Anything
Ask any questions about Medusa. Get help with your development.
You can also use the Medusa MCP server in Cursor, VSCode, etc...
FAQ
What is Medusa?
How can I create a module?
How can I create a data model?
How do I create a workflow?
How can I extend a data model in the Product Module?
Recipes
How do I build a marketplace with Medusa?
How do I build digital products with Medusa?
How do I build subscription-based purchases with Medusa?
What other recipes are available in the Medusa documentation?
Chat is cleared on refresh
Line break