Skip to content

Commit bc983fa

Browse files
authored
Unhiding hidden categories in the event manage view @see #1126 (#1138)
1 parent 944433c commit bc983fa

3 files changed

Lines changed: 12 additions & 4 deletions

File tree

backend/app/Services/Application/Handlers/Product/GetProductsHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public function handle(int $eventId, QueryParamsDTO $queryParamsDTO): LengthAwar
2828
$filteredProducts = $this->productFilterService->filter(
2929
productsCategories: $productPaginator->getCollection(),
3030
hideSoldOutProducts: false,
31+
hideHiddenCategories: false,
3132
);
3233

3334
$productPaginator->setCollection($filteredProducts);

backend/app/Services/Application/Handlers/ProductCategory/GetProductCategoriesHandler.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public function handle(int $eventId): Collection
5151
return $this->productFilterService->filter(
5252
productsCategories: $categories,
5353
hideSoldOutProducts: false,
54+
hideHiddenCategories: false,
5455
);
5556
}
5657
}

backend/app/Services/Domain/Product/ProductFilterService.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,14 @@ public function __construct(
4141
* @param Collection<ProductCategoryDomainObject> $productsCategories
4242
* @param PromoCodeDomainObject|null $promoCode
4343
* @param bool $hideSoldOutProducts
44+
* @param bool $hideHiddenCategories
4445
* @return Collection<ProductCategoryDomainObject>
4546
*/
4647
public function filter(
4748
Collection $productsCategories,
4849
?PromoCodeDomainObject $promoCode = null,
4950
bool $hideSoldOutProducts = true,
51+
bool $hideHiddenCategories = true,
5052
): Collection
5153
{
5254
if ($productsCategories->isEmpty()) {
@@ -57,8 +59,9 @@ public function filter(
5759
->flatMap(fn(ProductCategoryDomainObject $category) => $category->getProducts());
5860

5961
if ($products->isEmpty()) {
60-
return $productsCategories
61-
->reject(fn(ProductCategoryDomainObject $category) => $category->getIsHidden());
62+
return $hideHiddenCategories
63+
? $productsCategories->reject(fn(ProductCategoryDomainObject $category) => $category->getIsHidden())
64+
: $productsCategories;
6265
}
6366

6467
$eventId = $products->first()->getEventId();
@@ -73,8 +76,11 @@ public function filter(
7376
->reject(fn(ProductDomainObject $product) => $this->filterProduct($product, $promoCode, $hideSoldOutProducts))
7477
->each(fn(ProductDomainObject $product) => $this->processProductPrices($product, $hideSoldOutProducts));
7578

76-
return $productsCategories
77-
->reject(fn(ProductCategoryDomainObject $category) => $category->getIsHidden())
79+
$filteredCategories = $hideHiddenCategories
80+
? $productsCategories->reject(fn(ProductCategoryDomainObject $category) => $category->getIsHidden())
81+
: $productsCategories;
82+
83+
return $filteredCategories
7884
->each(fn(ProductCategoryDomainObject $category) => $category->setProducts(
7985
$filteredProducts->where(
8086
static fn(ProductDomainObject $product) => $product->getProductCategoryId() === $category->getId()

0 commit comments

Comments
 (0)