Skip to content

Commit

Permalink
Add pull request WapplerSystems#28 (WapplerSystems#28) to pass global…
Browse files Browse the repository at this point in the history
… attributes marked in the form configuration by 'cleverreachAttributeLocalization: global'
  • Loading branch information
GO.WEST Service committed Sep 11, 2019
1 parent 8bafc8c commit f448e21
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Classes/CleverReach/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Api
const MODE_OPTIN = 'optin';

const MODE_OPTOUT = 'optout';

const ATTRIBUTES_GLOBAL = 'global';


public function __construct()
Expand Down
4 changes: 3 additions & 1 deletion Classes/Domain/Model/Receiver.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,13 @@ class Receiver
* Receiver constructor.
* @param string $email
* @param array $attributes
* @param array $globalAttributes
*/
public function __construct($email, $attributes = null)
public function __construct($email, $attributes = [], $globalAttributes = [])
{
$this->email = $email;
$this->attributes = $attributes;
$this->globalAttributes = $globalAttributes;
$this->registered = time();
}

Expand Down
9 changes: 7 additions & 2 deletions Classes/Form/Finishers/CleverreachFinisher.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ protected function executeInternal()
$connectToAPI = false;
$hasActivatorField = false;
$attributes = [];
$globalAttributes = [];


foreach ($formValues as $identifier => $value) {
Expand All @@ -75,7 +76,11 @@ protected function executeInternal()
if ($properties['cleverreachField'] === 'email') {
$email = $value;
} else {
$attributes[$properties['cleverreachField']] = $value;
if(API::ATTRIBUTES_GLOBAL === strtolower($properties['cleverreachAttributeLocalization'] ?? '')) {
$globalAttributes[$properties['cleverreachField']] = $value;
} else {
$attributes[$properties['cleverreachField']] = $value;
}
}
}

Expand All @@ -97,7 +102,7 @@ protected function executeInternal()

if (\strtolower($this->options['mode']) === Api::MODE_OPTIN) {

$receiver = new Receiver($email, $attributes);
$receiver = new Receiver($email, $attributes, $globalAttributes);
$this->api->addReceiversToGroup($receiver, $groupId);
$this->api->sendSubscribeMail($email, $formId, $groupId);

Expand Down
1 change: 1 addition & 0 deletions Configuration/Yaml/Demo/Optin.form.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ renderables:
placeholder: Name
required: required
cleverreachField: name
cleverreachAttributeLocalization: global
validators:
-
identifier: NotEmpty
Expand Down

0 comments on commit f448e21

Please sign in to comment.