Add cashier name retrieval and caching logic to orders processing
- Introduced `getCashierName` method in `users_o` for cashier name retrieval. - Added caching for cashier names with dedicated expiration settings. - Updated `ordersRoute` to include cashier names in order details. - Added `$cashierNameCacheExpiration` property in `db_object_t` for centralized cache control.
This commit is contained in:
@@ -1461,4 +1461,28 @@ class users_o extends db
|
||||
return $customer_names;
|
||||
}
|
||||
|
||||
public function getCashierName(int $cashier_id): string
|
||||
{
|
||||
$virtualCacheObjectID = "cashier_$cashier_id";
|
||||
$cache_key = 'cashier_name';
|
||||
// Check if the name is cached
|
||||
$cached_name = $this->getCached($cache_key, $virtualCacheObjectID);
|
||||
if ($cached_name) {
|
||||
return (string)$cached_name;
|
||||
} else {
|
||||
// Not cached, get the name from the database
|
||||
$cashier = new users_o();
|
||||
$cashier->select($cashier_id);
|
||||
$name = $cashier->display_name->value();
|
||||
// If the name is empty, set it to 'Unknown Cashier'
|
||||
if (empty($name)) {
|
||||
$name = 'Unknown Cashier';
|
||||
}
|
||||
// Cache the name
|
||||
$this->cache($cache_key, $name, $virtualCacheObjectID);
|
||||
$this->setCachedExpiration($cache_key, self::$cashierNameCacheExpiration, $virtualCacheObjectID);
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user