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.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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;
  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->addFilterByMerchantOptionnal($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. }