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:
Jeppe Bundgaard
2025-11-27 15:08:07 +01:00
parent 542596b5a0
commit 8302b05028
3 changed files with 27 additions and 0 deletions
+24
View File
@@ -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;
}
}
}