Merge branch 'ticket1310' into 'develop'
Ticket1310 See merge request service-web-lab/le-gaulois!31
This commit is contained in:
commit
c8bd9cfd50
14 changed files with 845 additions and 649 deletions
|
|
@ -26,12 +26,17 @@ use Illuminate\Http\UploadedFile;
|
|||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\File;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ProductsController extends Controller
|
||||
{
|
||||
use UpdateModelStatus;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @param \App\Http\Requests\SearchProduct $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(SearchProduct $request)
|
||||
{
|
||||
$ranges = Range::all(['id', 'name']);
|
||||
|
|
@ -60,9 +65,15 @@ class ProductsController extends Controller
|
|||
return view('bo.products.index', compact('p', 'searchFields', 'ranges'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
// Limitation aux champs dont on a besoin sur certaines requêtes pour ne pas surcharger ces dernières
|
||||
// Limitation aux champs dont on a besoin sur certaines
|
||||
// requêtes pour ne pas surcharger ces dernières.
|
||||
$pictograms = ProductPictograms::paginate();
|
||||
$pictosDatas = [];
|
||||
foreach ($pictograms as $picto) {
|
||||
|
|
@ -87,89 +98,103 @@ class ProductsController extends Controller
|
|||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\StoreProductRequest $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(StoreProductRequest $request)
|
||||
{
|
||||
$name = $request->name;
|
||||
$slug = Str::slug($name);
|
||||
$seo_title = $request->seo_title;
|
||||
$seo_description = $request->seo_description;
|
||||
$tags = $request->tags;
|
||||
$subtitle = $request->subtitle;
|
||||
$info1 = $request->info1;
|
||||
$info2 = $request->info2;
|
||||
$description = $request->description;
|
||||
$numberPortion = intval($request->number_portion);
|
||||
$typePortion = $request->type_portion;
|
||||
$theoreticalAverageWeight = $request->theoretical_average_weight;
|
||||
$otherFormat = $request->other_format;
|
||||
$rangeId = $request->range_id;
|
||||
$meatTypeId = $request->meat_type_id;
|
||||
$consumptionTimesId = $request->consumption_times_id;
|
||||
$labelId = (\is_string($request->label_id) and \strlen($request->label_id)) ? $request->label_id : null;
|
||||
$preparationAdvice = $request->preparation_advice;
|
||||
$ingredients = $request->ingredients;
|
||||
$tips = $request->tips;
|
||||
$recipeId = $request->recipe_id;
|
||||
$videoLink = $request->video_link;
|
||||
$status = 0;
|
||||
$pictos = json_decode($request->pictos);
|
||||
return DB::transaction(function () use ($request) {
|
||||
$name = $request->name;
|
||||
$seo_title = $request->seo_title;
|
||||
$seo_description = $request->seo_description;
|
||||
$tags = $request->tags;
|
||||
$subtitle = $request->subtitle;
|
||||
$info1 = $request->info1;
|
||||
$info2 = $request->info2;
|
||||
$description = $request->description;
|
||||
$numberPortion = intval($request->number_portion);
|
||||
$typePortion = $request->type_portion;
|
||||
$theoreticalAverageWeight = $request->theoretical_average_weight;
|
||||
$otherFormat = $request->other_format;
|
||||
$rangeId = $request->range_id;
|
||||
$meatTypeId = $request->meat_type_id;
|
||||
$consumptionTimesId = $request->consumption_times_id;
|
||||
$labelId = (\is_string($request->label_id) and
|
||||
\strlen($request->label_id)) ? $request->label_id : null;
|
||||
$preparationAdvice = $request->preparation_advice;
|
||||
$ingredients = $request->ingredients;
|
||||
$tips = $request->tips;
|
||||
$recipeId = $request->recipe_id;
|
||||
$videoLink = $request->video_link;
|
||||
$status = 0;
|
||||
$pictos = json_decode($request->pictos);
|
||||
|
||||
$p = new Products();
|
||||
$p = new Products();
|
||||
|
||||
$this->storeUploadedImage($request, $p, 'picture');
|
||||
$this->storeUploadedImage($request, $p, 'pictureVideo');
|
||||
$this->storeUploadedImage($request, $p, 'picture');
|
||||
$this->storeUploadedImage($request, $p, 'pictureVideo');
|
||||
|
||||
$p->name = $name;
|
||||
$p->slug = $slug;
|
||||
$p->seo_title = $seo_title;
|
||||
$p->seo_description = $seo_description;
|
||||
$p->tags = $tags;
|
||||
$p->subtitle = $subtitle;
|
||||
$p->info1 = $info1;
|
||||
$p->info2 = $info2;
|
||||
$p->description = $description;
|
||||
$p->number_portion = $numberPortion;
|
||||
$p->type_portion = $typePortion;
|
||||
$p->theoretical_average_weight = $theoreticalAverageWeight;
|
||||
$p->other_format = $otherFormat;
|
||||
$p->range_id = $rangeId;
|
||||
$p->sub_range_id = $request->sub_range_id ?: null;
|
||||
$p->meat_type_id = $meatTypeId;
|
||||
$p->consumption_times_id = $consumptionTimesId;
|
||||
$p->label_id = $labelId;
|
||||
$p->preparation_advice = $preparationAdvice;
|
||||
$p->ingredients = $ingredients;
|
||||
$p->tips = $tips;
|
||||
if (!empty($recipeId)) {
|
||||
$p->recipe_id = $recipeId;
|
||||
}
|
||||
$p->video_link = $videoLink;
|
||||
$p->status = $status;
|
||||
$p->order = $this->getLastOrder();
|
||||
$p->star = 0;
|
||||
$p->show_rsm = 0;
|
||||
$p->xml_inco_id = $request->xml_inco;
|
||||
$p->saveOrFail();
|
||||
$p->name = $name;
|
||||
$p->seo_title = $seo_title;
|
||||
$p->seo_description = $seo_description;
|
||||
$p->tags = $tags;
|
||||
$p->subtitle = $subtitle;
|
||||
$p->info1 = $info1;
|
||||
$p->info2 = $info2;
|
||||
$p->description = $description;
|
||||
$p->number_portion = $numberPortion;
|
||||
$p->type_portion = $typePortion;
|
||||
$p->theoretical_average_weight = $theoreticalAverageWeight;
|
||||
$p->other_format = $otherFormat;
|
||||
$p->range_id = $rangeId;
|
||||
$p->sub_range_id = $request->sub_range_id ?: null;
|
||||
$p->meat_type_id = $meatTypeId;
|
||||
$p->consumption_times_id = $consumptionTimesId;
|
||||
$p->label_id = $labelId;
|
||||
$p->preparation_advice = $preparationAdvice;
|
||||
$p->ingredients = $ingredients;
|
||||
$p->tips = $tips;
|
||||
if (!empty($recipeId)) {
|
||||
$p->recipe_id = $recipeId;
|
||||
}
|
||||
$p->video_link = $videoLink;
|
||||
$p->status = $status;
|
||||
$p->order = $this->getLastOrder();
|
||||
$p->star = 0;
|
||||
$p->show_rsm = 0;
|
||||
$p->xml_inco_id = $request->xml_inco;
|
||||
$p->saveOrFail();
|
||||
|
||||
// Gestion des pictos
|
||||
$pictosIds = [];
|
||||
foreach ($pictos as $picto) {
|
||||
$pictosIds[] = $picto->id;
|
||||
}
|
||||
$p->pictograms()->sync($pictosIds);
|
||||
// Gestion des pictos.
|
||||
$pictosIds = [];
|
||||
foreach ($pictos as $picto) {
|
||||
$pictosIds[] = $picto->id;
|
||||
}
|
||||
$p->pictograms()->sync($pictosIds);
|
||||
|
||||
// Gestion des valeurs nutritionelles
|
||||
$inv = new IncoNutritionalValues();
|
||||
$inv->fill($request->validated());
|
||||
$inv->product()->associate($p);
|
||||
$inv->save();
|
||||
// Gestion des valeurs nutritionelles.
|
||||
$inv = new IncoNutritionalValues();
|
||||
$inv->fill($request->validated());
|
||||
$inv->product()->associate($p);
|
||||
$inv->save();
|
||||
|
||||
return redirect()->route('bo.products.edit', $p);
|
||||
return redirect()->route('bo.products.edit', $p);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Products $p
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Products $p)
|
||||
{
|
||||
// Limitation aux champs dont on a besoin sur certaines requêtes pour ne pas surcharger ces dernières
|
||||
// Limitation aux champs dont on a besoin
|
||||
// sur certaines requêtes pour ne pas surcharger ces dernières.
|
||||
$pictograms = ProductPictograms::all();
|
||||
$pictosDatas = [];
|
||||
foreach ($pictograms as $picto) {
|
||||
|
|
@ -204,85 +229,96 @@ class ProductsController extends Controller
|
|||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \App\Http\Requests\UpdateProductRequest $request
|
||||
* @param \App\Models\Products $p
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(UpdateProductRequest $request, Products $p)
|
||||
{
|
||||
$name = $request->name;
|
||||
$slug = Str::slug($name);
|
||||
$seo_description = $request->seo_description;
|
||||
$seo_title = $request->seo_title;
|
||||
$picture = $request->picture;
|
||||
$tags = $request->tags;
|
||||
$subtitle = $request->subtitle;
|
||||
$info1 = $request->info1;
|
||||
$info2 = $request->info2;
|
||||
$description = $request->description;
|
||||
$numberPortion = intval($request->number_portion);
|
||||
$typePortion = $request->type_portion;
|
||||
$theoreticalAverageWeight = $request->theoretical_average_weight;
|
||||
$otherFormat = $request->other_format;
|
||||
$rangeId = $request->range_id;
|
||||
$meatTypeId = $request->meat_type_id;
|
||||
$consumptionTimesId = $request->consumption_times_id;
|
||||
$labelId = (\is_string($request->label_id) and \strlen($request->label_id)) ? $request->label_id : null;
|
||||
$preparationAdvice = $request->preparation_advice;
|
||||
$ingredients = $request->ingredients;
|
||||
$tips = $request->tips;
|
||||
$recipeId = $request->recipe_id;
|
||||
$videoLink = $request->video_link;
|
||||
$pictureVideo = $request->picture_video;
|
||||
$status = $request->status === null ? 0 : 1;
|
||||
$show_rsm = $request->show_rsm === null ? 0 : 1;
|
||||
$pictos = json_decode($request->pictos);
|
||||
return DB::transaction(function () use ($request, $p) {
|
||||
$name = $request->name;
|
||||
$seo_description = $request->seo_description;
|
||||
$seo_title = $request->seo_title;
|
||||
$tags = $request->tags;
|
||||
$subtitle = $request->subtitle;
|
||||
$info1 = $request->info1;
|
||||
$info2 = $request->info2;
|
||||
$description = $request->description;
|
||||
$numberPortion = intval($request->number_portion);
|
||||
$typePortion = $request->type_portion;
|
||||
$theoreticalAverageWeight = $request->theoretical_average_weight;
|
||||
$otherFormat = $request->other_format;
|
||||
$rangeId = $request->range_id;
|
||||
$meatTypeId = $request->meat_type_id;
|
||||
$consumptionTimesId = $request->consumption_times_id;
|
||||
$labelId = (\is_string($request->label_id) and
|
||||
\strlen($request->label_id)) ? $request->label_id : null;
|
||||
$preparationAdvice = $request->preparation_advice;
|
||||
$ingredients = $request->ingredients;
|
||||
$tips = $request->tips;
|
||||
$recipeId = $request->recipe_id;
|
||||
$videoLink = $request->video_link;
|
||||
$status = $request->status === null ? 0 : 1;
|
||||
$show_rsm = $request->show_rsm === null ? 0 : 1;
|
||||
$pictos = json_decode($request->pictos);
|
||||
|
||||
$this->storeUploadedImage($request, $p, 'picture');
|
||||
$this->storeUploadedImage($request, $p, 'pictureVideo');
|
||||
$this->storeUploadedImage($request, $p, 'picture');
|
||||
$this->storeUploadedImage($request, $p, 'pictureVideo');
|
||||
|
||||
// Gestion des valeurs nutritionelles
|
||||
/** @var \App\Models\IncoNutritionalValues */
|
||||
$inv = $p->incoNutritionalValues ?? new IncoNutritionalValues();
|
||||
$inv->fill($request->validated());
|
||||
$inv->product()->associate($p);
|
||||
$inv->save();
|
||||
// Gestion des valeurs nutritionelles.
|
||||
/** @var \App\Models\IncoNutritionalValues */
|
||||
$inv = $p->incoNutritionalValues ?? new IncoNutritionalValues();
|
||||
$inv->fill($request->validated());
|
||||
$inv->product()->associate($p);
|
||||
$inv->save();
|
||||
|
||||
// Gestion des pictos
|
||||
$pictosIds = [];
|
||||
foreach ($pictos as $picto) {
|
||||
$pictosIds[] = $picto->id;
|
||||
}
|
||||
$p->pictograms()->sync($pictosIds);
|
||||
// Gestion des pictos.
|
||||
$pictosIds = [];
|
||||
foreach ($pictos as $picto) {
|
||||
$pictosIds[] = $picto->id;
|
||||
}
|
||||
$p->pictograms()->sync($pictosIds);
|
||||
|
||||
$p->name = $name;
|
||||
$p->slug = $slug;
|
||||
$p->tags = $tags;
|
||||
$p->subtitle = $subtitle;
|
||||
$p->seo_title = $seo_title;
|
||||
$p->seo_description = $seo_description;
|
||||
$p->info1 = $info1;
|
||||
$p->info2 = $info2;
|
||||
$p->description = $description;
|
||||
$p->number_portion = $numberPortion;
|
||||
$p->type_portion = $typePortion;
|
||||
$p->theoretical_average_weight = $theoreticalAverageWeight;
|
||||
$p->other_format = $otherFormat;
|
||||
$p->range_id = $rangeId;
|
||||
$p->sub_range_id = $request->sub_range_id ?: null;
|
||||
$p->meat_type_id = $meatTypeId;
|
||||
$p->consumption_times_id = $consumptionTimesId;
|
||||
$p->label_id = $labelId;
|
||||
$p->preparation_advice = $preparationAdvice;
|
||||
$p->ingredients = $ingredients;
|
||||
$p->tips = $tips;
|
||||
if (!empty($recipeId)) {
|
||||
$p->recipe_id = $recipeId;
|
||||
}
|
||||
$p->video_link = $videoLink;
|
||||
$p->show_rsm = $show_rsm;
|
||||
$p->status = $status;
|
||||
$p->saveOrFail();
|
||||
|
||||
return redirect()->route('bo.products.edit', $p->id)->with('success', 'Enregistré !');
|
||||
$p->name = $name;
|
||||
$p->tags = $tags;
|
||||
$p->subtitle = $subtitle;
|
||||
$p->seo_title = $seo_title;
|
||||
$p->seo_description = $seo_description;
|
||||
$p->info1 = $info1;
|
||||
$p->info2 = $info2;
|
||||
$p->description = $description;
|
||||
$p->number_portion = $numberPortion;
|
||||
$p->type_portion = $typePortion;
|
||||
$p->theoretical_average_weight = $theoreticalAverageWeight;
|
||||
$p->other_format = $otherFormat;
|
||||
$p->range_id = $rangeId;
|
||||
$p->sub_range_id = $request->sub_range_id ?: null;
|
||||
$p->meat_type_id = $meatTypeId;
|
||||
$p->consumption_times_id = $consumptionTimesId;
|
||||
$p->label_id = $labelId;
|
||||
$p->preparation_advice = $preparationAdvice;
|
||||
$p->ingredients = $ingredients;
|
||||
$p->tips = $tips;
|
||||
if (!empty($recipeId)) {
|
||||
$p->recipe_id = $recipeId;
|
||||
}
|
||||
$p->video_link = $videoLink;
|
||||
$p->show_rsm = $show_rsm;
|
||||
$p->status = $status;
|
||||
$p->saveOrFail();
|
||||
return redirect()->route('bo.products.edit', $p->id)->with('success', 'Enregistré !');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\Models\Products $product
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(Products $product)
|
||||
{
|
||||
if (!$product->recipes()->count()) {
|
||||
|
|
|
|||
|
|
@ -96,14 +96,21 @@ class CustomerController extends Controller
|
|||
return response()->json();
|
||||
}
|
||||
|
||||
public function setItemInCart(Products $product, bool $status)
|
||||
/**
|
||||
* Add item in customer shopping list
|
||||
*
|
||||
* @param \App\Models\Products $publishedProduct
|
||||
* @param boolean $status
|
||||
* @return void
|
||||
*/
|
||||
public function setItemInCart(Products $publishedProduct, bool $status): void
|
||||
{
|
||||
/** @var \App\Models\Customer */
|
||||
$customer = Auth::guard('customer')->user();
|
||||
if ($status) {
|
||||
$customer->products()->attach($product);
|
||||
$customer->products()->attach($publishedProduct);
|
||||
} else {
|
||||
$customer->products()->detach($product);
|
||||
$customer->products()->detach($publishedProduct);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class ProductsController extends Controller
|
|||
return view('front.products.index', compact('productsSlides', 'ranges', 'meatTypes', 'ct', 'labels'));
|
||||
}
|
||||
|
||||
public function filter(Model $model, SubRange $subrange = null)
|
||||
public function filter(Model $model, SubRange $slugSubRange = null)
|
||||
{
|
||||
// On récupère les mêmes données qu'au dessus pour l'affichage
|
||||
$productsSlides = ProductSliderPictures::where('status', 1)->orderBy('order', 'ASC')->get();
|
||||
|
|
@ -52,11 +52,11 @@ class ProductsController extends Controller
|
|||
/** @var \App\Models\Range */
|
||||
$gamme = $model;
|
||||
$subranges = $gamme->subranges()->orderBy('order')->get();
|
||||
if ($subrange) {
|
||||
if ($slugSubRange) {
|
||||
$title = $gamme->name;
|
||||
$productsList = $gamme->products()
|
||||
->where('status', true)
|
||||
->where('sub_range_id', $subrange->id)
|
||||
->where('sub_range_id', $slugSubRange->id)
|
||||
->orderBy('order')
|
||||
->get();
|
||||
} else {
|
||||
|
|
@ -88,7 +88,9 @@ class ProductsController extends Controller
|
|||
default:
|
||||
abort(404);
|
||||
break;
|
||||
}//end switch
|
||||
} //end switch
|
||||
|
||||
$subrange = $slugSubRange;
|
||||
|
||||
return view('front.products.index', compact(
|
||||
'productsList',
|
||||
|
|
@ -106,11 +108,17 @@ class ProductsController extends Controller
|
|||
));
|
||||
}
|
||||
|
||||
public function show(Products $product)
|
||||
/**
|
||||
* Display product
|
||||
*
|
||||
* @param \App\Models\Products $frontProduct
|
||||
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
|
||||
*/
|
||||
public function show(Products $frontProduct)
|
||||
{
|
||||
$recipeVideo = $product->recipe()->first();
|
||||
$recipeVideo = $frontProduct->recipe()->first();
|
||||
|
||||
$recipes = $product->recipes()->get();
|
||||
$recipes = $frontProduct->recipes()->get();
|
||||
$ids = [];
|
||||
foreach ($recipes as $r) {
|
||||
$ids[] = $r->id;
|
||||
|
|
@ -119,6 +127,7 @@ class ProductsController extends Controller
|
|||
$generalConfig = app()->view->getShared()['GeneralConfigGlobal'] ?? null;
|
||||
$generalConfig = $generalConfig ? $generalConfig->where('type', GeneralConfigType::rsm())->first() : null;
|
||||
$recipes = Recipes::whereIn('id', $ids)->where('status', true)->get();
|
||||
$product = $frontProduct;
|
||||
|
||||
return view('front.products.product', compact('product', 'recipes', 'recipeVideo', 'generalConfig'));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ namespace App\Http\Middleware;
|
|||
use App\Enums\BreedingPageType;
|
||||
use App\Models\BreedingPage;
|
||||
use App\Models\OldSlugable;
|
||||
use App\Models\Products;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
|
@ -39,6 +40,21 @@ class RedirectOldSlugs
|
|||
]), 301);
|
||||
}
|
||||
}
|
||||
) ?? $this->handleOldSlug(
|
||||
$request,
|
||||
'publishedProduct',
|
||||
Products::class,
|
||||
[],
|
||||
function ($oldSlug) {
|
||||
if (\is_object($oldSlug)) {
|
||||
/** @var \App\Models\Products */
|
||||
$publishedProduct = Products::query()
|
||||
->where('id', $oldSlug->old_slugable_id)->firstOrFail();
|
||||
return redirect(route('product.show', [
|
||||
'publishedProduct' => $publishedProduct->slug
|
||||
]), 301);
|
||||
}
|
||||
}
|
||||
) ?? $next($request);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,40 +4,67 @@ namespace App\Models;
|
|||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\Session;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class Products extends Model
|
||||
{
|
||||
/**
|
||||
* The attributes that should be cast.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'star' => 'boolean'
|
||||
];
|
||||
|
||||
/**
|
||||
* Perform any actions required after the model boots.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected static function booted()
|
||||
{
|
||||
static::creating(function (Products $product) {
|
||||
if (!$product->incoNutritionalValues) {
|
||||
static::creating(function (self $model) {
|
||||
self::setStarLogic($model);
|
||||
$model->slug = Str::slug($model->name);
|
||||
$model->preparation_advice = clean($model->preparation_advice);
|
||||
$model->ingredients = clean($model->ingredients);
|
||||
$model->tips = clean($model->tips);
|
||||
|
||||
OldSlugable::removeSameSlugs($model, $model->slug);
|
||||
if (!$model->incoNutritionalValues) {
|
||||
$inc = new IncoNutritionalValues();
|
||||
$inc->product()->associate($inc);
|
||||
}
|
||||
$product->preparation_advice = clean($product->preparation_advice);
|
||||
$product->ingredients = clean($product->ingredients);
|
||||
$product->tips = clean($product->tips);
|
||||
self::setStarLogic($product);
|
||||
});
|
||||
static::updating(function (Products $product) {
|
||||
$product->preparation_advice = clean($product->preparation_advice);
|
||||
$product->ingredients = clean($product->ingredients);
|
||||
$product->tips = clean($product->tips);
|
||||
self::setStarLogic($product);
|
||||
static::updating(function (self $model) {
|
||||
self::setStarLogic($model);
|
||||
$model->slug = Str::slug($model->name);
|
||||
$model->preparation_advice = clean($model->preparation_advice);
|
||||
$model->ingredients = clean($model->ingredients);
|
||||
$model->tips = clean($model->tips);
|
||||
|
||||
if ($product->status !== $product->getOriginal('status')) {
|
||||
if ($model->slug != $model->getOriginal('slug')) {
|
||||
OldSlugable::removeSameSlugs($model, $model->getOriginal('slug'));
|
||||
}
|
||||
|
||||
if ($model->status !== $model->getOriginal('status')) {
|
||||
Session::flash('info', trans('Le produit :product à été :status', [
|
||||
'product' => $product->name,
|
||||
'status' => $product->status ? trans('publié') : trans('dépublié'),
|
||||
'product' => $model->name,
|
||||
'status' => $model->status ? trans('publié') : trans('dépublié'),
|
||||
]));
|
||||
}
|
||||
OldSlugable::insertSlug($model);
|
||||
});
|
||||
}
|
||||
|
||||
// * RELATIONSHIPS
|
||||
|
||||
/**
|
||||
* belongsToMany ProductPictograms
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function pictograms()
|
||||
{
|
||||
return $this->belongsToMany(
|
||||
|
|
@ -48,60 +75,124 @@ class Products extends Model
|
|||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* BelongsTo Range
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function range()
|
||||
{
|
||||
return $this->belongsTo(Range::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* BelongsTo WidSubRangeget
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function subrange()
|
||||
{
|
||||
return $this->belongsTo(SubRange::class, 'sub_range_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* BelongsTo MeatTypes
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function meatType()
|
||||
{
|
||||
return $this->belongsTo(MeatTypes::class, 'meat_type_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* BelongsTo Label
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function label()
|
||||
{
|
||||
return $this->belongsTo(Label::class, 'label_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* BelongsTo ConsumptionTimes
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function consumptionTimes()
|
||||
{
|
||||
return $this->belongsTo(ConsumptionTimes::class, 'consumption_times_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* BelongsTo Recipes
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function recipe()
|
||||
{
|
||||
return $this->belongsTo(Recipes::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* HasMany IncoNutritionalValues
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\HasOne
|
||||
*/
|
||||
public function incoNutritionalValues()
|
||||
{
|
||||
return $this->hasOne(IncoNutritionalValues::class, 'product_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* BelongsToMany Recipes
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function recipes()
|
||||
{
|
||||
return $this->belongsToMany(Recipes::class, 'recipes_products', 'product_id', 'recipe_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* BelongsToMany Customers
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function customers()
|
||||
{
|
||||
return $this->belongsToMany(Customers::class, 'cart', 'product_id', 'customer_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* BelongsToMany Reduction
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
|
||||
*/
|
||||
public function reductions()
|
||||
{
|
||||
return $this->belongsToMany(Reduction::class, 'reduction_config', 'product_id', 'reduction_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* BelongsTo XmlInco
|
||||
*
|
||||
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
*/
|
||||
public function xmlInco()
|
||||
{
|
||||
return $this->belongsTo(XmlInco::class, 'xml_inco_id');
|
||||
}
|
||||
|
||||
// * METHODS
|
||||
|
||||
/**
|
||||
* Is start attribution logic
|
||||
*
|
||||
* @param self $product
|
||||
* @return void
|
||||
*/
|
||||
protected static function setStarLogic(self $product)
|
||||
{
|
||||
// * Prevent a product beeing star if not published
|
||||
|
|
|
|||
|
|
@ -32,7 +32,9 @@ use App\Models\Reduction;
|
|||
use App\Models\SubRange;
|
||||
use App\Models\Tag;
|
||||
use BadMethodCallException;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
use Illuminate\Routing\Route as RoutingRoute;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Kwaadpepper\Enum\Exceptions\EnumNotRoutableException;
|
||||
|
||||
|
|
@ -95,8 +97,12 @@ class RouteServiceProvider extends ServiceProvider
|
|||
}
|
||||
});
|
||||
Route::model('engagement', Engagement::class);
|
||||
Route::bind('publishedProduct', function ($value) {
|
||||
// * Old slug middleware will throw 404 if needed.
|
||||
return Products::where('slug', $value)->where('status', true)->first() ?? $value;
|
||||
});
|
||||
Route::bind('product', function ($value) {
|
||||
return Products::where('id', $value)->orWhere('slug', $value)->firstOrFail();
|
||||
return Products::where('id', $value)->firstOrFail();
|
||||
});
|
||||
Route::bind('range', function ($value) {
|
||||
return Range::where('id', $value)->orWhere('slug', $value)->firstOrFail();
|
||||
|
|
@ -104,8 +110,16 @@ class RouteServiceProvider extends ServiceProvider
|
|||
Route::bind('moment', function ($value) {
|
||||
return Moments::where('id', $value)->orWhere('slug', $value)->firstOrFail();
|
||||
});
|
||||
Route::bind('slugSubRange', function ($value, RoutingRoute $route) {
|
||||
// * slugRange must be resolved since slugSubRange comes second on url.
|
||||
/** @var \App\Models\Range */
|
||||
$slugRange = $route->parameter('slugRange');
|
||||
return SubRange::whereSlug($value)->whereHas('ranges', function (Builder $q) use ($slugRange) {
|
||||
$q->where('id', $slugRange->id);
|
||||
})->firstOrFail();
|
||||
});
|
||||
Route::bind('subRange', function ($value) {
|
||||
return SubRange::where('id', $value)->orWhere('slug', $value)->firstOrFail();
|
||||
return SubRange::where('id', $value)->firstOrFail();
|
||||
});
|
||||
Route::bind('slugRange', function ($value) {
|
||||
return Range::where('slug', $value)->where('status', true)->firstOrFail();
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
"kwaadpepper/enum": "^2.1",
|
||||
"kwaadpepper/exception-handler": "^0.1.0",
|
||||
"kwaadpepper/image-resizer": "^0.1.0",
|
||||
"kwaadpepper/refresh-sitemap": "^0.0.1",
|
||||
"kwaadpepper/refresh-sitemap": "^1.0",
|
||||
"kwaadpepper/serial-int-caster": "^1.0",
|
||||
"laravel/framework": "^8.0",
|
||||
"laravel/tinker": "^2.0",
|
||||
|
|
|
|||
944
composer.lock
generated
944
composer.lock
generated
File diff suppressed because it is too large
Load diff
|
|
@ -35,7 +35,7 @@ return [
|
|||
|
||||
'routesBinder' => [
|
||||
'product.show' => [
|
||||
'product' => [Products::class, 'slug']
|
||||
'publishedProduct' => [Products::class, 'slug']
|
||||
],
|
||||
'products.range' => [
|
||||
'slugRange' => [Range::class, 'slug']
|
||||
|
|
|
|||
|
|
@ -35,8 +35,8 @@
|
|||
window._translations = @json(cache(sprintf('translations.%s', app()->getLocale())));
|
||||
window._asset = '{{ asset('') }}';
|
||||
window._routes = {
|
||||
'setFav': '{{ route('account.set-cart', ['product' => '~PRODUCT~', 'status' => '~STATUS~']) }}',
|
||||
'product.show': '{{ route('product.show', ['product' => '~PRODUCT~']) }}'
|
||||
'setFav': '{{ route('account.set-cart', ['publishedProduct' => '~PRODUCT~', 'status' => '~STATUS~']) }}',
|
||||
'product.show': '{{ route('product.show', ['publishedProduct' => '~PRODUCT~']) }}'
|
||||
};
|
||||
</script>
|
||||
@endpush
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ $vegetal = ($vegetal || isset($gamme) && $gamme && $gamme->slug === "le-vegetal"
|
|||
@svg('assets/images/produit/arrow-_-.svg')
|
||||
</a>
|
||||
@foreach($subranges as $srange)
|
||||
<a class="subrangefilter noselect @if($subrange and $srange->id === $subrange->id)active @endif" href="{{ route('products.range', ['slugRange' => $gamme->slug, 'subRange' => $srange->slug]) }}">
|
||||
<a class="subrangefilter noselect @if($subrange and $srange->id === $subrange->id)active @endif" href="{{ route('products.range', ['slugRange' => $gamme->slug, 'slugSubRange' => $srange->slug]) }}">
|
||||
@if(isset($srange->picture) and strlen($srange->picture))
|
||||
<picture>
|
||||
<source srcset="{{ asset(resizePublic($srange->picture, 'productFilterWEBP')) }}" type="image/webp">
|
||||
|
|
|
|||
|
|
@ -293,8 +293,8 @@ $vegetal = ($vegetal || isset($gamme) && $gamme && $gamme->slug === "le-vegetal"
|
|||
window._routes = {
|
||||
"product.show": "{{ route('product.show', $product->slug) }}",
|
||||
"account.cart": "{{ route('account.cart') }}",
|
||||
"account.add-cart": "{{ route('account.set-cart', ['product' => $product, 'status' => 1]) }}",
|
||||
"account.remove-cart": "{{ route('account.set-cart', ['product' => $product, 'status' => 0]) }}"
|
||||
"account.add-cart": "{{ route('account.set-cart', ['publishedProduct' => $product, 'status' => 1]) }}",
|
||||
"account.remove-cart": "{{ route('account.set-cart', ['publishedProduct' => $product, 'status' => 0]) }}"
|
||||
};
|
||||
</script>
|
||||
@endpush
|
||||
|
|
|
|||
|
|
@ -72,9 +72,9 @@ Breadcrumbs::for('products.consumption-times.show', function (Generator $trail,
|
|||
$trail->parent('products.consumption-times');
|
||||
$trail->push(ucfirst($slugConsumptionTime), route('products.consumption-times', compact('slugConsumptionTime')));
|
||||
});
|
||||
Breadcrumbs::for('product.show', function (Generator $trail, Products $product) {
|
||||
Breadcrumbs::for('product.show', function (Generator $trail, Products $publishedProduct) {
|
||||
$trail->parent('products.index');
|
||||
$trail->push($product->name, route('product.show', compact('product')));
|
||||
$trail->push($publishedProduct->name, route('product.show', compact('publishedProduct')));
|
||||
});
|
||||
|
||||
// Kitchen side
|
||||
|
|
@ -303,4 +303,4 @@ Breadcrumbs::for('danslespres.description', function (Generator $trail) {
|
|||
Breadcrumbs::for('danslespres.media', function (Generator $trail) {
|
||||
$trail->parent('danslespres.index');
|
||||
$trail->push(__('La Démarche en photo et video'), route('danslespres.media'));
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -63,7 +63,9 @@ Route::prefix('/produits')
|
|||
->name('products.')
|
||||
->group(function () {
|
||||
Route::get('/', [ProductsController::class, 'index'])->name('index');
|
||||
Route::get('/gamme/{slugRange}/{subRange?}', [ProductsController::class, 'filter'])->name('range');
|
||||
Route::get('/gamme/{slugRange:slug}/{slugSubRange:slug?}', [
|
||||
ProductsController::class, 'filter'
|
||||
])->name('range');
|
||||
Route::get('/moment-consommations/{slugConsumptionTime}', [ProductsController::class, 'filter'])
|
||||
->name('consumption-times');
|
||||
Route::get('/type-viande/{slugMeatType}', [ProductsController::class, 'filter'])->name('meat-type');
|
||||
|
|
@ -71,10 +73,11 @@ Route::prefix('/produits')
|
|||
});
|
||||
|
||||
Route::prefix('/produit')
|
||||
->name('product.')
|
||||
->group(function () {
|
||||
Route::get('/{product}', [ProductsController::class, 'show'])->name('show');
|
||||
});
|
||||
->name('product.')
|
||||
->group(function () {
|
||||
Route::get('/{publishedProduct:slug}', [ProductsController::class, 'show'])
|
||||
->middleware('redirect-slugs')->name('show');
|
||||
});
|
||||
|
||||
Route::prefix('/cote-cuisine')->name('kitchen-side.')->group(function () {
|
||||
Route::get('/', [RecipesController::class, 'kitchenside'])->name('index');
|
||||
|
|
@ -314,7 +317,9 @@ Route::prefix('/mon-compte')
|
|||
Route::get('/messages/report', [ContactController::class, 'reportCustomer'])->name('reportCustomer');
|
||||
Route::get('/notifications', [ClubController::class, 'notifications'])->name('notifications');
|
||||
Route::get('/recettes-favorites', [ClubController::class, 'favoritesRecipes'])->name('favs-recipes');
|
||||
Route::post('/liste-de-courses/{product}/{status}', [CustomerController::class, 'setItemInCart'])->name('set-cart');
|
||||
Route::post('/liste-de-courses/{publishedProduct:slug}/{status}', [
|
||||
CustomerController::class, 'setItemInCart'
|
||||
])->name('set-cart');
|
||||
Route::post('/mes-informations', [ClubController::class, 'updateInfos'])->name('update-infos');
|
||||
Route::post('/mes-informations/change-password', [AuthController::class, 'changePasswordWhenAuthenticated'])
|
||||
->name('change-password');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue