@@ -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