diff --git a/UPGRADE-0.X.md b/UPGRADE-0.X.md index 832a68c..b0c51fb 100644 --- a/UPGRADE-0.X.md +++ b/UPGRADE-0.X.md @@ -1,5 +1,75 @@ # UPGRADE FROM `v0.1.0` TO `v0.X` +## UPGRADE FROM `v0.9.0` TO `v0.10.0` + +> **BC** Method Webgriffe\SyliusActiveCampaignPlugin\Model\CustomerActiveCampaignAwareTrait#__construct() was removed + +There was a bug due to a __construct method on the trait CustomerActiveCampaignAwareTrait. The constructor of the trait was never called. So that +the channelCustomers property was never initialized, or it was initialized to a null value. Even if it was a null value this was then used in a foreach, and it will trigger a deprecation error. +This bug has been fixed in this release. If you use the trait you can proceed in two ways: + +1 - You can import the channelCustomersInitializers method and call it in the constructor of your entity. The result will be like this: +```php +__channelCustomersInitializers(); + } +} +``` + +2 - 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 +channelCustomers = new ArrayCollection(); + } +} +``` + ## UPGRADE FROM `v0.8.0` TO `v0.9.0` Some services have been removed, please check if you are using them in your application and replace them: diff --git a/docs/installation.md b/docs/installation.md index 5366e16..c1346d7 100644 --- a/docs/installation.md +++ b/docs/installation.md @@ -50,6 +50,40 @@ nav_order: 2 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 + channelCustomers = new ArrayCollection(); + } } ``` diff --git a/src/Model/CustomerActiveCampaignAwareTrait.php b/src/Model/CustomerActiveCampaignAwareTrait.php index 4b83ef3..b7b9a56 100644 --- a/src/Model/CustomerActiveCampaignAwareTrait.php +++ b/src/Model/CustomerActiveCampaignAwareTrait.php @@ -18,9 +18,8 @@ trait CustomerActiveCampaignAwareTrait */ protected $channelCustomers; - public function __construct() + private function channelCustomersInitializers(): void { - parent::__construct(); $this->channelCustomers = new ArrayCollection(); } diff --git a/tests/Application/src/Entity/Customer/Customer.php b/tests/Application/src/Entity/Customer/Customer.php index f279769..4eba167 100644 --- a/tests/Application/src/Entity/Customer/Customer.php +++ b/tests/Application/src/Entity/Customer/Customer.php @@ -16,5 +16,13 @@ class Customer extends BaseCustomer implements CustomerInterface { use ActiveCampaignAwareTrait; - use CustomerActiveCampaignAwareTrait; + use CustomerActiveCampaignAwareTrait { + CustomerActiveCampaignAwareTrait::channelCustomersInitializers as private __channelCustomersInitializers; + } + + public function __construct() + { + parent::__construct(); + $this->__channelCustomersInitializers(); + } }