src/Controller/ContactController.php line 48

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use App\Component\Location\UserCountryDetector;
  5. use App\Entity\Cms\ContactInterface;
  6. use App\Repository\Cms\ContactRepositoryInterface;
  7. use Sylius\Component\Locale\Context\LocaleContextInterface;
  8. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  9. use Symfony\Component\HttpFoundation\Response;
  10. class ContactController extends AbstractController
  11. {
  12.     public function __construct(
  13.         private ContactRepositoryInterface $contactRepository,
  14.         private LocaleContextInterface $localeContext,
  15.         private UserCountryDetector $userCountryDetector,
  16.     ) {
  17.     }
  18.     public function renderPhoneNumberAction(): Response
  19.     {
  20.         $country $this->userCountryDetector->detect();
  21.         $phone $this->contactRepository->findOneByCountyAndCode('phone'$country$this->localeContext->getLocaleCode());
  22.         if ($phone === null) {
  23.             $phone $this->contactRepository->findOneByCode('phone'$this->localeContext->getLocaleCode());
  24.         }
  25.         return $this->render('@SyliusShop/Layout/Header/Top/phoneNo.html.twig', [
  26.             'phone' => $phone,
  27.         ]);
  28.     }
  29.     public function renderHomepageContacts(): Response
  30.     {
  31.         /** @var ContactInterface[] $contacts */
  32.         $contacts $this->contactRepository->findByCodesAndLocaleByPriority(
  33.             'live_chat,phone,email'$this->localeContext->getLocaleCode()
  34.         );
  35.         return $this->render('@SyliusShop/Homepage/_contactOptions.html.twig', [
  36.             'contacts' => $contacts,
  37.         ]);
  38.     }
  39.     public function renderPartialContacts(): Response
  40.     {
  41.         /** @var ContactInterface[] $contacts */
  42.         $contacts $this->contactRepository->findByCodesAndLocaleByPriority(
  43.             'live_chat,phone,email'$this->localeContext->getLocaleCode()
  44.         );
  45.         return $this->render('@SyliusShop/Partial/contactOptions.html.twig', [
  46.             'contacts' => $contacts,
  47.         ]);
  48.     }
  49. }