Medusa newsletter plugin
Register users to mailing list when purchase is made
Installation
Run the following command
1npm install --save @rootxpdev/medusa-newsletter-plugin
or
1yarn add @rootxpdev/medusa-newsletter-plugin
Add the following values to your Copy to clipboard
medusa-config.js
file123456789const plugins = [// ...other plugin configuration{resolve: "@rootxpdev/medusa-newsletter-plugin",options: {brevoApiKey: "", // Can be left empty to disable brevo integration}},];
Usage in store front
123456789101112131415161718import { 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 clipboard
3
on https://www.brevo.com/123456789101112131415161718192021222324252627// ...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
1yarn link
Run this command inside your medusa backend folder to use it
1yarn link "@rootxpdev/medusa-newsletter-plugin"