<?php
declare(strict_types=1);
namespace App\Controller;
use App\Component\Location\UserCountryDetector;
use App\Entity\Cms\ContactInterface;
use App\Repository\Cms\ContactRepositoryInterface;
use Sylius\Component\Locale\Context\LocaleContextInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
class ContactController extends AbstractController
{
public function __construct(
private ContactRepositoryInterface $contactRepository,
private LocaleContextInterface $localeContext,
private UserCountryDetector $userCountryDetector,
) {
}
public function renderPhoneNumberAction(): Response
{
$country = $this->userCountryDetector->detect();
$phone = $this->contactRepository->findOneByCountyAndCode('phone', $country, $this->localeContext->getLocaleCode());
if ($phone === null) {
$phone = $this->contactRepository->findOneByCode('phone', $this->localeContext->getLocaleCode());
}
return $this->render('@SyliusShop/Layout/Header/Top/phoneNo.html.twig', [
'phone' => $phone,
]);
}
public function renderHomepageContacts(): Response
{
/** @var ContactInterface[] $contacts */
$contacts = $this->contactRepository->findByCodesAndLocaleByPriority(
'live_chat,phone,email', $this->localeContext->getLocaleCode()
);
return $this->render('@SyliusShop/Homepage/_contactOptions.html.twig', [
'contacts' => $contacts,
]);
}
public function renderPartialContacts(): Response
{
/** @var ContactInterface[] $contacts */
$contacts = $this->contactRepository->findByCodesAndLocaleByPriority(
'live_chat,phone,email', $this->localeContext->getLocaleCode()
);
return $this->render('@SyliusShop/Partial/contactOptions.html.twig', [
'contacts' => $contacts,
]);
}
}