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.

65 lines
1.7KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository;
  3. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  4. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  5. use Lc\SovBundle\Repository\StoreInterface;
  6. trait MerchantStoreTrait
  7. {
  8. protected ?MerchantInterface $merchant = null;
  9. public function setMerchant(?MerchantInterface $merchant):self
  10. {
  11. $this->merchant = $merchant;
  12. return $this;
  13. }
  14. public function isMerchantDefined(): bool
  15. {
  16. return isset($this->merchant) && $this->merchant;
  17. }
  18. public function addFilterByMerchantOptionnal(RepositoryQueryInterface $query): StoreInterface
  19. {
  20. if($this->isMerchantDefined()) {
  21. $query->filterByMerchant($this->merchant);
  22. }
  23. return $this;
  24. }
  25. public function addFilterByMerchantRequired(RepositoryQueryInterface $query): StoreInterface
  26. {
  27. $this->addFilterByMerchantOptionnal($query);
  28. if(!$this->isMerchantDefined()) {
  29. throw new \ErrorException('Le Merchant doit être définie dans '.get_class($this));
  30. }
  31. return $this;
  32. }
  33. public function addFilterByMerchantViaSectionOptionnal(RepositoryQueryInterface $query): StoreInterface
  34. {
  35. if($this->isMerchantDefined()) {
  36. $query->filterByMerchantViaSection($this->merchant);
  37. }
  38. return $this;
  39. }
  40. public function addFilterByMerchantViaSectionRequired(RepositoryQueryInterface $query): StoreInterface
  41. {
  42. $this->addFilterByMerchantViaSectionOptionnal($query);
  43. if(!$this->isMerchantDefined()) {
  44. throw new \ErrorException('Le Merchant doit être définie dans '.get_class($this));
  45. }
  46. return $this;
  47. }
  48. }