mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-05-30 11:14:59 -04:00
Updating customers save triggers to pass an array
- Customer CSV import will potentially have many customerIds to send to. - Rework mailchimp onCustomerSaved() to receive an array of ids instead of a single ID Signed-off-by: objec <objecttothis@gmail.com>
This commit is contained in:
@@ -232,7 +232,7 @@ class Customers extends Persons
|
||||
];
|
||||
|
||||
if ($this->customer->saveCustomer($personData, $customerData, $customerId)) {
|
||||
Events::trigger('customer_saved', $customerData['person_id']);
|
||||
Events::trigger('customer_saved', [$customerData['person_id']]);
|
||||
|
||||
// New customer
|
||||
if ($customerId == NEW_ENTRY) {
|
||||
@@ -287,7 +287,7 @@ class Customers extends Persons
|
||||
}
|
||||
|
||||
/**
|
||||
* This deletes customers from the customers table
|
||||
* This deletes customers from the customer's table
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
public function postDelete(): ResponseInterface
|
||||
@@ -354,6 +354,7 @@ class Customers extends Persons
|
||||
$rowNumber = 1;
|
||||
|
||||
$failCodes = [];
|
||||
$customerIds = [];
|
||||
|
||||
while (($data = fgetcsv($handle)) !== false) {
|
||||
$consent = $data[3] == '' ? 0 : 1;
|
||||
@@ -401,8 +402,7 @@ class Customers extends Persons
|
||||
$failCodes[] = $rowNumber;
|
||||
log_message('error', "Row $rowNumber was not imported: Either email or account number already exist or data was invalid.");
|
||||
} elseif ($this->customer->saveCustomer($personData, $customerData)) {
|
||||
Events::trigger('customer_saved', $customerData['person_id']);
|
||||
|
||||
$customerIds[] = $customerData['person_id'];
|
||||
} else {
|
||||
$failCodes[] = $rowNumber;
|
||||
}
|
||||
@@ -415,6 +415,8 @@ class Customers extends Persons
|
||||
|
||||
return $this->response->setJSON(['success' => false, 'message' => $message]);
|
||||
} else {
|
||||
Events::trigger('customer_saved', $customerIds);
|
||||
|
||||
return $this->response->setJSON(['success' => true, 'message' => lang('Customers.csv_import_success')]);
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -190,29 +190,31 @@ class MailchimpPlugin extends BasePlugin
|
||||
echo $this->renderView('customer_tab', $viewData);
|
||||
}
|
||||
|
||||
public function onCustomerSaved(int $customerId): void
|
||||
public function onCustomerSaved(array $customerIds): void
|
||||
{
|
||||
if (!$this->shouldSyncOnSave()) {
|
||||
return;
|
||||
}
|
||||
|
||||
log_message('debug', "Customer saved event received for ID: {$customerId}");
|
||||
|
||||
$customerModel = new Customer();
|
||||
$customer = $customerModel->getInfo($customerId);
|
||||
|
||||
$subscriptionStatus = !empty($customer->consent)
|
||||
? strtolower(SubscriptionStatus::SUBSCRIBED->name)
|
||||
: strtolower(SubscriptionStatus::UNSUBSCRIBED->name);
|
||||
foreach ($customerIds as $customerId) {
|
||||
log_message('debug', "Customer saved event received for ID: {$customerId}");
|
||||
|
||||
$personData = [
|
||||
'email' => $customer->email ?? '',
|
||||
'first_name' => $customer->first_name ?? '',
|
||||
'last_name' => $customer->last_name ?? '',
|
||||
];
|
||||
$customerData = ['person_id' => $customerId];
|
||||
$customer = $customerModel->getInfo($customerId);
|
||||
|
||||
$this->mailchimpLibrary->synchronizeSubscription($personData, $customerData, $subscriptionStatus);
|
||||
$subscriptionStatus = !empty($customer->consent)
|
||||
? strtolower(SubscriptionStatus::SUBSCRIBED->name)
|
||||
: strtolower(SubscriptionStatus::UNSUBSCRIBED->name);
|
||||
|
||||
$personData = [
|
||||
'email' => $customer->email ?? '',
|
||||
'first_name' => $customer->first_name ?? '',
|
||||
'last_name' => $customer->last_name ?? '',
|
||||
];
|
||||
|
||||
$this->mailchimpLibrary->synchronizeSubscription($personData, ['person_id' => $customerId], $subscriptionStatus);
|
||||
}
|
||||
}
|
||||
|
||||
public function onCustomerDeleted(int $customerId, string $email): void
|
||||
|
||||
Reference in New Issue
Block a user