您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

116 行
3.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\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
  63. ->setSection($this->sectionResolver->getCurrent())
  64. ->getParent(false);
  65. }
  66. public function getSections()
  67. {
  68. return $this->sectionStore
  69. ->setMerchant($this->merchantResolver->getCurrent())
  70. ->getOnline();
  71. }
  72. public function getSectionCurrent()
  73. {
  74. return $this->sectionResolver->getCurrent();
  75. }
  76. public function getMerchants()
  77. {
  78. return $this->merchantStore->getOnline();
  79. }
  80. public function getReminders($params = [])
  81. {
  82. return $this->reminderStore
  83. ->setMerchant($this->merchantResolver->getCurrent())
  84. ->setSection($this->sectionResolver->getCurrent())
  85. ->get($params);
  86. }
  87. public function getUnits()
  88. {
  89. return $this->unitStore->getAsArray();
  90. }
  91. public function getTaxRates()
  92. {
  93. return $this->taxRateStore->setMerchant($this->merchantResolver->getCurrent())->getAsArray();
  94. }
  95. public function getReductionCartCodes()
  96. {
  97. //TODO mettre à jour une fois les repo fait
  98. return array();
  99. }
  100. }