user() ? '_' . auth('club')->user()->id : ''); $recipeCacheKey = 'HomeRecipesViews' . (auth('club')->user() ? '_' . auth('club')->user()->id : ''); $staticPageModel = StaticPage::getCachedStaticPage(StaticPageType::home); $mainSlideModels = MainSlide::getPublishedOrderedWithApproaches(); $demarcheSlideModels = DemarcheSlide::getPublishedOrdered(); $rangeModels = Range::getPublishedOrderedBySlug(); $productViews = Cache::remember($productCacheKey, 86400, function () { return Product::getProductsViewsByRange(); }); $hotNewsSettings = GeneralSetting::getCachedGeneralSetting(SettingsType::hotNews); $newsModels = News::getPublishedWithNewsCategory(); $recipeModels = Cache::remember($recipeCacheKey, 86400, function () { return Recipe::get9PublishedWithProducts(); }); $videoModels = Video::get9PublishedHomeVideosOrderedWithProducts(); $discountsTotal = Discount::getCachedDiscounts()->sum('value'); $staticPageModel->load(['sections.blocks', 'sections.pictos']); return view('fo.pages.home', compact( 'staticPageModel', 'mainSlideModels', 'rangeModels', 'demarcheSlideModels', 'productViews', 'newsModels', 'recipeModels', 'hotNewsSettings', 'videoModels', 'discountsTotal', )); } /** * Call the CRM to add a single optin * * @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'); } \report($e); return \response(trans('Une erreur est survenue, merci de réessayer ultérieurement'), 404); } catch (CrmException $e) { \report($e); return \response(trans('Une erreur est survenue, merci de réessayer ultérieurement'), 404); } } /** * unsubscribeNewsletter method */ public function unsubscribeNewsletter(UnsubscribeNewsletterRequest $request): View { $error = null; $hashcode = $request->hashcode; try { SingleOptin::unsetStatusWithHashcode($hashcode); } catch (ApiErrorException $e) { Log::debug($e->getMessage()); if ($e->getApiError()->equals(ApiError::modelNotFound)) { if ($customer = Customer::find($hashcode)) { $customer->opt_in = false; // ! Les données peuvent être parsés en retour de la crm et inconsitantes (Héritage vielle crm). try { $customer->save(); } catch (ValidationException $e) { $error = null; } } else { abort(404); } } else { if (app()->bound('sentry')) { app('sentry')->captureException($e); } $error = true; } } catch (CrmException $e) { Log::debug($e->getMessage()); $error = true; if (app()->bound('sentry')) { app('sentry')->captureException($e); } } // end try if (! is_null($error)) { return view('fo.pages.newsletter-unsubscribe')->with( 'error', trans('Une erreur est survenue, merci de réessayer ultérieurement') ); } return view('fo.pages.newsletter-unsubscribe'); } /** * Display a listing of the resource. */ public function updateHotNewsSatus(): JsonResponse { Cache::put('hotNewsIsDisplayed', true, now()->addHours(24)); return response()->json(); } }