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.

64 lines
1.8KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Product;
  3. use Lc\CaracoleBundle\Model\Product\ProductCategoryInterface;
  4. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  5. use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
  6. use Lc\CaracoleBundle\Repository\SectionStoreTrait;
  7. use Lc\CaracoleBundle\Repository\AbstractStore;
  8. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  9. class ProductCategoryStore extends AbstractStore
  10. {
  11. use SectionStoreTrait;
  12. use MerchantStoreTrait;
  13. protected ProductCategoryRepositoryQuery $query;
  14. public function __construct(ProductCategoryRepositoryQuery $query)
  15. {
  16. $this->query = $query;
  17. }
  18. public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  19. {
  20. $query->addOrderBy('.parent')->addOrderBy('.position');
  21. return $query;
  22. }
  23. public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  24. {
  25. $query->filterIsOnlineAndOffline();
  26. $this->addFilterBySectionOptionnal($query);
  27. $this->addFilterByMerchantViaSectionOptionnal($query);
  28. return $query;
  29. }
  30. public function relationsDefault($query): RepositoryQueryInterface
  31. {
  32. return $query;
  33. }
  34. public function getOneParent(): ?ProductCategoryInterface
  35. {
  36. $query = $this->createDefaultQuery();
  37. $query->filterIsParent();
  38. return $query->findOne();
  39. }
  40. public function getByDevAlias(string $devAlias): array
  41. {
  42. $query = $this->createDefaultQuery();
  43. $query->filterByDevAlias($devAlias);
  44. return $query->find();
  45. }
  46. public function getOneByTitle(string $title): ?ProductCategoryInterface
  47. {
  48. $query = $this->createDefaultQuery();
  49. $query->filterByTitle($title);
  50. return $query->findOne();
  51. }
  52. }