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

173 lines
6.5KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Twig;
  3. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  4. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  5. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  6. use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
  7. use Lc\CaracoleBundle\Repository\Config\TaxRateStore;
  8. use Lc\CaracoleBundle\Repository\Config\UnitStore;
  9. use Lc\CaracoleBundle\Repository\Merchant\MerchantRepositoryQuery;
  10. use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
  11. use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
  12. use Lc\CaracoleBundle\Repository\Product\ProductCategoryStore;
  13. use Lc\CaracoleBundle\Repository\Reminder\ReminderStore;
  14. use Lc\CaracoleBundle\Repository\Section\SectionRepository;
  15. use Lc\CaracoleBundle\Repository\Section\SectionRepositoryInterface;
  16. use Lc\CaracoleBundle\Repository\Section\SectionRepositoryQuery;
  17. use Lc\CaracoleBundle\Repository\Section\SectionStore;
  18. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  19. use Lc\CaracoleBundle\Resolver\SectionResolver;
  20. use Lc\ShopBundle\Context\UnitInterface;
  21. use Lc\SovBundle\Solver\Setting\SettingSolver;
  22. use Twig\Extension\AbstractExtension;
  23. use Twig\TwigFunction;
  24. class StoreTwigExtension extends AbstractExtension
  25. {
  26. protected MerchantStore $merchantStore;
  27. protected SectionStore $sectionStore;
  28. protected ReminderStore $reminderStore;
  29. protected MerchantResolver $merchantResolver;
  30. protected SectionResolver $sectionResolver;
  31. protected UnitStore $unitStore;
  32. protected TaxRateStore $taxRateStore;
  33. protected ProductCategoryStore $productCategoryStore;
  34. protected OrderShopStore $orderShopStore;
  35. protected SettingSolver $settingSolver;
  36. public function __construct(
  37. MerchantResolver $merchantResolver,
  38. SectionResolver $sectionResolver,
  39. MerchantStore $merchantStore,
  40. SectionStore $sectionStore,
  41. ReminderStore $reminderStore,
  42. UnitStore $unitStore,
  43. TaxRateStore $taxRateStore,
  44. ProductCategoryStore $productCategoryStore,
  45. OrderShopStore $orderShopStore,
  46. SettingSolver $settingSolver
  47. ) {
  48. $this->merchantResolver = $merchantResolver;
  49. $this->sectionResolver = $sectionResolver;
  50. $this->merchantStore = $merchantStore;
  51. $this->sectionStore = $sectionStore;
  52. $this->reminderStore = $reminderStore;
  53. $this->unitStore = $unitStore;
  54. $this->taxRateStore = $taxRateStore;
  55. $this->productCategoryStore = $productCategoryStore;
  56. $this->orderShopStore = $orderShopStore;
  57. $this->settingSolver = $settingSolver;
  58. }
  59. public function getFunctions()
  60. {
  61. return array(
  62. new TwigFunction('carac_sections', [$this, 'getSections']),
  63. new TwigFunction('carac_section_current', [$this, 'getSectionCurrent']),
  64. new TwigFunction('carac_cart_current', [$this, 'getCartCurrent']),
  65. new TwigFunction('carac_merchants', [$this, 'getMerchants']),
  66. new TwigFunction('carac_reminders', [$this, 'getReminders']),
  67. new TwigFunction('carac_units', [$this, 'getUnits']),
  68. new TwigFunction('carac_tax_rates', [$this, 'getTaxRates']),
  69. new TwigFunction('carac_reduction_cart_codes', [$this, 'getTaxRates']),
  70. new TwigFunction('product_categories', [$this, 'getProductCategories']),
  71. new TwigFunction('cart_current', [$this, 'getCartCurrent']),
  72. new TwigFunction('merchant_current', [$this, 'getMerchantCurrent']),
  73. new TwigFunction('user_merchant_current', [$this, 'getUserMerchantCurrent']),
  74. new TwigFunction('section_current', [$this, 'getSectionCurrent']),
  75. new TwigFunction('merchant_setting', [$this, 'getMerchantSetting']),
  76. new TwigFunction('merchant_setting_current', [$this, 'getMerchantSettingCurrent']),
  77. new TwigFunction('section_setting', [$this, 'getSectionSetting']),
  78. new TwigFunction('section_setting_current', [$this, 'getSectionSettingCurrent']),
  79. );
  80. }
  81. public function getSections()
  82. {
  83. return $this->sectionStore
  84. ->setMerchant($this->merchantResolver->getCurrent())
  85. ->getOnline();
  86. }
  87. public function getMerchants()
  88. {
  89. return $this->merchantStore->getOnline();
  90. }
  91. public function getSectionCurrent(): SectionInterface
  92. {
  93. return $this->sectionResolver->getCurrent();
  94. }
  95. public function getCartCurrent(): OrderShopInterface
  96. {
  97. return $this->orderShopStore
  98. ->setSection($this->sectionResolver->getCurrent())
  99. ->getOneCartCurrent();
  100. }
  101. public function getMerchantCurrent(): MerchantInterface
  102. {
  103. return $this->merchantResolver->getCurrent();
  104. }
  105. public function getUserMerchantCurrent(): UserMerchantInterface
  106. {
  107. $this->merchantResolver->getUserMerchant();
  108. }
  109. public function getMerchantSetting(MerchantInterface $merchant, string $settingName): string
  110. {
  111. return $this->settingSolver->getSettingValue($merchant, $settingName);
  112. }
  113. public function getMerchantSettingCurrent(string $settingName): string
  114. {
  115. return $this->settingSolver->getSettingValue($this->getMerchantCurrent(), $settingName);
  116. }
  117. public function getSectionSetting(SectionInterface $section, string $settingName): string
  118. {
  119. return $this->settingSolver->getSettingValue($section, $settingName);
  120. }
  121. public function getSectionSettingCurrent(string $settingName): string
  122. {
  123. return $this->settingSolver->getSettingValue($this->getSectionCurrent(), $settingName);
  124. }
  125. public function getProductCategories()
  126. {
  127. return $this->productCategoryStore
  128. ->setSection($this->sectionResolver->getCurrent())
  129. ->getParent();
  130. }
  131. public function getReminders($params = [])
  132. {
  133. return $this->reminderStore
  134. ->setMerchant($this->merchantResolver->getCurrent())
  135. ->setSection($this->sectionResolver->getCurrent())
  136. ->get($params);
  137. }
  138. public function getUnits()
  139. {
  140. return $this->unitStore->getAsArray();
  141. }
  142. public function getTaxRates()
  143. {
  144. return $this->taxRateStore->setMerchant($this->merchantResolver->getCurrent())->getAsArray();
  145. }
  146. public function getReductionCartCodes()
  147. {
  148. //TODO mettre à jour une fois les repo fait
  149. return array();
  150. }
  151. }