products->random(self::HERO_FALLBACK_COUNT + self::CLASSICS_COUNT)); $hero = collect($this->heroCollectionProducts()); if ($hero->isEmpty()) { $hero = $random->take(self::HERO_FALLBACK_COUNT); } $heroIds = $hero->pluck('id')->all(); $classics = $random ->reject(fn (array $product) => in_array($product['id'], $heroIds)) ->take(self::CLASSICS_COUNT); return view('home', [ 'page' => $page, 'heroProducts' => $hero->map(fn (array $product) => ProductCard::fromIndexed($product))->values(), 'classicsProducts' => $classics->map(fn (array $product) => ProductCard::fromIndexed($product))->values(), ]); } /** * Products the store owner picked for the hero, via the Lunar collection * with slug "hero". Not in the owner's drag order yet: the product index * doesn't carry per-collection position (pending a boboko-core task). */ private function heroCollectionProducts(): array { $collection = $this->collections->getBySlug(self::HERO_COLLECTION_SLUG); if ($collection === null) { return []; } return $this->products ->list(new ProductFilters(collectionId: $collection['id'])) ->products ->items(); } }