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.

95 lines
2.3KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Product;
  3. use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
  4. use Lc\CaracoleBundle\Repository\SectionStoreTrait;
  5. use Lc\CaracoleBundle\Solver\Price\PriceSolver;
  6. use Lc\SovBundle\Repository\AbstractStore;
  7. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  8. class ProductFamilyStore extends AbstractStore
  9. {
  10. use SectionStoreTrait;
  11. protected ProductFamilyRepositoryQuery $query;
  12. protected PriceSolver $priceSolver;
  13. public function __construct(ProductFamilyRepositoryQuery $query, PriceSolver $priceSolver)
  14. {
  15. $this->query = $query;
  16. $this->priceSolver = $priceSolver;
  17. }
  18. public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  19. {
  20. $query->orderBy('position');
  21. }
  22. public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  23. {
  24. $query->filterBySection($this->section);
  25. return $query;
  26. }
  27. public function relationsDefault($query): RepositoryQueryInterface
  28. {
  29. $query->joinProductCategories();
  30. $query->joinProducts();
  31. return $query;
  32. }
  33. //getProductFamiliesByCategory
  34. public function getByCategory(ProductCategoryInterface $productCategory, $query = null)
  35. {
  36. $query = $this->createDefaultQuery($query);
  37. $query
  38. ->filterIsOnline()
  39. ->filterByProductCategory($productCategory);
  40. return $query->find();
  41. }
  42. //getProductFamiliesNovelties
  43. public function getByNovelties($query = null)
  44. {
  45. $query = $this->createDefaultQuery($query);
  46. $query
  47. ->filterByPropertyNoveltyExpirationDate()
  48. ->filterIsOnline();
  49. return $query->find();
  50. }
  51. //getProductFamiliesOrganics
  52. public function getOrganics($query = null)
  53. {
  54. $query = $this->createDefaultQuery($query);
  55. $query
  56. ->filterPropertyOrganicLabel()
  57. ->filterIsOnline();
  58. return $query->find();
  59. }
  60. //findByTerms
  61. public function getByTerms($terms, $maxResults = false, $query = null)
  62. {
  63. $query = $this->createDefaultQuery($query);
  64. $query->filterIsOnline();
  65. $query->groupBy('id');
  66. if($maxResults) {
  67. $query->limit($maxResults);
  68. }
  69. return $query->find();
  70. }
  71. }