src/Controller/Catalog/GetBestSellersController.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Catalog;
  3. use App\Controller\BaseController;
  4. use App\Entity\Setting;
  5. use App\Entity\Store;
  6. use Doctrine\ORM\EntityManager;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. /**
  10.  * @Route("/catalog/bestsellers", name="best_sellers_products")
  11.  */
  12. class GetBestSellersController extends BaseController
  13. {
  14.     public function __invoke(Request $request)
  15.     {
  16.         $container 'CheckoutPreview';
  17.         $this->setState('campaignProduct'$this->getCampaignProduct());
  18.         return $this->response('catalog/product/best_sellers_product.html.twig', [
  19.             'props' => [
  20.             ],
  21.             'page' => $container,
  22.         ], [
  23.             'X-Robots-Tag' => 'noindex'
  24.         ]);
  25.     }
  26.     private function getCampaignProduct(): array
  27.     {
  28.         $em $this->getDoctrine()->getManager();
  29.         $showNotInStocks $em->getRepository(Setting::class)->findOneBy(['key' => 'showNotInStocks'])->getValue();
  30.         $urNo $em->getRepository(Setting::class)->findOneBy(['key' => 'urNo'])->getValue();
  31.         $em $this->getDoctrine()->getManager();
  32.         if ($showNotInStocks !== null && $showNotInStocks === "0") {
  33.             $result $em->createQuery('select m from App:Product m where m.quantity > 0 AND m.salesNumber > 0 AND m.parent IS NULL AND m.id != ' $urNo '')
  34.                 ->setMaxResults(20)
  35.                 ->getResult();
  36.         } else {
  37.             $result $em->createQuery('select m from App:Product m where m.salesNumber > 0 AND m.parent IS NULL AND m.id != ' $urNo '')
  38.                 ->setMaxResults(20)
  39.                 ->getResult();
  40.         }
  41.         $store $this->getDoctrine()->getRepository(Store::class)->find(1);
  42.         if (count($result) == 0) {
  43.             if ($showNotInStocks !== null && $showNotInStocks === "0") {
  44.                 $result $em->createQuery('select m from App:Product m where m.quantity > 0 AND m.parent IS NULL AND m.id != ' $urNo ' ORDER BY m.id DESC')
  45.                     ->setMaxResults
  46.                     (20)
  47.                     ->getResult();
  48.             } else {
  49.                 $result $em->createQuery('select m from App:Product m where m.parent IS NULL AND m.id != ' $urNo ' ORDER BY m.id DESC')
  50.                     ->setMaxResults
  51.                     (20)
  52.                     ->getResult();
  53.             }
  54.             return [
  55.                 'items' => $result,
  56.                 'store' => $store
  57.             ];
  58.         } else {
  59.             return [
  60.                 'items' => $result,
  61.                 'store' => $store
  62.             ];
  63.         }
  64.     }
  65. }