0.5.2 • Published 21 days ago

@rootxpdev/medusa-newsletter-plugin v0.5.2

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
21 days ago

Medusa newsletter plugin

Register users to mailing list when purchase is made

Installation

Run the following command

npm install --save @rootxpdev/medusa-newsletter-plugin

or

yarn add @rootxpdev/medusa-newsletter-plugin

Add the following values to your medusa-config.js file

const plugins = [
  // ...other plugin configuration
  {
    resolve: "@rootxpdev/medusa-newsletter-plugin",
    options: {
        brevoApiKey: "", // Can be left empty to disable brevo integration
    }
  },
];

Usage in store front

import { useCart, useUpdateCart } from "medusa-react"
// ...

const { cart, updateCart } = useCart()

// ...

/**
 * Set `newsletter` context variable.
 */
updateCart.mutate({
    context: {
        ...cart?.context,
        newsletter: true | false,
    }
})
    
// ...

ReactJS sample, in this case we have configured list with ID 3 on https://www.brevo.com/

// ...
const BREVO_LIST_ID = 3;
// ...
    <Checkbox onCheckedChange={(checked) => {
        let newsletters = cart?.context?.newsletters;
        if (!newsletters) {
            newsletters = [];
        }
        if (checked) {
            newsletters.push(BREVO_LIST_ID);
        } else {
            const index = newsletters.indexOf(BREVO_LIST_ID);
            if (index >= 0) {
                newsletters.splice(index, 1);
            }
        }
        updateCart.mutate({
            context: {
                ...cart?.context,
                newsletters,
            }
        })
    }} checked={cart.context?.newsletters?.includes(BREVO_LIST_ID)} />
    <Text className="txt-medium-plus text-ui-fg-base">
        I want to receive e-mail notifications about any news
    </Text>
// ... 

Testing locally

Run the following command to register this module locally

yarn link

Run this command inside your medusa backend folder to use it

yarn link "@rootxpdev/medusa-newsletter-plugin"
0.5.0

21 days ago

0.5.2

21 days ago

0.5.1

21 days ago

0.4.0

23 days ago

0.3.0

23 days ago

0.2.0

23 days ago