67 lines
2 KiB
PHP
67 lines
2 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Front;
|
|
|
|
use App\Contracts\Directories\ProductDirectory;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Front\Products\IndexProductRequest;
|
|
use Domain\Models\Entities\Product;
|
|
use Domain\Models\ValueObjects\Products\ProductCategory;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class ProductController extends Controller
|
|
{
|
|
public function __construct(
|
|
private readonly ProductDirectory $productDirectory,
|
|
) {
|
|
}
|
|
|
|
public function index(IndexProductRequest $request): Response
|
|
{
|
|
$categories = $request->getCategories();
|
|
|
|
$breedingMethods = $request->getBreedingMethods();
|
|
$technologies = $request->getTechnologies();
|
|
$businesses = $request->getBusinesses();
|
|
$isEgalim = $request->getIsEgalim();
|
|
$search = $request->getSearchValue() ?? '';
|
|
|
|
$categoriesProducts = [];
|
|
|
|
if (count($categories) === 0) {
|
|
$categories = ! $request->hasFilter() ? [
|
|
ProductCategory::OMELETS_AND_DELI_AND_DESSERT_LINES,
|
|
ProductCategory::HARD_BOILED_EGGS,
|
|
] : ProductCategory::cases();
|
|
}
|
|
|
|
foreach ($categories as $category) {
|
|
$result = $this->productDirectory->getCategoryProducts(
|
|
category: $category,
|
|
breedingMethods: $breedingMethods,
|
|
technologies: $technologies,
|
|
businesses: $businesses,
|
|
isEgalim: $isEgalim,
|
|
search: $search
|
|
);
|
|
|
|
if ($result !== null) {
|
|
$categoriesProducts[] = $result;
|
|
}
|
|
}
|
|
|
|
return Inertia::render('front/Pages/Products/Index', [
|
|
'categoriesProducts' => $categoriesProducts,
|
|
]);
|
|
}
|
|
|
|
public function show(Product $product): Response
|
|
{
|
|
return Inertia::render('front/Pages/Products/Show', [
|
|
'product' => $product,
|
|
]);
|
|
}
|
|
}
|