This directory holds the code for the Abandoned Cart 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
- SendGrid account or other equivalent notification service.
- 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.
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.