Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

112 lines
3.8KB

  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\Product\ProductCategoryStore;
  8. use Lc\CaracoleBundle\Repository\Reminder\ReminderStore;
  9. use Lc\CaracoleBundle\Repository\Section\SectionRepository;
  10. use Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface;
  11. use Lc\CaracoleBundle\Repository\Section\SectionRepositoryQuery;
  12. use Lc\CaracoleBundle\Repository\Section\SectionStore;
  13. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  14. use Lc\CaracoleBundle\Resolver\SectionResolver;
  15. use Lc\ShopBundle\Context\UnitInterface;
  16. use Twig\Extension\AbstractExtension;
  17. use Twig\TwigFunction;
  18. class StoreTwigExtension extends AbstractExtension
  19. {
  20. protected MerchantStore $merchantStore;
  21. protected SectionStore $sectionStore;
  22. protected ReminderStore $reminderStore;
  23. protected MerchantResolver $merchantResolver;
  24. protected SectionResolver $sectionResolver;
  25. protected UnitStore $unitStore;
  26. protected TaxRateStore $taxRateStore;
  27. protected ProductCategoryStore $productCategoryStore;
  28. public function __construct(
  29. MerchantResolver $merchantResolver,
  30. SectionResolver $sectionResolver,
  31. MerchantStore $merchantStore,
  32. SectionStore $sectionStore,
  33. ReminderStore $reminderStore,
  34. UnitStore $unitStore,
  35. TaxRateStore $taxRateStore,
  36. ProductCategoryStore $productCategoryStore
  37. ) {
  38. $this->merchantResolver = $merchantResolver;
  39. $this->sectionResolver = $sectionResolver;
  40. $this->merchantStore = $merchantStore;
  41. $this->sectionStore = $sectionStore;
  42. $this->reminderStore = $reminderStore;
  43. $this->unitStore = $unitStore;
  44. $this->taxRateStore = $taxRateStore;
  45. $this->productCategoryStore = $productCategoryStore;
  46. }
  47. public function getFunctions()
  48. {
  49. return array(
  50. new TwigFunction('carac_sections', [$this, 'getSections']),
  51. new TwigFunction('carac_section_current', [$this, 'getSectionCurrent']),
  52. new TwigFunction('carac_merchants', [$this, 'getMerchants']),
  53. new TwigFunction('carac_reminders', [$this, 'getReminders']),
  54. new TwigFunction('carac_units', [$this, 'getUnits']),
  55. new TwigFunction('carac_tax_rates', [$this, 'getTaxRates']),
  56. new TwigFunction('carac_reduction_cart_codes', [$this, 'getTaxRates']),
  57. new TwigFunction('carac_product_categories', [$this, 'getProductCategories']),
  58. );
  59. }
  60. public function getProductCategories()
  61. {
  62. return $this->productCategoryStore->getParent(false);
  63. }
  64. public function getSections()
  65. {
  66. return $this->sectionStore->setMerchant($this->merchantResolver->getCurrent())->getOnline();
  67. }
  68. public function getSectionCurrent()
  69. {
  70. return $this->sectionResolver->getCurrentFrontend();
  71. }
  72. public function getMerchants()
  73. {
  74. return $this->merchantStore->getOnline();
  75. }
  76. public function getReminders($params = [])
  77. {
  78. return $this->reminderStore
  79. ->setMerchant($this->merchantResolver->getCurrent())
  80. ->setSection($this->sectionResolver->getCurrent())
  81. ->get($params);
  82. }
  83. public function getUnits()
  84. {
  85. return $this->unitStore->getAsArray();
  86. }
  87. public function getTaxRates()
  88. {
  89. return $this->taxRateStore->setMerchant($this->merchantResolver->getCurrent())->getAsArray();
  90. }
  91. public function getReductionCartCodes()
  92. {
  93. //TODO mettre à jour une fois les repo fait
  94. return array();
  95. }
  96. }