Updated ProductPolicy and RecipePolicy to accept ProductDto in addition to Product. This change enhances the flexibility of the policies by allowing DTOs to be used for authorization checks. refactor(provider): simplify service provider bindings Refactored AppServiceProvider to simplify the binding of ProductDirectory and RecipeDirectory. Removed unnecessary dependencies and improved clarity. feat(route): update route bindings for front-end Changed route bindings for products and recipes to use frontProduct and frontRecipe. This improves clarity and consistency in route handling. fix(breadcrumbs): update breadcrumb checks for DTOs Updated breadcrumb generation to check for ProductDto and RecipeDto instead of their model counterparts. This ensures breadcrumbs function correctly with the new DTO structure. refactor(types): remove FilePath type and update schemas Removed the FilePath type definition and updated related schemas to use string directly. This simplifies type handling for file paths. style(entities): standardize naming conventions Updated naming conventions in Product and Recipe entities to use snake_case for consistency across the codebase. feat(frontend): update product and recipe pages for new DTO structure Modified front-end components to accommodate changes in the product and recipe data structures, ensuring compatibility with the new DTOs.
174 lines
6.1 KiB
PHP
174 lines
6.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
use App\Dto\ProductDto;
|
|
use App\Dto\RecipeDto;
|
|
use Diglactic\Breadcrumbs\Breadcrumbs;
|
|
use Diglactic\Breadcrumbs\Generator;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Support\Facades\Schema;
|
|
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
|
|
use Uwil\LaravelDynamicPages\Enums\PageStatusEnum;
|
|
use Uwil\LaravelDynamicPages\Helpers\RouteHelper;
|
|
use Uwil\LaravelDynamicPages\Models\DynamicPage;
|
|
|
|
// FIXME: This should be refactored, a work has to be done in coordination with the concerned package.
|
|
if (! Schema::hasTable((new DynamicPage())->getTable())) {
|
|
return;
|
|
}
|
|
|
|
$currentLocale = app()->getLocale();
|
|
$supportedLocales = LaravelLocalization::getSupportedLanguagesKeys();
|
|
|
|
$pageHome = DynamicPage::getModelsCached()
|
|
->where('status', PageStatusEnum::published)
|
|
->where('isRoot', true)
|
|
->first();
|
|
DynamicPage::getModelsCached()->map(function (DynamicPage $dynamicPageModel) use ($supportedLocales, $pageHome) {
|
|
collect($supportedLocales)->map(function (string $locale) use ($dynamicPageModel, $pageHome) {
|
|
Breadcrumbs::for(
|
|
sprintf('front.dynamic-pages.%s.%s', $dynamicPageModel->id_key, $locale),
|
|
function (Generator $trail) use ($locale, $dynamicPageModel, $pageHome) {
|
|
if (! is_null($dynamicPageModel->page_id)) {
|
|
$trail->parent(sprintf(
|
|
'front.dynamic-pages.%s.%s',
|
|
$dynamicPageModel->parentPage->id_key,
|
|
$locale,
|
|
));
|
|
} elseif (isset($pageHome) && $dynamicPageModel->id_key !== $pageHome->id_key) {
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $locale));
|
|
}
|
|
$trail->push(
|
|
$dynamicPageModel->title,
|
|
RouteHelper::routeNameChecker(sprintf('front.dynamic-pages.%s', $dynamicPageModel->id_key))
|
|
);
|
|
}
|
|
);
|
|
});
|
|
});
|
|
|
|
Breadcrumbs::for('front.engage', function (Generator $trail) {
|
|
$currentLocale = app()->getLocale();
|
|
$pageHome = DynamicPage::getModelsCached()
|
|
->where('status', PageStatusEnum::published)
|
|
->where('isRoot', true)
|
|
->first();
|
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
ucfirst(__('front.ovoteam_commit')),
|
|
route('front.engage')
|
|
);
|
|
});
|
|
|
|
Breadcrumbs::for('front.made-in-france', function (Generator $trail) use ($pageHome, $currentLocale) {
|
|
$currentLocale = app()->getLocale();
|
|
$pageHome = DynamicPage::getModelsCached()
|
|
->where('status', PageStatusEnum::published)
|
|
->where('isRoot', true)
|
|
->first();
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
ucfirst(__('front.ovoteam_commit')),
|
|
route('front.engage')
|
|
);
|
|
$trail->push(
|
|
trans('front.made-in-france'),
|
|
route('front.made-in-france')
|
|
);
|
|
});
|
|
|
|
Breadcrumbs::for('front.expertise', function (Generator $trail) use ($currentLocale, $pageHome) {
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
ucfirst(__('front.ovoteam_commit')),
|
|
route('front.engage')
|
|
);
|
|
$trail->push(
|
|
trans('front.expertise'),
|
|
route('front.expertise')
|
|
);
|
|
});
|
|
|
|
Breadcrumbs::for('front.gamme', function (Generator $trail) use ($pageHome, $currentLocale) {
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
ucfirst(__('front.ovoteam_commit')),
|
|
route('front.engage')
|
|
);
|
|
$trail->push(
|
|
trans('front.gamme'),
|
|
route('front.gamme')
|
|
);
|
|
});
|
|
|
|
Breadcrumbs::for('front.contact-us', function (Generator $trail) use ($currentLocale, $pageHome) {
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
trans('front.contactpage'),
|
|
route('front.contact-us')
|
|
);
|
|
});
|
|
|
|
Breadcrumbs::for('front.search', function (Generator $trail) use ($currentLocale, $pageHome) {
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
trans('front.search'),
|
|
route('front.search')
|
|
);
|
|
});
|
|
|
|
Breadcrumbs::for('front.products.index', function (Generator $trail) use ($pageHome, $currentLocale) {
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
trans('front.titles.products'),
|
|
route('front.products.index')
|
|
);
|
|
});
|
|
Breadcrumbs::for('front.products.show', function (Generator $trail) use ($pageHome, $currentLocale) {
|
|
$product = request()->route('frontProduct');
|
|
|
|
if (! $product instanceof ProductDto) {
|
|
Log::warning('Product not found for breadcrumb generation.');
|
|
|
|
return;
|
|
}
|
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
trans('front.titles.products'),
|
|
route('front.products.index')
|
|
);
|
|
$trail->push(
|
|
$product->name,
|
|
route('front.products.show', ['frontProduct' => $product->slug])
|
|
);
|
|
});
|
|
|
|
Breadcrumbs::for('front.recipes.index', function (Generator $trail) use ($pageHome, $currentLocale) {
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
trans('front.titles.recipes'),
|
|
route('front.recipes.index')
|
|
);
|
|
});
|
|
Breadcrumbs::for('front.recipes.show', function (Generator $trail) use ($pageHome, $currentLocale) {
|
|
$recipe = request()->route('frontRecipe');
|
|
|
|
if (! $recipe instanceof RecipeDto) {
|
|
Log::warning('Recipe not found for breadcrumb generation.');
|
|
|
|
return;
|
|
}
|
|
|
|
$trail->parent(sprintf('front.dynamic-pages.%s.%s', $pageHome->id_key, $currentLocale));
|
|
$trail->push(
|
|
trans('front.titles.recipes'),
|
|
route('front.recipes.index')
|
|
);
|
|
$trail->push(
|
|
$recipe->name,
|
|
route('front.recipes.show', ['frontRecipe' => $recipe->slug])
|
|
);
|
|
});
|