src/Controller/Store/Api/SingleStoreController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Store\Api;
  3. use App\Controller\Store\BaseStoreController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. /**
  8.  * @Route("/api", name="api_store")
  9.  */
  10. class SingleStoreController extends BaseStoreController
  11. {
  12.     /**
  13.      * @Route("/store", name="single")
  14.      * @param Request $request
  15.      * @return Response
  16.      */
  17.     public function single(Request $request): Response
  18.     {
  19.         if(!$request->query->get('token')) {
  20.             return $this->json([
  21.                 'code' => 400,
  22.                 'status' => 'error',
  23.                 'message' => 'Forbidden'
  24.             ]);
  25.         }
  26.         $site $this->siteRepository->getOneToken($request->query->get('token'));
  27.         if($site == null) {
  28.             return $this->json([
  29.                 'code' => 400,
  30.                 'status' => 'error',
  31.                 'message' => 'Forbidden'
  32.             ]);
  33.         }
  34.         if($request->query->get('id')) {
  35.             $store $this->storeRepository->getOne($request->query->get('id'));
  36.         }
  37.         if($request->query->get('slug')) {
  38.             $store $this->storeRepository->getOneSlug($request->query->get('slug'));
  39.         }
  40.         $type = ($request->query->get('type')) ?: null;
  41.         $page = ($request->query->get('page')) ?: 1;
  42.         $response['body'] = $this->storeService->getFields($store$site);
  43.         $reviews $this->reviewRepository->listBy([
  44.             'store' => $store->getId(),
  45.             'limit' => 15,
  46.             'fake' => true,
  47.             'status' => ['Published'],
  48.             'page' => ($type == 'reviews') ? $page 1,
  49.         ]);
  50.         $reviews_all $this->reviewRepository->listBy([
  51.             'store' => $store->getId(),
  52.             'limit' => 15,
  53.             'fake' => true,
  54.             'page' => ($type == 'reviews') ? $page 1,
  55.         ]);
  56.         if($reviews != null) {
  57.             foreach ($reviews as $review) {
  58.                 $response['body']['reviews'][] = $this->reviewService->getFields($review);
  59.             }
  60.         }
  61.         $response['body']['count']['reviews'] = $this->reviewRepository->getCount();
  62.         $response['body']['count']['reviews_average'] = $this->reviewRepository->getAverage();
  63.         $response['body']['count']['reviews_percent'] = ceil($this->reviewRepository->getAverage() * 100 5).'%';
  64.         $response['body']['total_pages']['reviews'] = ceil($this->reviewRepository->getCount() / 15);
  65.         $deals_all $this->dealRepository->listBy([
  66.             'child_mode' => true,
  67.             'parent' => true,
  68.             'store' => $store->getId(),
  69.             'limit' => 15,
  70.             'page' => ($type == 'deals') ? $page 1,
  71.             'status' => ['published'],
  72.             'site' => $site->getId()
  73.         ]);
  74.         $response['body']['count']['deals_all'] = $this->dealRepository->getCount();
  75.         $response['body']['total_pages']['deals_all'] = ceil($this->dealRepository->getCount() / 15);
  76.         $deals $this->dealRepository->listBy([
  77.             'child_mode' => true,
  78.             'parent' => true,
  79.             'store' => $store->getId(),
  80.             'limit' => 15,
  81.             'page' => ($type == 'deals') ? $page 1,
  82.             'coupon' => 'exclude',
  83.             'status' => ['published'],
  84.             'site' => $site->getId()
  85.         ]);
  86.         $response['body']['count']['deals'] = $this->dealRepository->getCount();
  87.         $response['body']['total_pages']['deals'] = ceil($this->dealRepository->getCount() / 15);
  88.         $coupons $this->dealRepository->listBy([
  89.             'child_mode' => true,
  90.             'parent' => true,
  91.             'store' => $store->getId(),
  92.             'limit' => 15,
  93.             'page' => ($type == 'coupons') ? $page 1,
  94.             'coupon' => 'view',
  95.             'status' => ['published'],
  96.             'site' => $site->getId()
  97.         ]);
  98.         $response['body']['count']['coupons'] = $this->dealRepository->getCount();
  99.         $response['body']['total_pages']['coupons'] = ceil($this->dealRepository->getCount() / 15);
  100.         if($deals != null) {
  101.             foreach ($deals as $item) {
  102.                 $response['body']['deals'][] = $this->dealService->getFields($item);
  103.             }
  104.         }
  105.         if($coupons != null) {
  106.             foreach ($coupons as $item) {
  107.                 $response['body']['coupons'][] = $this->dealService->getFields($item);
  108.             }
  109.         }
  110.         if($deals_all != null) {
  111.             foreach ($deals_all as $item) {
  112.                 $response['body']['deals_all'][] = $this->dealService->getFields($item);
  113.             }
  114.         }
  115.         return $this->json($response);
  116.     }
  117. }