Installation
- Run
composer require webgriffe/sylius-active-campaign-plugin
-
Add
Webgriffe\SyliusActiveCampaignPlugin\WebgriffeSyliusActiveCampaignPlugin::class => ['all' => true]
to yourconfig/bundles.php
. - Configure your ActiveCampaign API connection parameters by creating the
config/packages/webgriffe_sylius_active_campaign_plugin.yaml
file with the following content:imports: - { resource: "@WebgriffeSyliusActiveCampaignPlugin/config/app/config.yaml" } webgriffe_sylius_active_campaign: api_client: base_url: 'https://www.activecampaign.com/' key: 'SECRET'
Pay attention that among these parameters there are some sensitive configuration that you probably don’t want to commit in your VCS. There are different solutions to this problem, like env configurations and secrets. Refer to Symfony best practices doc for more info.
- Import the routes needed for updating the list status of contact (you can omit this if you don’t need to update the list status, or you don’t use the list subscription feature). Add the following to your
config/routes.yaml
file:webgriffe_sylius_active_campaign_shop: resource: "@WebgriffeSyliusActiveCampaignPlugin/config/app_routing.yml"
Note that these routes shouldn’t be inside your “shop routes”, the locale parameter is not needed.
- Your
Customer
entity must implement theWebgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareInterface
. You can use theWebgriffe\SyliusActiveCampaignPlugin\Model\ActiveCampaignAwareTrait
and theWebgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareTrait
as implementations for the interface. The Customer entity should look like this:<?php namespace App\Entity\Customer; use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\Customer as BaseCustomer; use Webgriffe\SyliusActiveCampaignPlugin\Model\ActiveCampaignAwareTrait; use Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareInterface; use Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareTrait; /** * @ORM\Entity * @ORM\Table(name="sylius_customer") */ class Customer extends BaseCustomer implements CustomerActiveCampaignAwareInterface { use ActiveCampaignAwareTrait; use CustomerActiveCampaignAwareTrait { CustomerActiveCampaignAwareTrait::channelCustomersInitializers as private __channelCustomersInitializers; } public function __construct() { parent::__construct(); $this->__channelCustomersInitializers(); } }
If you prefer you can avoid to import the channelCustomersInitializers method and initialize yourself the channelCustomers property in the constructor. The result will be like this:
<?php namespace App\Entity\Customer; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\Customer as BaseCustomer; use Webgriffe\SyliusActiveCampaignPlugin\Model\ActiveCampaignAwareTrait; use Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareInterface; use Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareTrait; /** * @ORM\Entity * @ORM\Table(name="sylius_customer") */ class Customer extends BaseCustomer implements CustomerActiveCampaignAwareInterface { use ActiveCampaignAwareTrait; use CustomerActiveCampaignAwareTrait; public function __construct() { parent::__construct(); $this->channelCustomers = new ArrayCollection(); } }
- Your
Channel
entity must implement theWebgriffe\SyliusActiveCampaignPlugin\Model\ChannelActiveCampaignAwareInterface
. You can use theWebgriffe\SyliusActiveCampaignPlugin\Model\ActiveCampaignAwareTrait
and theWebgriffe\SyliusActiveCampaignPlugin\Model\ChannelActiveCampaignAwareTrait
as implementation for the interface. The Channel entity should look like this:<?php namespace App\Entity\Channel; use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\Channel as BaseChannel; use Webgriffe\SyliusActiveCampaignPlugin\Model\ActiveCampaignAwareTrait; use Webgriffe\SyliusActiveCampaignPlugin\Model\ChannelActiveCampaignAwareInterface; use Webgriffe\SyliusActiveCampaignPlugin\Model\ChannelActiveCampaignAwareTrait; /** * @ORM\Entity * @ORM\Table(name="sylius_channel") */ class Channel extends BaseChannel implements ChannelActiveCampaignAwareInterface { use ActiveCampaignAwareTrait; use ChannelActiveCampaignAwareTrait; }
- Your
Order
entity must implement theWebgriffe\SyliusActiveCampaignPlugin\Model\ActiveCampaignAwareInterface
. You can use theWebgriffe\SyliusActiveCampaignPlugin\Model\ActiveCampaignAwareTrait
as implementation for the interface. The Order entity should look like this:<?php namespace App\Entity\Order; use Doctrine\ORM\Mapping as ORM; use Sylius\Component\Core\Model\Order as BaseOrder; use Webgriffe\SyliusActiveCampaignPlugin\Model\ActiveCampaignAwareInterface; use Webgriffe\SyliusActiveCampaignPlugin\Model\ActiveCampaignAwareTrait; /** * @ORM\Entity * @ORM\Table(name="sylius_order") */ class Order extends BaseOrder implements ActiveCampaignAwareInterface { use ActiveCampaignAwareTrait; }
- The
SyliusActiveCampaignPlugin
needs to store theActiveCampaign Ecommerce Customer's id
on a Channel-Customer association that should implement theWebgriffe\SyliusActiveCampaignPlugin\Model\ChannelCustomerInterface
. If you don’t already have an association like this in you project you could use the plugin’s ChannelCustomer resource by adding aChannelCustomer
entity and make it extending theWebgriffe\SyliusActiveCampaignPlugin\Model\ChannelCustomer
class. You can have a look at the following example:<?php namespace App\Entity\Customer; use Doctrine\ORM\Mapping as ORM; use Webgriffe\SyliusActiveCampaignPlugin\Model\ChannelCustomer as BaseChannelCustomer; /** * @ORM\Entity * @ORM\Table(name="webgriffe_sylius_active_campaign_channel_customer") */ class ChannelCustomer extends BaseChannelCustomer { }
If you have added the ChannelCustomer entity be sure to mark it as a Sylius Resource by adding the following lines in the
webgriffe_sylius_active_campaign_plugin.yaml
file:webgriffe_sylius_active_campaign: ... resources: channel_customer: classes: model: App\Entity\Customer\ChannelCustomer
-
Your
CustomerRepository
class must implement theWebgriffe\SyliusActiveCampaignPlugin\Repository\ActiveCampaignCustomerRepositoryInterface
. You can use theWebgriffe\SyliusActiveCampaignPlugin\Doctrine\ORM\ActiveCampaignCustomerRepositoryTrait
as implementation for the interface if you use Doctrine ORM and extends the Sylius Customer Repository. Remember to add the repository in your sylius_resource configuration. -
Your
ChannelRepository
class must implement theWebgriffe\SyliusActiveCampaignPlugin\Repository\ActiveCampaignResourceRepositoryInterface
. You can use theWebgriffe\SyliusActiveCampaignPlugin\Doctrine\ORM\ActiveCampaignChannelRepositoryTrait
as implementation for the interface if you use Doctrine ORM and extends the Sylius Channel Repository. Remember to add the repository in your sylius_resource configuration. -
Your
OrderRepository
class must implement theWebgriffe\SyliusActiveCampaignPlugin\Repository\ActiveCampaignOrderRepositoryInterface
. You can use theWebgriffe\SyliusActiveCampaignPlugin\Doctrine\ORM\ActiveCampaignOrderRepositoryTrait
as implementation for the interface if you use Doctrine ORM and extends the Sylius Order Repository. Remember to add the repository in your sylius_resource configuration. - If you use
Doctrine
and you have used the traits of the plugin you should run a diff of your Doctrine’s schema and then run the migration generated:bin/console doctrine:migrations:diff bin/console doctrine:migrations:migrate