From 8302b05028483866293e9e7fc7109b349486ba2b Mon Sep 17 00:00:00 2001 From: Jeppe Bundgaard Date: Thu, 27 Nov 2025 15:08:07 +0100 Subject: [PATCH] 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. --- services/nginx/app/objects/users_o.php | 24 +++++++++++++++++++++++ services/nginx/app/routes/ordersRoute.php | 2 ++ services/nginx/app/traits/db_object_t.php | 1 + 3 files changed, 27 insertions(+) diff --git a/services/nginx/app/objects/users_o.php b/services/nginx/app/objects/users_o.php index 65636b16..ea8c56d9 100644 --- a/services/nginx/app/objects/users_o.php +++ b/services/nginx/app/objects/users_o.php @@ -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; + } + } + } \ No newline at end of file diff --git a/services/nginx/app/routes/ordersRoute.php b/services/nginx/app/routes/ordersRoute.php index 14b2b0a8..bde6cc12 100644 --- a/services/nginx/app/routes/ordersRoute.php +++ b/services/nginx/app/routes/ordersRoute.php @@ -92,6 +92,8 @@ class ordersRoute // Add the customer name to the order $order['customer_name'] = (new users_o())->getCustomerName($order['customer_id']); $order['user_id'] = (int)$tmp_customer->id; + // Add the cashier name to the order + $order['cashier_name'] = (new users_o())->getCashierName((int)$order['cashier_id']); $order['pending_handheld'] = $order_obj->isPendingHandheld(); $order['attachments'] = $order_obj->listAttachments(); $order['po'] = $order['po'] ?? null; diff --git a/services/nginx/app/traits/db_object_t.php b/services/nginx/app/traits/db_object_t.php index 4e43e193..f39ffb7f 100644 --- a/services/nginx/app/traits/db_object_t.php +++ b/services/nginx/app/traits/db_object_t.php @@ -49,6 +49,7 @@ use objects\users_o; trait db_object_t { + public static int $cashierNameCacheExpiration = 300; // The cashier name cache expiration time, in seconds. Default is 1 day (86400 seconds). public static int $economicCustomerNameCacheExpiration = 86400; // The economic customer name cache expiration time, in seconds. Default is 1 day (86400 seconds). public static int $asArrayCacheExpiration = 600; // The id of the object in the database public static int $isBookedCacheExpiration = 300; // The booked / not booked cache expiration time, in seconds. Default is 1 minute (60 seconds).