From cacd32020688934a1575294aa2ad79d8ed50bca5 Mon Sep 17 00:00:00 2001 From: Ollama Date: Mon, 16 Mar 2026 18:21:14 +0000 Subject: [PATCH] Add SHOW_IN_SEARCH flag to separate attribute search from visibility Phase 2 implementation: - Add SHOW_IN_SEARCH constant (value 8) to Attribute model - Update Items controller to include searchable attributes when search_custom filter is enabled - Add language strings for the new visibility flag - Update Attributes controller to include new flag in form This allows attributes to be searchable even if they are not displayed in the items table, addressing issue #2919. Fixes #2919 --- app/Controllers/Attributes.php | 2 +- app/Controllers/Items.php | 7 +++++++ app/Language/en-GB/Attributes.php | 2 ++ app/Language/en/Attributes.php | 2 ++ app/Models/Attribute.php | 3 ++- 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/Controllers/Attributes.php b/app/Controllers/Attributes.php index c8da0467c..007612b55 100644 --- a/app/Controllers/Attributes.php +++ b/app/Controllers/Attributes.php @@ -246,7 +246,7 @@ class Attributes extends Secure_Controller $data['definition_group'][''] = lang('Common.none_selected_text'); $data['definition_info'] = $info; - $show_all = Attribute::SHOW_IN_ITEMS | Attribute::SHOW_IN_RECEIVINGS | Attribute::SHOW_IN_SALES; + $show_all = Attribute::SHOW_IN_ITEMS | Attribute::SHOW_IN_RECEIVINGS | Attribute::SHOW_IN_SALES | Attribute::SHOW_IN_SEARCH; $data['definition_flags'] = $this->get_attributes($show_all); $selected_flags = $info->definition_flags === '' ? $show_all : $info->definition_flags; $data['selected_definition_flags'] = $this->get_attributes($selected_flags); diff --git a/app/Controllers/Items.php b/app/Controllers/Items.php index cc5ac97ee..64fb316ef 100644 --- a/app/Controllers/Items.php +++ b/app/Controllers/Items.php @@ -129,6 +129,13 @@ class Items extends Secure_Controller // Check if any filter is set in the multiselect dropdown $request_filters = array_fill_keys($this->request->getGet('filters', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? [], true); $filters = array_merge($filters, $request_filters); + + // When search_custom is enabled, include attributes that are searchable but may not be visible in table + if (!empty($filters['search_custom'])) { + $searchable_definitions = $this->attribute->get_definitions_by_flags(Attribute::SHOW_IN_ITEMS | Attribute::SHOW_IN_SEARCH); + $filters['definition_ids'] = array_keys($searchable_definitions); + } + $items = $this->item->search($search, $filters, $limit, $offset, $sort, $order); $total_rows = $this->item->get_found_rows($search, $filters); $data_rows = []; diff --git a/app/Language/en-GB/Attributes.php b/app/Language/en-GB/Attributes.php index 0b4bf10cc..396723708 100644 --- a/app/Language/en-GB/Attributes.php +++ b/app/Language/en-GB/Attributes.php @@ -30,5 +30,7 @@ return [ "show_in_receivings_visibility" => "Receivings", "show_in_sales" => "Show in sales", "show_in_sales_visibility" => "Sales", + "show_in_search" => "Show in search", + "show_in_search_visibility" => "Search", "update" => "Update Attribute", ]; diff --git a/app/Language/en/Attributes.php b/app/Language/en/Attributes.php index b3ab1fde9..e0d3ed156 100644 --- a/app/Language/en/Attributes.php +++ b/app/Language/en/Attributes.php @@ -30,5 +30,7 @@ return [ "show_in_receivings_visibility" => "Receivings", "show_in_sales" => "Show in sales", "show_in_sales_visibility" => "Sales", + "show_in_search" => "Show in search", + "show_in_search_visibility" => "Search", "update" => "Update Attribute", ]; diff --git a/app/Models/Attribute.php b/app/Models/Attribute.php index d48abad2d..1d1fdf64d 100644 --- a/app/Models/Attribute.php +++ b/app/Models/Attribute.php @@ -38,9 +38,10 @@ class Attribute extends Model 'attribute_decimal' ]; - public const SHOW_IN_ITEMS = 1; // TODO: These need to be moved to constants.php + public const SHOW_IN_ITEMS = 1; public const SHOW_IN_SALES = 2; public const SHOW_IN_RECEIVINGS = 4; + public const SHOW_IN_SEARCH = 8; public function deleteDropdownAttributeValue(string $attribute_value, int $definition_id): bool { $attribute_id = $this->getAttributeIdByValue($attribute_value);