Skip to content

Commit

Permalink
Added support for generic contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
Franck Allimant committed Apr 9, 2024
1 parent 2174c23 commit e743d31
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
32 changes: 23 additions & 9 deletions Api/BrevoClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public function buildCreateOrUpdateData(string $email): array
$contactAttribute = $this->getCustomerAttribute($customer->getId());
}

return $this->buildCreateOrUpdateGenericData($email, $contactAttribute);
}

public function buildCreateOrUpdateGenericData(string $email, array $contactAttribute): array
{
$data['email'] = $email;
if (! empty($contactAttribute)) {
$data['attributes'] = $contactAttribute;
Expand All @@ -100,13 +105,12 @@ public function buildCreateOrUpdateData(string $email): array

public function createContact(string $email)
{
$contactAttribute = [];

if (null !== $customer = CustomerQuery::create()->findOneByEmail($email)) {
$contactAttribute = $this->getCustomerAttribute($customer->getId());
}
return $this->createGenericContact($email, $this->buildCreateOrUpdateData($email));
}

$createContact = new CreateContact($this->buildCreateOrUpdateData($email));
public function createGenericContact(string $email, array $contactAttributes)
{
$createContact = new CreateContact($contactAttributes);

$this->contactApi->createContactWithHttpInfo($createContact);

Expand All @@ -115,10 +119,20 @@ public function createContact(string $email)

public function updateContact($identifier, Customer $customer)
{
$createContact = new UpdateContact($this->buildCreateOrUpdateData($customer->getEmail()));
$this->contactApi->updateContactWithHttpInfo($identifier, $createContact);
return $this->updateGenericContact(
$identifier,
$customer->getEmail(),
$this->buildCreateOrUpdateData($customer->getEmail())
);
}

return $this->contactApi->getContactInfoWithHttpInfo($customer->getEmail());
public function updateGenericContact($identifier, string $email, array $contactAttributes)
{
$updateContact = new UpdateContact($contactAttributes);

$this->contactApi->updateContactWithHttpInfo($identifier, $updateContact);

return $this->contactApi->getContactInfoWithHttpInfo($email);
}

public function update(NewsletterEvent $event, $contact = null)
Expand Down
2 changes: 1 addition & 1 deletion Config/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<language>en_US</language>
<language>fr_FR</language>
</languages>
<version>1.1.18</version>
<version>1.1.19</version>
<authors>
<author>
<name>Chabreuil Antoine</name>
Expand Down

0 comments on commit e743d31

Please sign in to comment.