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:
@@ -380,4 +380,29 @@ class departments_o extends db
|
||||
$this->getObjectProperties();
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws Exception
|
||||
* @return products_o[] An array of all products in the department's categories
|
||||
*/
|
||||
public function getAllProductInDepartmentCategories(): array
|
||||
{
|
||||
self::requireSelected();
|
||||
// Get all the categories associated
|
||||
$department_categories = (new department_categories_o())->getDepartmentCategoryObjects($this->id);
|
||||
$categories = [];
|
||||
/** @var products_o[] $products */
|
||||
$products = [];
|
||||
foreach ( $department_categories as $department_category ) {
|
||||
$categories[] = $department_category->getCategory();
|
||||
}
|
||||
foreach ( $categories as $category ) {
|
||||
$cat_products = $category->getProducts();
|
||||
foreach ($cat_products as $cat_product) {
|
||||
$products[] = $cat_product;
|
||||
}
|
||||
}
|
||||
// Remove duplicate products
|
||||
return array_unique($products, SORT_REGULAR);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user