Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

StoreTwigExtension.php 9.2KB

3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
2 anos atrás
2 anos atrás
3 anos atrás
3 anos atrás
2 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
3 anos atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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('cart_current_visited', [$this, 'getCartCurrentVisited']),
  80. new TwigFunction('merchant_current', [$this, 'getMerchantCurrent']),
  81. new TwigFunction('user_merchant_current', [$this, 'getUserMerchantCurrent']),
  82. new TwigFunction('section_current', [$this, 'getSectionCurrent']),
  83. new TwigFunction('section_default', [$this, 'getSectionDefault']),
  84. new TwigFunction('section_current_default', [$this, 'getSectionCurrentDefault']),
  85. new TwigFunction('section_current_visited', [$this, 'getSectionCurrentVisited']),
  86. new TwigFunction('is_out_of_sections', [$this, 'isOutOfSections']),
  87. new TwigFunction('is_inside_section', [$this, 'isInsideSection']),
  88. new TwigFunction('section_current_slug', [$this, 'getSectionCurrentSlug']),
  89. new TwigFunction('section_current_default_slug', [$this, 'getSectionCurrentDefaultSlug']),
  90. new TwigFunction('section_current_visited_slug', [$this, 'getSectionCurrentVisitedSlug']),
  91. new TwigFunction('merchant_setting', [$this, 'getMerchantSetting']),
  92. new TwigFunction('merchant_setting_current', [$this, 'getMerchantSettingCurrent']),
  93. new TwigFunction('section_setting', [$this, 'getSectionSetting']),
  94. new TwigFunction('section_setting_current', [$this, 'getSectionSettingCurrent']),
  95. new TwigFunction('visitor_current', [$this, 'getVisitorCurrent']),
  96. );
  97. }
  98. public function isInsideSection(): bool
  99. {
  100. return (bool) $this->sectionResolver->getCurrent();
  101. }
  102. public function isOutOfSections()
  103. {
  104. return $this->sectionResolver->isOutOfSection();
  105. }
  106. public function getSections()
  107. {
  108. return $this->sectionStore
  109. ->setMerchant($this->merchantResolver->getCurrent())
  110. ->getOnline();
  111. }
  112. public function getMerchants()
  113. {
  114. return $this->merchantStore->getOnline();
  115. }
  116. public function getSectionCurrent(): ?SectionInterface
  117. {
  118. return $this->sectionResolver->getCurrent();
  119. }
  120. public function getSectionDefault(): ?SectionInterface
  121. {
  122. return $this->sectionStore->setMerchant($this->merchantResolver->getCurrent())->getOneDefault();
  123. }
  124. public function getSectionCurrentDefault(): ?SectionInterface
  125. {
  126. return $this->sectionResolver->getCurrent(true);
  127. }
  128. public function getSectionCurrentVisited(): ?SectionInterface
  129. {
  130. return $this->sectionResolver->getCurrent(true, true);
  131. }
  132. public function getSectionCurrentSlug(): string
  133. {
  134. return $this->sectionResolver->getCurrent()->getSlug();
  135. }
  136. public function getSectionCurrentDefaultSlug(): string
  137. {
  138. return $this->sectionResolver->getCurrent(true)->getSlug();
  139. }
  140. public function getSectionCurrentVisitedSlug(): string
  141. {
  142. return $this->sectionResolver->getCurrent(true, true)->getSlug();
  143. }
  144. public function getCartCurrent(): OrderShopInterface
  145. {
  146. return $this->orderShopBuilder->createIfNotExist(
  147. $this->sectionResolver->getCurrent(),
  148. $this->security->getUser(),
  149. $this->visitorResolver->getCurrent(),
  150. true
  151. );
  152. }
  153. public function getCartCurrentVisited(): OrderShopInterface
  154. {
  155. return $this->orderShopBuilder->createIfNotExist(
  156. $this->sectionResolver->getCurrent(true, true),
  157. $this->security->getUser(),
  158. $this->visitorResolver->getCurrent(),
  159. true
  160. );
  161. }
  162. public function getMerchantCurrent(): MerchantInterface
  163. {
  164. return $this->merchantResolver->getCurrent();
  165. }
  166. public function getUserMerchantCurrent(): ?UserMerchantInterface
  167. {
  168. return $this->merchantResolver->getUserMerchant();
  169. }
  170. public function getMerchantSetting(MerchantInterface $merchant, string $settingName): string
  171. {
  172. return $this->settingSolver->getSettingValue($merchant, $settingName);
  173. }
  174. public function getMerchantSettingCurrent(string $settingName): ?string
  175. {
  176. return $this->settingSolver->getSettingValue($this->getMerchantCurrent(), $settingName);
  177. }
  178. public function getSectionSetting(SectionInterface $section, string $settingName): ?string
  179. {
  180. return $this->settingSolver->getSettingValue($section, $settingName);
  181. }
  182. public function getSectionSettingCurrent(string $settingName)
  183. {
  184. return $this->settingSolver->getSettingValue($this->getSectionCurrent(), $settingName);
  185. }
  186. public function getProductCategories()
  187. {
  188. return $this->productCategoryStore
  189. ->setSection($this->sectionResolver->getCurrent())
  190. ->getParent();
  191. }
  192. public function getReminders($params = [])
  193. {
  194. return $this->reminderStore
  195. ->setMerchant($this->merchantResolver->getCurrent())
  196. ->setSection($this->sectionResolver->getCurrent())
  197. ->get($params);
  198. }
  199. public function getUnits()
  200. {
  201. return $this->unitStore->getAsArray();
  202. }
  203. public function getTaxRates()
  204. {
  205. return $this->taxRateStore->setMerchant($this->merchantResolver->getCurrent())->getAsArray();
  206. }
  207. public function getReductionCartCodes()
  208. {
  209. //TODO mettre à jour une fois les repo fait
  210. return array();
  211. }
  212. public function getVisitorCurrent()
  213. {
  214. return $this->visitorResolver->getCurrent();
  215. }
  216. }