|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <?php
-
- namespace Lc\ShopBundle\Repository;
-
- use Lc\ShopBundle\Context\DefaultRepositoryInterface;
- use Lc\ShopBundle\Context\ProductFamilyInterface;
-
- /**
- * @method ProductFamilyInterface|null find($id, $lockMode = null, $lockVersion = null)
- * @method ProductFamilyInterface|null findOneBy(array $criteria, array $orderBy = null)
- * @method ProductFamilyInterface[] findAll()
- * @method ProductFamilyInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
- */
- class ProductFamilyRepository extends BaseRepository implements DefaultRepositoryInterface
- {
- public function getInterfaceClass()
- {
- return ProductFamilyInterface::class;
- }
-
- public function findNovelties()
- {
- $query = $this->findByMerchantQuery() ;
- $query->andWhere(':now <= e.propertyNoveltyExpirationDate')
- ->setParameter('now', new \DateTime()) ;
- return $query->getQuery()->getResult() ;
- }
-
- public function findNoveltiesByParentCategories()
- {
- return $this->_productsByParentCategories($this->findNovelties()) ;
- }
-
- public function findOrganics()
- {
- $query = $this->findByMerchantQuery() ;
- $query->andWhere('e.propertyOrganicLabel IS NOT NULL');
- return $query->getQuery()->getResult() ;
- }
-
- public function findOrganicsByParentCategories()
- {
- return $this->_productsByParentCategories($this->findOrganics()) ;
- }
-
- public function _productsByParentCategories($products)
- {
- $categoriesArray = [] ;
- foreach($products as $product) {
- $productCategories = $product->getProductCategories() ;
- $category = $productCategories[0]->getParentCategory() ;
- if(!isset($categoriesArray[$category->getId()])) {
- $categoriesArray[$category->getId()] = [
- 'category' => $category,
- 'products' => []
- ] ;
- }
- $categoriesArray[$category->getId()]['products'][] = $product ;
- }
-
- return $categoriesArray;
- }
-
- public function findByTerms($terms, $maxResults = false)
- {
- $query = $this->findByMerchantQuery() ;
- $query->andWhere('e.title LIKE :terms');
- $query->setParameter('terms', '%'.$terms.'%') ;
- if($maxResults) {
- $query->setMaxResults($maxResults) ;
- }
- return $query->getQuery()->getResult() ;
- }
- }
|