Category

Other

Version

0.5.2

Last updated

Apr 28, 2024, 20:28:12 PM2 months 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 Copy to clipboardmedusa-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 Copy to clipboard3 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"

Build your own plugins

Develop your own plugins with our API to speed up your processes.

Make your plugin available via npm for it to be shared in our Plugin Library with the broader Medusa community.