src/Flexy/FrontBundle/Repository/ProductFrontRepository.php line 32

  1. <?php
  2. namespace App\Flexy\FrontBundle\Repository;
  3. use App\Flexy\ShopBundle\Entity\Product\Product;
  4. use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepository;
  5. use Doctrine\Persistence\ManagerRegistry;
  6. /**
  7.  * @method Product|null find($id, $lockMode = null, $lockVersion = null)
  8.  * @method Product|null findOneBy(array $criteria, array $orderBy = null)
  9.  * @method Product[]    findAll()
  10.  * @method Product[]    findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11.  */
  12. class ProductFrontRepository extends ServiceEntityRepository
  13. {
  14.     public function __construct(ManagerRegistry $registry)
  15.     {
  16.         parent::__construct($registryProduct::class);
  17.     }
  18.      /**
  19.      * @return PubBanner[] Returns an array of PubBanner objects
  20.     */
  21.     public function findDeals()
  22.     {
  23.         $now = new \DateTime();
  24.         return $this->createQueryBuilder('p')
  25.             ->leftJoin("p.promotion","promotion")
  26.             ->leftJoin("p.vendor","vendor")
  27.             ->leftJoin("vendor.user","user")
  28.             ->andWhere('p.isPublished = TRUE AND user.isValid = TRUE  ')
  29.             ->andWhere('promotion IS NOT NULL ')
  30.             ->andWhere('promotion.endAt > :now ')
  31.             ->setParameter("now",$now)
  32.             ->orderBy('p.id''DESC')
  33.             ->setMaxResults(10)
  34.             ->getQuery()
  35.             ->getResult()
  36.         ;
  37.     }
  38.     /**
  39.      * @return PubBanner[] Returns an array of PubBanner objects
  40.     */
  41.     public function findAll()
  42.     {
  43.         return $this->createQueryBuilder('p')
  44.         ->leftJoin("p.vendor","vendor")
  45.         ->leftJoin("vendor.user","user")
  46.             ->andWhere('p.isPublished = TRUE AND user.isValid = TRUE ')
  47.             ->orderBy('p.id''DESC')
  48.             ->getQuery()
  49.             ->getResult()
  50.         ;
  51.     }
  52.         /**
  53.      * @return PubBanner[] Returns an array of PubBanner objects
  54.     */
  55.     public function findByKeyWord($value)
  56.     {
  57.         return $this->createQueryBuilder('p')
  58.             ->leftJoin("p.vendor","vendor")
  59.             ->leftJoin("vendor.user","user")
  60.             ->andWhere('p.isPublished = TRUE AND user.isValid = TRUE  AND p.name LIKE :val')
  61.             ->orWhere('p.skuCode LIKE :val')
  62.             ->orWhere('p.metaTitle LIKE :val')
  63.             ->orWhere('p.metaDescription LIKE :val')
  64.             ->orWhere('p.description LIKE :val')
  65.             ->setParameter('val'"%".$value."%")
  66.             ->orderBy('p.id''ASC')
  67.             ->setMaxResults(10)
  68.             ->getQuery()
  69.             ->getResult()
  70.         ;
  71.     }
  72.     public function findByKeyWordAndCategory($value)
  73.     {
  74.         return $this->createQueryBuilder('p')
  75.             ->leftJoin("p.vendor","vendor")
  76.             ->leftJoin("vendor.user","user")
  77.             ->andWhere('p.isPublished = TRUE AND user.isValid = TRUE ')
  78.             ->andWhere('p.name LIKE :val')
  79.             ->orWhere('p.description LIKE :val')
  80.             ->setParameter('val'"%".$value."%")
  81.             ->orderBy('p.id''ASC')
  82.             ->setMaxResults(10)
  83.             ->getQuery()
  84.             ->getResult()
  85.         ;
  86.     }
  87.     // /**
  88.     //  * @return PubBanner[] Returns an array of PubBanner objects
  89.     //  */
  90.     /*
  91.     public function findByExampleField($value)
  92.     {
  93.         return $this->createQueryBuilder('p')
  94.             ->andWhere('p.exampleField = :val')
  95.             ->setParameter('val', $value)
  96.             ->orderBy('p.id', 'ASC')
  97.             ->setMaxResults(10)
  98.             ->getQuery()
  99.             ->getResult()
  100.         ;
  101.     }
  102.     */
  103.     /*
  104.     public function findOneBySomeField($value): ?PubBanner
  105.     {
  106.         return $this->createQueryBuilder('p')
  107.             ->andWhere('p.exampleField = :val')
  108.             ->setParameter('val', $value)
  109.             ->getQuery()
  110.             ->getOneOrNullResult()
  111.         ;
  112.     }
  113.     */
  114. }