src/Repository/PricingRepository.php line 82

Open in your IDE?
  1. <?php
  2. namespace App\Repository;
  3. use App\Entity\Pricing;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Common\Persistence\ManagerRegistry;
  6. /**
  7.  * @method Pricing|null find($id, $lockMode = null, $lockVersion = null)
  8.  * @method Pricing|null findOneBy(array $criteria, array $orderBy = null)
  9.  * @method Pricing[]    findAll()
  10.  * @method Pricing[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11.  */
  12. class PricingRepository extends ServiceEntityRepository
  13. {
  14.     public function __construct(ManagerRegistry $registry)
  15.     {
  16.         parent::__construct($registryPricing::class);
  17.     }
  18.     public function findAllDiscountsOfCompany($company)
  19.     {
  20.         return $this->createQueryBuilder('p')
  21.             ->join('p.discountProduct''product')
  22.             ->andWhere('product.company = :company')
  23.             ->andWhere('p.isADiscount = true')
  24.             ->setParameter('company'$company)
  25.             ->orderBy('p.endDate''ASC')
  26.             ->getQuery()
  27.             ->getResult()
  28.         ;
  29.     }
  30.     public function findOnSale($sorting null$order null)
  31.     {
  32.         $now = new \DateTime();
  33.         $products =  $this->createQueryBuilder('p')
  34.         // ->select('size(prod.inCarts)')
  35.             ->andWhere('p.isADiscount = true')
  36.             ->leftJoin('p.products''prod')
  37.             ->andWhere('p.startDate <= :now')
  38.             ->andWhere('p.endDate >= :now')
  39.             ->setParameter('now'$now);
  40.             if ($sorting != null) {
  41.      
  42.                 if ($sorting == "popularity") {
  43.                   if (strtolower($order) == "asc") {
  44.                     $order "ASC";
  45.                   } else {
  46.                     $order "DESC";
  47.                   }
  48.             
  49.                    $sorting 'size(prod.inCarts)';
  50.             
  51.                 }
  52.                 if ($sorting == "price") {
  53.                   if (strtolower($order) == "asc") {
  54.                     $order "ASC";
  55.                   } else {
  56.                     $order "DESC";
  57.                   }
  58.                  
  59.                   $sorting "p.price";
  60.                   
  61.                 }
  62.                 if ($sorting == "date") {
  63.                   if (strtolower($order) == "asc") {
  64.                     $order "ASC";
  65.                   } else {
  66.                     $order "DESC";
  67.                   }
  68.             
  69.                   $sorting ="p.startDate";
  70.                 }
  71.                 $products->orderBy$sorting $order);
  72.               }
  73.   
  74. // dd($products);
  75.             return $products->getQuery()
  76.             ->getResult();
  77.     }
  78.     public function findOnSaleFrontpage($maxResults 10)
  79.     {
  80.         $now = new \DateTime();
  81.         return $this->createQueryBuilder('p')
  82.             ->andWhere('p.isADiscount = true')
  83.             ->andWhere('p.startDate <= :now')
  84.             ->andWhere('p.endDate >= :now')
  85.             ->setParameter('now'$now)
  86.             ->setMaxResults($maxResults)
  87.             ->orderBy('RAND()')
  88.             ->getQuery()
  89.             ->getResult()
  90.         ;
  91.     }
  92. }