Skip to content

Commit 3290826

Browse files
authored
Merge pull request #37 from BitBagCommerce/UC-29-send-event
[UC-29] Add event to CustomerWithKeyUpdater
2 parents 614abb4 + bddfcbc commit 3290826

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

src/Updater/CustomerWithKeyUpdater.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,18 @@ public function updateWithUserKey(
7878
null !== $customer->getEmail() &&
7979
$userFoundByKey['email'] === strtolower($customer->getEmail())
8080
) {
81-
return $this->userApi->updateUser(
81+
$user = $this->userApi->updateUser(
8282
$apiAwareResource,
8383
$userFoundByKey['id'],
8484
$payload,
8585
);
86+
87+
if (!is_array($user) || !isset($user['email']) || !is_string($user['email'])) {
88+
throw new \RuntimeException('User was not created or updated (missing email).');
89+
}
90+
$this->sendEvent($apiAwareResource, $user['email'], $eventName, $payload);
91+
92+
return $user;
8693
}
8794

8895
$userByEmailFromForm = $this->userApi->findUser(
@@ -101,14 +108,13 @@ public function updateWithUserKey(
101108
);
102109

103110
$this->userApi->mergeUsers($apiAwareResource, $userByEmailFromForm['id'], [$userFoundByKey['id']]);
104-
105-
$this->changeCookieWithEvent($user, $apiAwareResource, $eventName);
111+
$this->changeCookieWithEvent($user, $apiAwareResource, $eventName, $payload);
106112

107113
return $user;
108114
}
109115

110116
$user = $this->userApi->createUser($apiAwareResource, $payload);
111-
$this->changeCookieWithEvent($user, $apiAwareResource, $eventName);
117+
$this->changeCookieWithEvent($user, $apiAwareResource, $eventName, $payload);
112118

113119
return $user;
114120
}
@@ -157,6 +163,7 @@ public function changeCookieWithEvent(
157163
?array $user,
158164
UserComApiAwareInterface $apiAwareResource,
159165
string $eventName,
166+
?array $payload = null,
160167
): void {
161168
if (false === is_array($user) ||
162169
false === array_key_exists('id', $user) ||
@@ -166,6 +173,6 @@ public function changeCookieWithEvent(
166173
}
167174

168175
$this->cookieManager->setUserComCookie($user['user_key']);
169-
$this->sendEvent($apiAwareResource, $user['email'], $eventName);
176+
$this->sendEvent($apiAwareResource, $user['email'], $eventName, $payload);
170177
}
171178
}

0 commit comments

Comments
 (0)