GENERAL
FRONTEND
ADDITIONAL
We work on stable, supported and up-to-date versions of packages. We recommend you to do the same.
| Package | Version |
|---|---|
| PHP | >=8.2 |
| sylius/sylius | 2.0.x |
| MySQL | >= 5.7 |
| NodeJS | 20.x |
composer require bitbag/mailchimp-plugin --no-scriptsAdd plugin dependencies to your config/bundles.php file:
# config/bundles.php
return [
...
BitBag\SyliusMailChimpPlugin\BitBagSyliusMailChimpPlugin::class => ['all' => true],
];Import routing in your config/routes.yaml file
(may have already been added in the config/routes/bitbag_sylius_mailchimp_plugin.yaml file):
# config/routes.yaml
bitbag_sylius_mailchimp_plugin:
resource: "@BitBagSyliusMailChimpPlugin/config/routing.yml"Add the parameters listed below to your config/packages/_sylius.yaml file:
# config/packages/_sylius.yaml
parameters:
mailchimp.api_key: '%env(resolve:MAIL_CHIMP_API_KEY)%'
mailchimp.list_id: '%env(resolve:MAIL_CHIMP_LIST_ID)%'
mailchimp.webhook_secret: '%env(resolve:MAIL_CHIMP_WEBHOOK_SECRET)%'Add plugin parameters to your config/services.yaml file:
# config/services.yaml
parameters:
...
mailchimp.api_key: '%env(resolve:MAIL_CHIMP_API_KEY)%'
mailchimp.list_id: '%env(resolve:MAIL_CHIMP_LIST_ID)%'
mailchimp.webhook_secret: '%env(resolve:MAIL_CHIMP_WEBHOOK_SECRET)%'Complete the API authorisation data from your MailChimp account.
To get info about list id: https://mailchimp.com/developer/marketing/api/lists/get-lists-info/
# .env.local
...
MAIL_CHIMP_API_KEY=YOUR_KEY
MAIL_CHIMP_LIST_ID=YOUR_LIST_ID
MAIL_CHIMP_WEBHOOK_SECRET=QUERY_PARAMETER_FOR_UNSUBSCRIBED_WEBHHOOKYou can read more about Mailchimp webhooks here: https://mailchimp.com/developer/marketing/guides/sync-audience-data-webhooks/
bin/console cache:clearNote: If you are running it on production, add the -e prod flag to this command.
Include the newsletter in your template:
# templates location: templates/bundles/SyliusShopBundle/The_place_where_the_form_is_to_be_placed #
{% include '@BitBagSyliusMailChimpPlugin/_subscribe.html.twig' %}You could, for example, use the newsletter template _newsletter.html.twig (@BitBagSyliusMailChimpPlugin/_subscribe.html.twig).
config/packages/_sylius.yaml
Add:
sylius_twig_hooks:
hooks:
...
'sylius_shop.homepage.index':
newsletter:
template: "@BitBagSyliusMailChimpPlugin/_newsletter.html.twig"
priority: 30
// ..Please setup your webpack.config.js file to require the plugin's webpack configuration. To do so, please put the line below somewhere on top of your webpack.config.js file:
const [bitbagMailChimp] = require('./vendor/bitbag/mailchimp-plugin/webpack.config.js');As next step, please add the imported consts into final module exports:
module.exports = [..., bitbagMailChimp];Add the webpack configuration into config/packages/webpack_encore.yaml:
webpack_encore:
output_path: '%kernel.project_dir%/public/build/default'
builds:
...
mail-chimp-shop: '%kernel.project_dir%/public/build/bitbag/mail-chimp/shop'Add encore functions to your templates:
SyliusShopBundle templates/shop/javascripts.html.twig:
...
{{ encore_entry_script_tags('bitbag-mail-chimp-shop', null, 'mail-chimp-shop') }}
<script>
document.addEventListener('DOMContentLoaded', function () {
var form = document.querySelector('#footer-newsletter-form');
if (form) {
joinNewsletter(form);
}
});
</script>yarn install
yarn encore dev # or prod, depends on your environmentFor incorrectly displayed translations, execute the command:
bin/console cache:clear