Skip to content

Latest commit

 

History

History
101 lines (72 loc) · 2.63 KB

README.md

File metadata and controls

101 lines (72 loc) · 2.63 KB

Medusa v2 Example: Abandoned Cart

This directory holds the code for the Abandoned Cart Guide.

You can either:

Prerequisites

Installation

  1. Clone the repository and change to the product-review directory:
git clone https://github.com/medusajs/examples.git
cd examples/product-review

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. Install dependencies:

yarn # or npm install

5. Setup and seed the database:

npx medusa db:setup
yarn seed # or npm run seed

6. Set SendGrid environment variables (or the whichever Notification Provider you'll use):

SENDGRID_API_KEY=
SENDGRID_FROM=
ABANDONED_CART_TEMPLATE_ID=

7. Start the Medusa application:

yarn dev # or npm run dev

Once a day, the abandoned-cart scheduled job will run to send the notifications for the abandoned cart. You can also update the scheduled in the job at src/jobs/abandoned-cart.ts to test it out every minute.

Copy into Existing Medusa Application

If you have an existing Medusa application, copy the following directories and files into your project:

  • src/scheduled-jobs
  • src/workflows

Then, configure the SendGrid Notification Module Provider (or whichever Notification Module Provider you're using) in medusa-config.ts:

module.exports = defineConfig({
  // ...
  modules: [
    {
      resolve: "@medusajs/notification",
      options: {
        providers: [
          {
            resolve: "@medusajs/notification-sendgrid",
            options: {
              api_key: process.env.SENDGRID_API_KEY,
              from: process.env.SENDGRID_FROM,
              channels: ["email"],
            },
          },
        ],
      },
    },
  ],
})

Finally, start the Medusa application:

yarn dev # or npm run dev

Once a day, the abandoned-cart scheduled job will run to send the notifications for the abandoned cart. You can also update the scheduled in the job at src/jobs/abandoned-cart.ts to test it out every minute.

More Resources