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.

88 line
2.9KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Twig;
  3. use Lc\CaracoleBundle\Repository\Config\TaxRateStore;
  4. use Lc\CaracoleBundle\Repository\Config\UnitStore;
  5. use Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryQuery;
  6. use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
  7. use Lc\CaracoleBundle\Repository\Reminder\ReminderStore;
  8. use Lc\CaracoleBundle\Repository\Section\SectionRepository;
  9. use Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface;
  10. use Lc\CaracoleBundle\Repository\Section\SectionRepositoryQuery;
  11. use Lc\CaracoleBundle\Repository\Section\SectionStore;
  12. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  13. use Lc\CaracoleBundle\Resolver\SectionResolver;
  14. use Lc\ShopBundle\Context\UnitInterface;
  15. use Twig\Extension\AbstractExtension;
  16. use Twig\TwigFunction;
  17. class StoreTwigExtension extends AbstractExtension
  18. {
  19. protected MerchantStore $merchantStore;
  20. protected SectionStore $sectionStore;
  21. protected ReminderStore $reminderStore;
  22. protected MerchantResolver $merchantResolver;
  23. protected SectionResolver $sectionResolver;
  24. protected UnitStore $unitStore;
  25. protected TaxRateStore $taxRateStore;
  26. public function __construct(
  27. MerchantResolver $merchantResolver,
  28. SectionResolver $sectionResolver,
  29. MerchantStore $merchantStore,
  30. SectionStore $sectionStore,
  31. ReminderStore $reminderStore,
  32. UnitStore $unitStore,
  33. TaxRateStore $taxRateStore
  34. ) {
  35. $this->merchantResolver = $merchantResolver;
  36. $this->sectionResolver = $sectionResolver;
  37. $this->merchantStore = $merchantStore;
  38. $this->sectionStore = $sectionStore;
  39. $this->reminderStore = $reminderStore;
  40. $this->unitStore = $unitStore;
  41. $this->taxRateStore = $taxRateStore;
  42. }
  43. public function getFunctions()
  44. {
  45. return array(
  46. new TwigFunction('carac_sections', [$this, 'getSections']),
  47. new TwigFunction('carac_merchants', [$this, 'getMerchants']),
  48. new TwigFunction('carac_reminders', [$this, 'getReminders']),
  49. new TwigFunction('carac_units', [$this, 'getUnits']),
  50. new TwigFunction('carac_tax_rates', [$this, 'getTaxRates']),
  51. );
  52. }
  53. public function getSections()
  54. {
  55. return $this->sectionStore->setMerchant($this->merchantResolver->getCurrent())->getOnline();
  56. }
  57. public function getMerchants()
  58. {
  59. return $this->merchantStore->getOnline();
  60. }
  61. public function getReminders($params = [])
  62. {
  63. return $this->reminderStore
  64. ->setMerchant($this->merchantResolver->getCurrent())
  65. ->setSection($this->sectionResolver->getCurrent())
  66. ->get($params);
  67. }
  68. public function getUnits()
  69. {
  70. return $this->unitStore->getAsArray();
  71. }
  72. public function getTaxRates()
  73. {
  74. return $this->taxRateStore->setMerchant($this->merchantResolver->getCurrent())->getAsArray();
  75. }
  76. }