Add product retrieval by department categories and typecasting fixes
- Added methods in `department_categories_o`, `departments_o`, and `categories_o` to retrieve products associated with department categories. - Updated `productsRoute` and `superuserDepartmentRoute` to fetch department-specific products. - Fixed typecasting in product price assignments for improved data consistency.
This commit is contained in:
@@ -3,6 +3,9 @@
|
||||
namespace routes;
|
||||
|
||||
use classes\authentication;
|
||||
use objects\categories_o;
|
||||
use objects\department_categories_o;
|
||||
use objects\departments_o;
|
||||
use objects\logs_o;
|
||||
use objects\product_options_o;
|
||||
use objects\products_o;
|
||||
@@ -240,12 +243,14 @@ class productsRoute
|
||||
(new logs_o())->add('products', 'global', 1, $user->id, 'LIST_PRODUCTS', 'Successfully listed products');
|
||||
// Check if the department_id is set
|
||||
if (isset($data['department_id'])) {
|
||||
// Get all product ids contained in a category attached to the department
|
||||
$departmentSpecificProducts = (new departments_o())->select((int)$data['department_id'])->getAllProductInDepartmentCategories();
|
||||
// Return the list of products
|
||||
$response->success(
|
||||
(new products_o())->applyDepartmentPricing((array)(new products_o())->listObjectsWithPaginationIfSet(
|
||||
function ($product) {
|
||||
return parseProduct($product);
|
||||
}
|
||||
},
|
||||
), (int)$data['department_id'])
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user