Skip to content

Commit 71f69df

Browse files
authored
Merge pull request #32 from BitBagCommerce/UC-29-send-event
[UC-29] Add event to CustomerWithKeyUpdater
2 parents 7178e72 + 4617766 commit 71f69df

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/Updater/CustomerWithKeyUpdater.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,19 @@ 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 (false === is_array($user) || false === array_key_exists('email', $user)) {
88+
throw new \RuntimeException('User was not created or updated.');
89+
}
90+
91+
$this->sendEvent($apiAwareResource, $user['email'], $eventName, $payload);
92+
93+
return $user;
8694
}
8795

8896
$userByEmailFromForm = $this->userApi->findUser(
@@ -101,14 +109,13 @@ public function updateWithUserKey(
101109
);
102110

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

107114
return $user;
108115
}
109116

110117
$user = $this->userApi->createUser($apiAwareResource, $payload);
111-
$this->changeCookieWithEvent($user, $apiAwareResource, $eventName);
118+
$this->changeCookieWithEvent($user, $apiAwareResource, $eventName, $payload);
112119

113120
return $user;
114121
}
@@ -157,6 +164,7 @@ public function changeCookieWithEvent(
157164
?array $user,
158165
UserComApiAwareInterface $apiAwareResource,
159166
string $eventName,
167+
?array $payload = null,
160168
): void {
161169
if (false === is_array($user) ||
162170
false === array_key_exists('id', $user) ||
@@ -166,6 +174,6 @@ public function changeCookieWithEvent(
166174
}
167175

168176
$this->cookieManager->setUserComCookie($user['user_key']);
169-
$this->sendEvent($apiAwareResource, $user['email'], $eventName);
177+
$this->sendEvent($apiAwareResource, $user['email'], $eventName, $payload);
170178
}
171179
}

0 commit comments

Comments
 (0)