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.7KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Config;
  3. use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
  4. use Lc\CaracoleBundle\Repository\AbstractStore;
  5. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  6. class TaxRateStore extends AbstractStore
  7. {
  8. use MerchantStoreTrait;
  9. protected TaxRateRepositoryQuery $query;
  10. public function __construct(TaxRateRepositoryQuery $query)
  11. {
  12. $this->query = $query;
  13. }
  14. public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  15. {
  16. $query->orderBy('id');
  17. return $query;
  18. }
  19. public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  20. {
  21. return $query;
  22. }
  23. public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  24. {
  25. return $query;
  26. }
  27. public function getAsArray($query = null)
  28. {
  29. $taxRates = $this->createDefaultQuery($query)->find();
  30. $taxRatesList = [];
  31. foreach ($taxRates as $taxRate) {
  32. $taxRatesList[$taxRate->getId()]['title'] = $taxRate->getTitle();
  33. $taxRatesList[$taxRate->getId()]['value'] = $taxRate->getValue();
  34. }
  35. $taxRatesList['default']['title'] = $this->merchant->getTaxRate()->getTitle();
  36. $taxRatesList['default']['value'] = $this->merchant->getTaxRate()->getValue();
  37. return $taxRatesList;
  38. }
  39. public function getAsFormChoices($query = null): array
  40. {
  41. $taxRateArray = $this->createDefaultQuery($query)->find();
  42. $taxRateChoices = [];
  43. foreach($taxRateArray as $taxRate) {
  44. $taxRateChoices[$taxRate->getTitle()] = $taxRate->getId();
  45. }
  46. return $taxRateChoices;
  47. }
  48. }