Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

188 rindas
7.0KB

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