2024-01-10 14:49:46 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Controllers\Fo;
|
|
|
|
|
|
|
|
|
|
use App\Http\Controllers\Controller;
|
2024-04-10 15:18:22 +02:00
|
|
|
use App\Http\Requests\Fo\SingleOptinRequest;
|
2024-04-12 12:15:18 +02:00
|
|
|
use App\Models\DemarcheSlide;
|
2024-04-04 13:00:12 +02:00
|
|
|
use App\Models\MainSlide;
|
2024-04-10 15:18:22 +02:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\Vite;
|
2024-04-10 16:31:20 +02:00
|
|
|
use LDC\LDCCRM\Enums\ApiError;
|
|
|
|
|
use LDC\LDCCRM\Exceptions\ApiErrorException;
|
|
|
|
|
use LDC\LDCCRM\Exceptions\CrmException;
|
|
|
|
|
use LDC\LDCCRM\Models\SingleOptin;
|
2024-01-10 14:49:46 +01:00
|
|
|
|
|
|
|
|
class HomeController extends Controller
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Contracts\View\View
|
|
|
|
|
*/
|
|
|
|
|
public function index(): \Illuminate\Contracts\View\View
|
|
|
|
|
{
|
2024-04-04 13:00:12 +02:00
|
|
|
$mainSlideModels = MainSlide::query()->where('published', true)->orderBy('order', 'ASC')->get();
|
2024-04-12 12:15:18 +02:00
|
|
|
$demarcheSlideModels = DemarcheSlide::query()->where('published', true)->orderBy('order', 'ASC')->get();
|
2024-04-10 15:18:22 +02:00
|
|
|
$productViews = $this->getProductsViewsByRange();
|
2024-04-11 14:17:06 +02:00
|
|
|
// FIXME: replace 'for loop' by eloquent orm on news publicated
|
|
|
|
|
for ($i = 0; $i < 5; $i++) {
|
2024-04-18 15:21:18 +02:00
|
|
|
$newsModels[] = (object)['title' => "lorem ipsum"];
|
2024-04-11 15:20:27 +02:00
|
|
|
}
|
2024-04-11 14:17:06 +02:00
|
|
|
$newsModels = collect($newsModels);
|
|
|
|
|
// FIXME: replace 'for loop' by eloquent orm on recipes publicated
|
|
|
|
|
for ($i = 0; $i < 5; $i++) {
|
|
|
|
|
$recipeModels[] = (object)[
|
2024-04-18 15:21:18 +02:00
|
|
|
'name' => "lorem ipsum", 'cooking_time' => '1h32', 'preparation_time' => '40min',
|
2024-04-11 14:17:06 +02:00
|
|
|
'difficulty' => 'ez', 'picture' => Vite::asset('resources/assets/images/tmp/product-picture.png'),
|
2024-04-18 15:21:18 +02:00
|
|
|
'packaging' => Vite::asset('resources/assets/images/tmp/packaging.png'), 'alt' => "lorem ipsum",
|
|
|
|
|
'title' => "lorem ipsum", 'isFavorite' => ($i % 2) ? true : false, 'tags' => (object)[(object)['name' =>
|
|
|
|
|
"lorem ipsum"], (object)['name' => "lorem ipsum"]]
|
2024-04-11 14:17:06 +02:00
|
|
|
];
|
|
|
|
|
};
|
|
|
|
|
$recipeModels = collect($recipeModels);
|
|
|
|
|
return view('fo.pages.home', compact(
|
|
|
|
|
'mainSlideModels',
|
2024-04-12 12:15:18 +02:00
|
|
|
'demarcheSlideModels',
|
2024-04-11 14:17:06 +02:00
|
|
|
'productViews',
|
|
|
|
|
'newsModels',
|
|
|
|
|
'recipeModels'
|
|
|
|
|
));
|
2024-04-10 15:18:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @param string|null $slug
|
|
|
|
|
* @return array<string>
|
|
|
|
|
*/
|
|
|
|
|
public function getProductsViewsByRange(string|null $slug = null): array
|
|
|
|
|
{
|
|
|
|
|
/** FIXME: replace 'first-range' by the first Range slug publicated with order by ASC. */
|
|
|
|
|
$rangeSlug = !is_null($slug) ? $slug : "first-range";
|
|
|
|
|
/** FIXME: replace this part of 'productModels' values by products associated to the range (limit 6, random). */
|
|
|
|
|
$productModels = [];
|
|
|
|
|
for ($i = 0; $i < 5; $i++) {
|
|
|
|
|
$productModels[] = (object)[
|
2024-04-11 14:17:06 +02:00
|
|
|
"name" => "Produit $i de la gamme $rangeSlug",
|
|
|
|
|
'packaging' => Vite::asset('resources/assets/images/tmp/packaging.png'),
|
2024-04-18 15:21:18 +02:00
|
|
|
'packaging_alt' => "lorem ipsum",
|
|
|
|
|
'packaging_title' => "lorem ipsum",
|
2024-04-11 14:17:06 +02:00
|
|
|
'picture' => Vite::asset('resources/assets/images/tmp/product-picture.png'),
|
2024-04-18 15:21:18 +02:00
|
|
|
'picture_alt' => "lorem ipsum",
|
|
|
|
|
'picture_title' => "lorem ipsum",
|
2024-04-11 14:17:06 +02:00
|
|
|
'tag' => Vite::asset('resources/assets/images/tmp/product-tag.png'),
|
2024-04-18 15:21:18 +02:00
|
|
|
'tag_alt' => "lorem ipsum",
|
|
|
|
|
'tag_title' => "lorem ipsum",
|
|
|
|
|
'isFavorite' => ($i % 2) ? true : false,
|
|
|
|
|
'isNew' => ($i % 2) ? false : true,
|
2024-04-10 15:18:22 +02:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
foreach ($productModels as $productModel) {
|
2024-04-11 14:17:06 +02:00
|
|
|
$productViews[] = view('fo.partials.product-card', compact('productModel'))->render();
|
2024-04-10 15:18:22 +02:00
|
|
|
} //end foreach
|
|
|
|
|
return $productViews;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Display a listing of the resource.
|
|
|
|
|
*
|
|
|
|
|
* @param \Illuminate\Http\Request|null $request
|
|
|
|
|
* @return \Illuminate\Http\JsonResponse
|
|
|
|
|
*/
|
|
|
|
|
public function jsonGetProductsViewsByRange(Request $request): \Illuminate\Http\JsonResponse
|
|
|
|
|
{
|
|
|
|
|
return response()->json($this->getProductsViewsByRange($request->RANGESLUG));
|
2024-01-10 14:49:46 +01:00
|
|
|
}
|
2024-04-10 16:31:20 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Call the CRM to add a single optin
|
|
|
|
|
*
|
|
|
|
|
* @param \App\Http\Requests\Fo\SingleOptinRequest $request
|
|
|
|
|
* @return string|array|null|\Illuminate\Contracts\Translation\Translator
|
|
|
|
|
* @throws \LDC\LDCCRM\Exceptions\ValidationException ValidationException.
|
|
|
|
|
* @throws \Illuminate\Contracts\Container\BindingResolutionException BindingResolutionException.
|
|
|
|
|
*/
|
|
|
|
|
public function addOptIn(SingleOptinRequest $request)
|
|
|
|
|
{
|
|
|
|
|
try {
|
|
|
|
|
SingleOptin::setStatus($request->email, true);
|
|
|
|
|
return \response(trans("Votre inscription à la newsletter a été prise en compte"), 200);
|
|
|
|
|
} catch (ApiErrorException $e) {
|
|
|
|
|
// Il y a deja un customerInfo avec optin a true pour ce customer.
|
|
|
|
|
if ($e->getApiError()->equals(ApiError::singleOptinCustomerExists())) {
|
|
|
|
|
return trans('Vous êtes déjà inscrit avec cette adresse email');
|
|
|
|
|
}
|
|
|
|
|
if (app()->bound('sentry')) {
|
|
|
|
|
app('sentry')->captureException($e);
|
|
|
|
|
}
|
|
|
|
|
return \response(trans('Une erreur est survenue, merci de réessayer ultérieurement'), 404);
|
|
|
|
|
} catch (CrmException $e) {
|
|
|
|
|
if (app()->bound('sentry')) {
|
|
|
|
|
app('sentry')->captureException($e);
|
|
|
|
|
}
|
|
|
|
|
return \response(trans('Une erreur est survenue, merci de réessayer ultérieurement'), 404);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-01-10 14:49:46 +01:00
|
|
|
}
|