Enhance XLVask customer handling: improve JSON encoding with error handling, refine property assignment in xlvask_customer, add debugging logs, and update customer cache logic.
This commit is contained in:
@@ -15,10 +15,11 @@ class xlvask_cache implements xlvask_cache_i
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @throws Exception If there is an error encoding the customer data to JSON.
|
||||
*/
|
||||
public function setCustomerCache(int $customer_number, xlvask_customer $customer): void
|
||||
{
|
||||
$customer_data = json_encode($customer);
|
||||
$customer_data = json_encode($customer, JSON_THROW_ON_ERROR);
|
||||
redis->set(self::getCustomerCacheKey($customer_number), $customer_data);
|
||||
redis->expire(self::getCustomerCacheKey($customer_number), 3600); // Set cache expiration to 1 hour
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ class xlvask_customer
|
||||
* The discount percentage for the customer.
|
||||
* @var null|integer $discount
|
||||
*/
|
||||
public ?int $discount = 0;
|
||||
public ?int $discount;
|
||||
/**
|
||||
* The phone number of the customer. (Can be null)
|
||||
* @var string|null $phone
|
||||
|
||||
@@ -65,12 +65,14 @@ class xlvask_tasks
|
||||
}
|
||||
// Get the users from XL Vask
|
||||
$customer_objects = $this->fetchCustomers();
|
||||
//echo 'Customers fetched from XL Vask: ' . count($customer_objects) . PHP_EOL;
|
||||
// Return the customers with an external ID
|
||||
$customers = [
|
||||
'with_external_id' => [...self::filterCustomersWithExternalId($customer_objects)],
|
||||
'without_external_id' => [...self::filterCustomersWithoutExternalId($customer_objects)],
|
||||
'all' => $customer_objects,
|
||||
];
|
||||
print_r($customers);
|
||||
|
||||
return self::synchronize_customers($customers['with_external_id']);
|
||||
}
|
||||
@@ -91,7 +93,15 @@ class xlvask_tasks
|
||||
$customer_objects_raw = $xlvask->getCustomers();
|
||||
// Parse the users into customer objects
|
||||
return array_map(function ($customer) use ($xlvask) {
|
||||
return (new $xlvask->helpers->xlvask_customer())->setProperties($customer);
|
||||
/** @var xlvask_customer $tmp */
|
||||
$tmp = new $xlvask->helpers->xlvask_customer();
|
||||
foreach ( $customer as $key => $value ) {
|
||||
// Assign the properties shared by the xlvask_customer class.
|
||||
if (property_exists($tmp, $key)) {
|
||||
$tmp->{$key} = $value;
|
||||
}
|
||||
}
|
||||
return $tmp; // Return the xlvask_customer object
|
||||
}, $customer_objects_raw);
|
||||
}
|
||||
|
||||
@@ -146,6 +156,7 @@ class xlvask_tasks
|
||||
/** @var xlvask_customer $customer */
|
||||
return $customer->externId; // The customer number is stored in the externId property in XL Vask
|
||||
}, $with_external_id);
|
||||
echo 'Mapping ' . count($customer_numbers) . ' customer numbers for synchronization.' . PHP_EOL;
|
||||
|
||||
// Get all the user ids associated with the customer numbers
|
||||
$users = (new users_o())->getUsersByCustomerNumbers($customer_numbers, true);
|
||||
|
||||
Reference in New Issue
Block a user