@rootxpdev/medusa-newsletter-plugin
v0.5.2
Published
Register users to mailing lists
Downloads
2
Maintainers
Readme
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"