No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

StoreTwigExtension.php 7.2KB

hace 3 años
hace 3 años
hace 3 años
hace 3 años
hace 3 años
hace 3 años
hace 3 años
hace 3 años
hace 3 años
hace 3 años
hace 3 años
hace 3 años
hace 3 años
hace 3 años
hace 3 años
hace 3 años
hace 3 años
hace 3 años
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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_current_slug', [$this, 'getSectionCurrentSlug']),
  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. new TwigFunction('visitor_current', [$this, 'getVisitorCurrent']),
  88. );
  89. }
  90. public function getSections()
  91. {
  92. return $this->sectionStore
  93. ->setMerchant($this->merchantResolver->getCurrent())
  94. ->getOnline();
  95. }
  96. public function getMerchants()
  97. {
  98. return $this->merchantStore->getOnline();
  99. }
  100. public function getSectionCurrent(): SectionInterface
  101. {
  102. return $this->sectionResolver->getCurrent();
  103. }
  104. public function getSectionCurrentSlug(): string
  105. {
  106. return $this->sectionResolver->getCurrent()->getSlug();
  107. }
  108. public function getCartCurrent(): OrderShopInterface
  109. {
  110. return $this->orderShopBuilder->createIfNotExist(
  111. $this->sectionResolver->getCurrent(),
  112. $this->security->getUser(),
  113. $this->visitorResolver->getCurrent(),
  114. true
  115. );
  116. }
  117. public function getMerchantCurrent(): MerchantInterface
  118. {
  119. return $this->merchantResolver->getCurrent();
  120. }
  121. public function getUserMerchantCurrent(): ?UserMerchantInterface
  122. {
  123. return $this->merchantResolver->getUserMerchant();
  124. }
  125. public function getMerchantSetting(MerchantInterface $merchant, string $settingName): string
  126. {
  127. return $this->settingSolver->getSettingValue($merchant, $settingName);
  128. }
  129. public function getMerchantSettingCurrent(string $settingName): ?string
  130. {
  131. return $this->settingSolver->getSettingValue($this->getMerchantCurrent(), $settingName);
  132. }
  133. public function getSectionSetting(SectionInterface $section, string $settingName): ?string
  134. {
  135. return $this->settingSolver->getSettingValue($section, $settingName);
  136. }
  137. public function getSectionSettingCurrent(string $settingName)
  138. {
  139. return $this->settingSolver->getSettingValue($this->getSectionCurrent(), $settingName);
  140. }
  141. public function getProductCategories()
  142. {
  143. return $this->productCategoryStore
  144. ->setSection($this->sectionResolver->getCurrent())
  145. ->getParent();
  146. }
  147. public function getReminders($params = [])
  148. {
  149. return $this->reminderStore
  150. ->setMerchant($this->merchantResolver->getCurrent())
  151. ->setSection($this->sectionResolver->getCurrent())
  152. ->get($params);
  153. }
  154. public function getUnits()
  155. {
  156. return $this->unitStore->getAsArray();
  157. }
  158. public function getTaxRates()
  159. {
  160. return $this->taxRateStore->setMerchant($this->merchantResolver->getCurrent())->getAsArray();
  161. }
  162. public function getReductionCartCodes()
  163. {
  164. //TODO mettre à jour une fois les repo fait
  165. return array();
  166. }
  167. public function getVisitorCurrent()
  168. {
  169. return $this->visitorResolver->getCurrent();
  170. }
  171. }