src/Controller/PageController.php line 153

  1. <?php
  2. namespace App\Controller;
  3. use App\Admin\ServicesAdmin;
  4. use App\Entity\Brand;
  5. use App\Entity\Category;
  6. use App\Entity\Collection;
  7. use App\Entity\FixedPages;
  8. use App\Entity\Gallery;
  9. use App\Entity\Library;
  10. use App\Entity\News;
  11. use App\Entity\Page;
  12. use App\Entity\Product;
  13. use App\Entity\Services;
  14. use App\Entity\Testimonials;
  15. use App\Repository\FixedPagesRepository;
  16. use App\Repository\PageRepository;
  17. use App\Services\ArcaPaymentService;
  18. use App\Services\PageService;
  19. use Doctrine\ORM\EntityManagerInterface;
  20. use Gedmo\Translatable\TranslatableListener;
  21. use Gedmo\Translatable\Entity\Translation;
  22. use Gedmo\Translatable\Entity\Repository\TranslationRepository;
  23. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  24. use Symfony\Component\HttpFoundation\JsonResponse;
  25. use Symfony\Component\HttpFoundation\Request;
  26. use Symfony\Component\HttpFoundation\Response;
  27. use Symfony\Component\Routing\Annotation\Route;
  28. class PageController extends AbstractController
  29. {
  30.     private EntityManagerInterface $entityManager;
  31.     public function __construct(EntityManagerInterface $entityManager)
  32.     {
  33.         $this->entityManager $entityManager;
  34.     }
  35.     public function headerData()
  36.     {
  37.         $collections $this->entityManager->getRepository(Collection::class)->findAll();
  38.         return $this->render('@web/parts/header_collections.html.twig', [
  39.             'collections' => $collections
  40.         ]);
  41.     }
  42.     public function headerCategory()
  43.     {
  44.         $collections $this->entityManager->getRepository(Category::class)->findAll();
  45.         return $this->render('@web/parts/header_category.html.twig', [
  46.             'collections' => $collections
  47.         ]);
  48.     }
  49.     #[Route(''name'page_index'requirements: ['_locale' => 'en|ru|hy'], defaults: ['_locale' => 'en'])]
  50.     public function index(PageRepository $pageRepository)
  51.     {
  52.         return $this->render('@web/page/index.html.twig', [
  53.         ]);
  54.     }
  55.     #[Route('/{_locale}/heritage'name'page_heritage'requirements: ['_locale' => 'en|ru|hy'], defaults: ['_locale' => 'en'])]
  56.     public function hertiage(FixedPagesRepository $pageRepository)
  57.     {
  58.         $mainTitle $pageRepository->find(1);
  59.         $secondTitle $pageRepository->find(2);
  60.         $about $pageRepository->find(5);
  61.         $collections $this->entityManager->getRepository(Collection::class)->findAll();
  62.         $categories $this->entityManager->getRepository(Category::class)->findAll();
  63.         $news $this->entityManager->getRepository(News::class)->findBy(['type' => 1],['id' => 'DESC'], 2);
  64.         return $this->render('@web/page/heritage.html.twig', [
  65.             'mainTitle' => $mainTitle,
  66.             'secondTitle' => $secondTitle,
  67.             'collections' => $collections,
  68.             'about' => $about,
  69.             'news' => $news,
  70.             'categories' => $categories
  71.         ]);
  72.     }
  73.     #[Route('/{_locale}/heritage/news'name'page_heritage_news'requirements: ['_locale' => 'en|ru|hy'], defaults: ['_locale' => 'en'])]
  74.     public function hertiageNews(FixedPagesRepository $pageRepository)
  75.     {
  76.         $page $this->entityManager->getRepository(FixedPages::class)->find(6);
  77.         $news $this->entityManager->getRepository(News::class)->findBy(['type' => 1],['id' => 'DESC']);
  78.         return $this->render('@web/page/news.html.twig', [
  79.             'page' => $page,
  80.             'news' => $news,
  81.         ]);
  82.     }
  83.     #[Route('/{_locale}/liver/news'name'page_liver_news'requirements: ['_locale' => 'en|ru|hy'], defaults: ['_locale' => 'en'])]
  84.     public function liverNews(FixedPagesRepository $pageRepository)
  85.     {
  86.         $page $this->entityManager->getRepository(FixedPages::class)->find(1);
  87.         $news $this->entityManager->getRepository(News::class)->findBy(['type' => 2],['id' => 'DESC']);
  88.         return $this->render('@web/page/news.html.twig', [
  89.             'page' => $page,
  90.             'news' => $news,
  91.         ]);
  92.     }
  93.     #[Route('/{_locale}/heritage/news/{id}'name'page_heritage_news_view'requirements: ['_locale' => 'en|ru|hy'], defaults: ['_locale' => 'en'])]
  94.     public function heritageNewsView(News $news)
  95.     {
  96.         $page $news;
  97.         return $this->render('@web/page/news_view.html.twig', [
  98.             'news' => $news,
  99.             'page' => $page,
  100.         ]);
  101.     }
  102.     #[Route('/{_locale}/liver/library'name'page_liver_library'requirements: ['_locale' => 'en|ru|hy'], defaults: ['_locale' => 'en'])]
  103.     public function page_liver_library(FixedPagesRepository $pageRepository)
  104.     {
  105.         $page $pageRepository->find(6);
  106.         $library $this->entityManager->getRepository(Library::class)->findAll();
  107.         return $this->render('@web/page/library.html.twig', [
  108.             'page' => $page,
  109.             'library' => $library
  110.         ]);
  111.     }
  112.     #[Route('/{_locale}/liver/news/{id}'name'page_liver_news_view'requirements: ['_locale' => 'en|ru|hy'], defaults: ['_locale' => 'en'])]
  113.     public function liverNewsView(News $news)
  114.     {
  115.         $page $news;
  116.         return $this->render('@web/page/news_view.html.twig', [
  117.             'news' => $news,
  118.             'page' => $page,
  119.         ]);
  120.     }
  121.     #[Route('/{_locale}/liver/caf'name'page_liver_caf'requirements: ['_locale' => 'en|ru|hy'], defaults: ['_locale' => 'en'])]
  122.     public function liverCafView()
  123.     {
  124.         $page $this->entityManager->getRepository(FixedPages::class)->find(8);
  125.         return $this->render('@web/page/caf.html.twig', [
  126.             'page' => $page,
  127.         ]);
  128.     }
  129.     #[Route('/{_locale}/liver'name'page_liver'requirements: ['_locale' => 'en|ru|hy'], defaults: ['_locale' => 'en'])]
  130.     public function liver(FixedPagesRepository $pageRepository)
  131.     {
  132.         $mainTitle $pageRepository->find(6);
  133.         $about $pageRepository->find(7);
  134.         $products $this->entityManager->getRepository(Product::class)->findBy(['productType' => 2], ['id' => 'DESC'], 3);
  135.         $news $this->entityManager->getRepository(News::class)->findBy(['type' => 2],['id' => 'DESC']);
  136.         return $this->render('@web/page/liver.html.twig', [
  137.             'mainTitle' => $mainTitle,
  138.             'products' => $products,
  139.             'about' => $about,
  140.             'news' => $news,
  141.         ]);
  142.     }
  143.     #[Route('/{_locale}/liver/products'name'page_liver_products'requirements: ['_locale' => 'en|ru|hy'], defaults: ['_locale' => 'en'])]
  144.     public function liverProducts(Request $requestPageRepository $pageRepository)
  145.     {
  146.         $page $this->entityManager->getRepository(FixedPages::class)->find(6);
  147.         $products $this->entityManager
  148.             ->getRepository(Product::class)
  149.             ->findBy(['productType' => 2], ['id' => 'DESC']);
  150.         return $this->render('@web/page/liver-products.html.twig', [
  151.             'products' => $products,
  152.             'page' => $page
  153.         ]);
  154.     }
  155.     #[Route('/{_locale}/liver/products/{id}'name'page_liver_product_view'requirements: ['_locale' => 'en|ru|hy'], defaults: ['_locale' => 'en'])]
  156.     public function liverProduct(Product $product)
  157.     {
  158.         $products $this->entityManager->getRepository(Product::class)->findBy(['productType' => 2], ['id' => 'DESC']);
  159.         $delivery $this->entityManager->getRepository(FixedPages::class)->find(4);
  160.         return $this->render('@web/page/liver-product.html.twig', [
  161.             'product' => $product,
  162.             'delivery' => $delivery,
  163.             'products' => $products
  164.         ]);
  165.     }
  166.     #[Route('/{_locale}/heritage/products'name'page_heritage_products'requirements: ['_locale' => 'en|ru|hy'], defaults: ['_locale' => 'en'])]
  167.     public function hertiageProducts(Request $requestPageRepository $pageRepository)
  168.     {
  169.         $collectionId $request->query->getInt('collection'0);
  170.         $categoryId $request->query->getInt('category'0);
  171.         $collection $this->entityManager->getRepository(Collection::class)->findAll();
  172.         $category $this->entityManager->getRepository(Category::class)->findAll();
  173.         $criteria = [];
  174.         if ($collectionId 0) {
  175.             $criteria['collection'] = $collectionId// relation id is OK here
  176.         }
  177.         if ($categoryId 0) {
  178.             $criteria['category'] = $categoryId// relation id is OK here
  179.         }
  180.         $criteria['productType'] = 1;
  181.         $page $this->entityManager->getRepository(Collection::class)->find($collectionId);
  182.         if (!$page) {
  183.             $page $this->entityManager->getRepository(FixedPages::class)->find(1);
  184.         }
  185.         $products $this->entityManager
  186.             ->getRepository(Product::class)
  187.             ->findBy($criteria, ['id' => 'DESC']); // optional order
  188.         return $this->render('@web/page/hertiage-products.html.twig', [
  189.             'products' => $products,
  190.             'collection' => $collection,
  191.             'category' => $category,
  192.             'collectionId' => $collectionId,
  193.             'categoryId' => $categoryId,
  194.             'page' => $page
  195.         ]);
  196.     }
  197.     #[Route('/{_locale}/heritage/products/{id}'name'page_heritage_product_view'requirements: ['_locale' => 'en|ru|hy'], defaults: ['_locale' => 'en'])]
  198.     public function hertiageXachProducts(Product $product)
  199.     {
  200.         $products $this->entityManager->getRepository(Product::class)->findAll();
  201.         $delivery $this->entityManager->getRepository(FixedPages::class)->find(4);
  202.         return $this->render('@web/page/hertiage-product.html.twig', [
  203.             'product' => $product,
  204.             'delivery' => $delivery,
  205.             'products' => $products
  206.         ]);
  207.     }
  208.     #[Route('/{_locale}/heritage-terms'name'heritage_terms'requirements: ['_locale' => 'en|ru|hy'], defaults: ['_locale' => 'en'])]
  209.     public function heritageTerms()
  210.     {
  211.         $terms $this->entityManager->getRepository(FixedPages::class)->find(3);
  212.         return $this->render('@web/page/hertiage-terms.html.twig', [
  213.             'terms' => $terms
  214.         ]);
  215.     }
  216.     #[Route('/pay'name'pay')]
  217.     public function pay(ArcaPaymentService $arca)
  218.     {
  219.         $orderId uniqid();
  220.         $result $arca->registerOrder(
  221.             1000// AMD
  222.             $orderId,
  223.             'https://liver.am/payment-success'
  224.         );
  225.         if (isset($result['formUrl'])) {
  226.             return $this->redirect($result['formUrl']);
  227.         }
  228.         return $this->json($result);
  229.     }
  230.     #[Route('/payment-success'name'payment_success')]
  231.     public function success(Request $requestArcaPaymentService $arca)
  232.     {
  233.         $orderId $request->get('orderId');
  234.         $status $arca->getOrderStatus($orderId);
  235.         if ($status['orderStatus'] == 2) {
  236.             return new Response('Payment successful');
  237.         }
  238.         return new Response('Payment failed');
  239.     }
  240. }