public function handle(Subscription $subscription)
{
// Init variables
$mergeFields = array();
$interests = array();
try {
// We must overwrite existing interests
if ($this->modulesSettings->get('Mailmotor', 'overwrite_interests', true)) {
$possibleInterests = $this->subscriber->getInterests();
// Loop interests
foreach ($possibleInterests as $categoryId => $categoryInterest) {
foreach ($categoryInterest['children'] as $categoryChildId => $categoryChildTitle) {
// Add interest
$interests[$categoryChildId] = in_array($categoryChildId, $subscription->interests);
}
}
} elseif (!empty($subscription->interests)) {
// Loop checked interests
foreach ($subscription->interests as $checkedInterestId) {
// Add interest
$interests[$checkedInterestId] = true;
}
}
// Fallback for when no mail-engine is chosen in the Backend
} catch (NotImplementedException $e) {
}
// Subscribing the user, will dispatch an event
$this->subscriber->subscribe($subscription->email, $subscription->language, $mergeFields, $interests);
}