Skip to content

Commit 0fe2055

Browse files
authored
Merge pull request #22 from BitBagCommerce/UC-25
[UC-25] Add payload to user events
2 parents 82619d5 + db88844 commit 0fe2055

3 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/EventSubscriber/CustomerProfileUpdatedSubscriberInterface.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ interface CustomerProfileUpdatedSubscriberInterface
2323
public const ROUTE_TO_EVENT_MAP = [
2424
'sylius_customer_profile' => 'customer_profile_update',
2525
'sylius_admin_customer_update' => 'admin_customer_update',
26+
'sylius_shop_account_profile_update' => 'shop_customer_update',
2627
'sylius_shop_register' => 'customer_registration',
2728
'sylius_shop_checkout_address' => 'customer_order_address_provided',
2829
];

src/Updater/CustomerWithKeyUpdater.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,12 @@ private function updateForUserWithoutEmail(
133133
;
134134

135135
$id = $customerFoundByEmailId ?? $userFromUserKey['id'];
136+
$payload = $this->buildPayload($email, $customer, $address);
136137

137138
$user = $this->userApi->updateUser(
138139
$apiAwareResource,
139140
$id,
140-
$this->buildPayload($email, $customer, $address),
141+
$payload,
141142
);
142143

143144
if (is_array($customerFoundByEmail) &&
@@ -147,7 +148,7 @@ private function updateForUserWithoutEmail(
147148
$this->userApi->mergeUsers($apiAwareResource, $customerFoundByEmail['id'], [$userFromUserKey['id']]);
148149
}
149150

150-
$this->sendEvent($apiAwareResource, $email, $eventName);
151+
$this->sendEvent($apiAwareResource, $email, $eventName, $payload);
151152

152153
return $user;
153154
}

src/Updater/CustomerWithoutKeyUpdater.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function updateWithoutUserKey(
6363
if (false === is_array($user) || false === array_key_exists('id', $user)) {
6464
throw new \RuntimeException('User was not created or updated.');
6565
}
66-
$this->sendEvent($userApiAwareResource, $user['email'], $eventName);
66+
$this->sendEvent($userApiAwareResource, $user['email'], $eventName, $payload);
6767

6868
return $user;
6969
}
@@ -76,13 +76,14 @@ protected function buildPayload(
7676
return $this->customerPayloadBuilder->build($email, $customer, $address);
7777
}
7878

79-
protected function sendEvent(UserComApiAwareInterface $resource, string $userCustomId, string $event): void
79+
protected function sendEvent(UserComApiAwareInterface $resource, string $userCustomId, string $event, ?array $payload = null): void
8080
{
8181
$this->userApi->createEventForUser(
8282
$resource,
8383
$userCustomId,
8484
[
8585
'name' => $event,
86+
'data' => $payload,
8687
],
8788
);
8889
}

0 commit comments

Comments
 (0)