You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

115 lines
4.8KB

  1. <?php
  2. namespace Lc\ShopBundle\Repository;
  3. use Lc\ShopBundle\Context\DefaultRepositoryInterface;
  4. use Lc\ShopBundle\Context\ProductFamilyInterface;
  5. use Lc\ShopBundle\Context\ReductionCatalogInterface;
  6. /**
  7. * @method ProductFamilyInterface|null find($id, $lockMode = null, $lockVersion = null)
  8. * @method ProductFamilyInterface|null findOneBy(array $criteria, array $orderBy = null)
  9. * @method ProductFamilyInterface[] findAll()
  10. * @method ProductFamilyInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  11. */
  12. class ProductFamilyRepository extends BaseRepository implements DefaultRepositoryInterface
  13. {
  14. public function getInterfaceClass()
  15. {
  16. return ProductFamilyInterface::class;
  17. }
  18. public function getProductFamiliesByCategory($category){
  19. $expr = $this->_em->getExpressionBuilder();
  20. $query = $this->findByMerchantQuery() ;
  21. /* $query->select(array('e as product', 'reductionCatalog as reduction'));
  22. $query->from(ReductionCatalogInterface::class, 'reductionCatalog');*/
  23. $query->andWhere(':category MEMBER OF e.productCategories');
  24. $query->andWhere('e.status = 1');
  25. /* /* $query->andWhere($query->expr()->orX(
  26. $query->expr()->eq('reductionCatalog', 'null'),
  27. $query->expr()->eq( 'reductionCatalog.status = 1 AND (
  28. :user MEMBER OF reductionCatalog.users OR reductionCatalog.users is empty ) AND
  29. (:groupUser MEMBER OF reductionCatalog.groupUsers OR reductionCatalog.groupUsers is empty ) AND
  30. (e MEMBER OF reductionCatalog.productFamilies OR reductionCatalog.productFamilies is empty')
  31. ));
  32. $query
  33. ->andWhere('reductionCatalog.status = 1')
  34. ->andWhere(':user MEMBER OF reductionCatalog.users OR reductionCatalog.users is empty')
  35. ->andWhere(':groupUser MEMBER OF reductionCatalog.groupUsers OR reductionCatalog.groupUsers is empty')
  36. ->andWhere('e MEMBER OF reductionCatalog.productFamilies OR reductionCatalog.productFamilies is empty')
  37. //->andWhere(':category MEMBER OF reductionCatalog.productCategories OR reductionCatalog.productCategories is empty')
  38. //->andWhere('e.supplier MEMBER OF reductionCatalog.suppliers OR reductionCatalog.suppliers is empty')
  39. ->setParameter('user', $user)
  40. ->setParameter('groupUser', $user->getGroupUsers()
  41. );*/
  42. $query->setParameter('category', $category->getId());
  43. return $query->getQuery()->getResult() ;
  44. }
  45. public function getProductFamiliesByNovelties(){
  46. $query = $this->findByMerchantQuery() ;
  47. $query->andWhere('e.status = 1');
  48. $query->andWhere(':now <= e.propertyNoveltyExpirationDate')
  49. ->setParameter('now', new \DateTime()) ;
  50. return $query->getQuery()->getResult() ;
  51. }
  52. /**************************** OLD *********************************/
  53. public function findNovelties()
  54. {
  55. $query = $this->findByMerchantQuery() ;
  56. return $query->getQuery()->getResult() ;
  57. }
  58. public function findNoveltiesByParentCategories()
  59. {
  60. return $this->_productsByParentCategories($this->findNovelties()) ;
  61. }
  62. public function findOrganics()
  63. {
  64. $query = $this->findByMerchantQuery() ;
  65. $query->andWhere('e.propertyOrganicLabel IS NOT NULL');
  66. return $query->getQuery()->getResult() ;
  67. }
  68. public function findOrganicsByParentCategories()
  69. {
  70. return $this->_productsByParentCategories($this->findOrganics()) ;
  71. }
  72. public function _productsByParentCategories($products)
  73. {
  74. $categoriesArray = [] ;
  75. foreach($products as $product) {
  76. $productCategories = $product->getProductCategories() ;
  77. $category = $productCategories[0]->getParentCategory() ;
  78. if(!isset($categoriesArray[$category->getId()])) {
  79. $categoriesArray[$category->getId()] = [
  80. 'category' => $category,
  81. 'products' => []
  82. ] ;
  83. }
  84. $categoriesArray[$category->getId()]['products'][] = $product ;
  85. }
  86. return $categoriesArray;
  87. }
  88. }