7.0.0 • Published 1 year ago

vendure-plugin-stock-monitoring v7.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Vendure stock monitoring plugin

Vendure version

Official documentation here

This plugin helps you monitor the stocklevels in two ways:

  1. A dashboard widget that displays variants who's stocklevel is below a given threshold
  2. An email handler that sends an email when stocklevels of a variant dropped below a given threshold

Getting started

  1. Add the plugin to your vendure-config.ts to expose a productVariantsWithLowStock query in the admin API.
import { StockMonitoringPlugin } from 'vendure-plugin-stock-monitoring';
import { AdminUiPlugin } from '@vendure/admin-ui-plugin';

plugins: [
  StockMonitoringPlugin.init({
    threshold: 10,
  }),
  // Add the widget to the admin ui
  AdminUiPlugin.init({
    port: 3002,
    route: 'admin',
    app: compileUiExtensions({
      outputPath: path.join(__dirname, '__admin-ui'),
      extensions: [StockMonitoringPlugin.ui],
    }),
  }),
];

For more configuration options regarding the admin ui, check the docs.

When you start the server and login, you can find stock-levels under the add widgets button.

Low stock email handler

The email handler will send an email when the stocklevel of a variant drops below the given threshold. To activate the handler, you can add the following handlers to your vendure-config.ts:

import { createLowStockEmailHandler } from "vendure-plugin-stock-monitoring";

EmailPlugin.init({
  handlers: [
    // Dynamically get email recipients based on the event
    // and send an email when stock drops below 10
    createLowStockEmailHandler({
      threshold: 10,
      subject: "Stock of variants belo 10",
      emailRecipients: async (injector, event) => {
        // Dynamically resolve email recipients with the injector and event
        const recipients = await injector.get(MyService).getAdminsForChannel(event.ctx);
        return recipients;
      }
    }),
    // Send emails to two static addresses when stock drops below 99
    createLowStockEmailHandler({
      threshold: 99,
      subject: "Stock of variants below 99",
      emailRecipients: ["test@test.com", "admin2@vendure.io"]
    })
  ],
  ...

Create a template file for the low stock email in static/email/templates/low-stock/body.hbs with the following content:

<mjml>
  <mj-body>
    <mj-section>
      <mj-column>
        <mj-text font-size='30px'>Low stocknotification</mj-text>
        <mj-divider border-color='#343434'></mj-divider>

        <mj-text>
          These products are low on stock:
          <br />
          <br />
          {{#each lines}}
            <a href='http://localhost:3050/admin/products/'>
              {{productVariant.name}}
              -
              {{productVariant.stockOnHand}}
              pc.
            </a>
            <br />
          {{/each}}
        </mj-text>

      </mj-column>
    </mj-section>

  </mj-body>
</mjml>
5.5.0

1 year ago

5.4.0

1 year ago

5.0.1

1 year ago

6.0.0

1 year ago

7.0.0

1 year ago

5.6.7

1 year ago

4.10.0

1 year ago

4.1.0

2 years ago

4.0.1

2 years ago

4.0.0

2 years ago

3.21.0

2 years ago

4.3.0

1 year ago

3.19.0

2 years ago

3.17.2

2 years ago

3.17.1

2 years ago

3.17.0

2 years ago