Skip to content

Latest commit

 

History

History
95 lines (66 loc) · 2.43 KB

README.md

File metadata and controls

95 lines (66 loc) · 2.43 KB

Medusa v2 Example: Custom Line Item Price

This directory holds the code for the Custom Line Item Price Guide.

You can either:

Prerequisites

Installation

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

Copy into Existing Medusa Application

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.

More Resources