This directory holds the code for the Custom Line Item Price Guide.
You can either:
- install and use it as a Medusa application;
- or copy its source files into an existing Medusa application.
- Node.js v20+
- Git CLI
- PostgreSQL
- GoldAPI.io Account which is used to retrieve real-time metal prices. You can create a free account.
- Clone the repository and change to the
custom-item-price
directory:
git clone https://github.com/medusajs/examples.git
cd examples/custom-item-price
2. Rename the .env.template
file to .env
.
3. If necessary, change the PostgreSQL username, password, and host in the DATABASE_URL
environment variable.
4. Set the following environment variables:
GOLD_API_TOKEN=
Where GOLD_API_TOKEN
is the access token that you can retrieve from your GoldAPI.io dashboard.
5. Install dependencies:
yarn # or npm install
6. Setup and seed the database:
npx medusa db:setup
yarn seed # or npm run seed
7. Start the Medusa application:
yarn dev # or npm run dev
If you have an existing Medusa application, copy the following directories and files into your project:
src/api/store
src/api/middlewares.ts
src/modules/metal-prices
src/workflows/steps
src/workflows/add-custom-to-cart.ts
Then, add the Metal Prices Module to medusa-config.ts
:
module.exports = defineConfig({
// ...
modules: [
{
resolve: "./src/modules/metal-prices",
options: {
accessToken: process.env.GOLD_API_TOKEN,
sandbox: process.env.GOLD_API_SANDBOX === "true"
}
}
],
})
Make sure to add the following environment variable:
GOLD_API_TOKEN=
Where GOLD_API_TOKEN
is the access token that you can retrieve from your GoldAPI.io dashboard.
- Medusa Documentatin
- OpenAPI Spec file: Can be imported into tools like Postman to view and send requests to this project's API routes.