Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

310 lines
11KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Controller;
  3. use Lc\CaracoleBundle\Container\Address\AddressContainer;
  4. use Lc\CaracoleBundle\Container\Config\TaxRateContainer;
  5. use Lc\CaracoleBundle\Container\Config\UnitContainer;
  6. use Lc\CaracoleBundle\Container\Credit\CreditHistoryContainer;
  7. use Lc\CaracoleBundle\Container\File\DocumentContainer;
  8. use Lc\CaracoleBundle\Container\Merchant\MerchantContainer;
  9. use Lc\CaracoleBundle\Container\Order\OrderPaymentContainer;
  10. use Lc\CaracoleBundle\Container\Order\OrderProductContainer;
  11. use Lc\CaracoleBundle\Container\Order\OrderProductReductionCatalogContainer;
  12. use Lc\CaracoleBundle\Container\Order\OrderProductRefundContainer;
  13. use Lc\CaracoleBundle\Container\Order\OrderReductionCartContainer;
  14. use Lc\CaracoleBundle\Container\Order\OrderReductionCreditContainer;
  15. use Lc\CaracoleBundle\Container\Order\OrderRefundContainer;
  16. use Lc\CaracoleBundle\Container\Order\OrderShopContainer;
  17. use Lc\CaracoleBundle\Container\Order\OrderStatusContainer;
  18. use Lc\CaracoleBundle\Container\Order\OrderStatusHistoryContainer;
  19. use Lc\CaracoleBundle\Container\PointSale\PointSaleContainer;
  20. use Lc\CaracoleBundle\Container\Product\ProductCategoryContainer;
  21. use Lc\CaracoleBundle\Container\Product\ProductContainer;
  22. use Lc\CaracoleBundle\Container\Product\ProductFamilyContainer;
  23. use Lc\CaracoleBundle\Container\Reduction\ReductionCartContainer;
  24. use Lc\CaracoleBundle\Container\Reduction\ReductionCatalogContainer;
  25. use Lc\CaracoleBundle\Container\Reduction\ReductionCreditContainer;
  26. use Lc\CaracoleBundle\Container\Section\OpeningContainer;
  27. use Lc\CaracoleBundle\Container\Section\SectionContainer;
  28. use Lc\CaracoleBundle\Container\Setting\MerchantSettingContainer;
  29. use Lc\CaracoleBundle\Container\Setting\SectionSettingContainer;
  30. use Lc\CaracoleBundle\Container\User\UserMerchantContainer;
  31. use Lc\CaracoleBundle\Container\User\UserPointSaleContainer;
  32. use Lc\CaracoleBundle\Container\User\VisitorContainer;
  33. use Lc\CaracoleBundle\Model\Merchant\MerchantInterface;
  34. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  35. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  36. use Lc\CaracoleBundle\Model\User\UserMerchantInterface;
  37. use Lc\CaracoleBundle\Model\User\VisitorInterface;
  38. use Lc\CaracoleBundle\Resolver\MerchantResolver;
  39. use Lc\CaracoleBundle\Resolver\SectionResolver;
  40. use Lc\CaracoleBundle\Resolver\VisitorResolver;
  41. use Lc\CaracoleBundle\Solver\Price\PriceSolver;
  42. use Lc\SovBundle\Model\User\UserInterface;
  43. use Lc\SovBundle\Solver\Setting\SettingSolver;
  44. use Symfony\Component\Security\Core\Security;
  45. trait ControllerTrait
  46. {
  47. public static function getSubscribedServices()
  48. {
  49. return array_merge(
  50. parent::getSubscribedServices(),
  51. [
  52. PriceSolver::class => PriceSolver::class,
  53. MerchantResolver::class => MerchantResolver::class,
  54. SectionResolver::class => SectionResolver::class,
  55. OrderShopContainer::class => OrderShopContainer::class,
  56. AddressContainer::class => AddressContainer::class,
  57. TaxRateContainer::class => TaxRateContainer::class,
  58. UnitContainer::class => UnitContainer::class,
  59. CreditHistoryContainer::class => CreditHistoryContainer::class,
  60. DocumentContainer::class => DocumentContainer::class,
  61. MerchantContainer::class => MerchantContainer::class,
  62. OrderPaymentContainer::class => OrderPaymentContainer::class,
  63. OrderProductContainer::class => OrderProductContainer::class,
  64. OrderProductReductionCatalogContainer::class => OrderProductReductionCatalogContainer::class,
  65. OrderProductRefundContainer::class => OrderProductRefundContainer::class,
  66. OrderReductionCartContainer::class => OrderReductionCartContainer::class,
  67. OrderReductionCreditContainer::class => OrderReductionCreditContainer::class,
  68. OrderRefundContainer::class => OrderRefundContainer::class,
  69. OrderStatusContainer::class => OrderStatusContainer::class,
  70. OrderStatusHistoryContainer::class => OrderStatusHistoryContainer::class,
  71. PointSaleContainer::class => PointSaleContainer::class,
  72. ProductCategoryContainer::class => ProductCategoryContainer::class,
  73. ProductContainer::class => ProductContainer::class,
  74. ProductFamilyContainer::class => ProductFamilyContainer::class,
  75. ReductionCartContainer::class => ReductionCartContainer::class,
  76. ReductionCatalogContainer::class => ReductionCatalogContainer::class,
  77. ReductionCreditContainer::class => ReductionCreditContainer::class,
  78. OpeningContainer::class => OpeningContainer::class,
  79. SectionContainer::class => SectionContainer::class,
  80. MerchantSettingContainer::class => MerchantSettingContainer::class,
  81. SectionSettingContainer::class => SectionSettingContainer::class,
  82. UserMerchantContainer::class => UserMerchantContainer::class,
  83. UserPointSaleContainer::class => UserPointSaleContainer::class,
  84. VisitorContainer::class => VisitorContainer::class,
  85. ]
  86. );
  87. }
  88. public function getMerchantSettingCurrent(string $settingName)
  89. {
  90. return $this->getSettingValue($this->getMerchantCurrent(), $settingName);
  91. }
  92. public function getSectionSettingCurrent(string $settingName)
  93. {
  94. return $this->getSettingValue($this->getCurrentSection(), $settingName);
  95. }
  96. public function getSettingSolver(): SettingSolver
  97. {
  98. return $this->get(SettingSolver::class);
  99. }
  100. public function getSettingValue($entity, $settingName)
  101. {
  102. return $this->getSettingSolver()->getSettingValue($entity, $settingName);
  103. }
  104. public function getUserCurrent(): ?UserInterface
  105. {
  106. return $this->get(Security::class)->getUser();
  107. }
  108. public function getVisitorCurrent(): VisitorInterface
  109. {
  110. return $this->getVisitorContainer()->getResolver()->getCurrent();
  111. }
  112. public function getMerchantCurrent(): MerchantInterface
  113. {
  114. return $this->get(MerchantResolver::class)->getCurrent();
  115. }
  116. public function getUserMerchantCurrent(): UserMerchantInterface
  117. {
  118. return $this->getUserMerchantContainer()->getBuilder()->createIfNotExist(
  119. $this->getUserCurrent(),
  120. $this->getMerchantCurrent()
  121. );
  122. }
  123. public function getMerchantUserCurrent(): MerchantInterface
  124. {
  125. return $this->get(MerchantResolver::class)->getMerchantUser($this->getUserCurrent());
  126. }
  127. public function getSectionCurrent(): SectionInterface
  128. {
  129. return $this->get(SectionResolver::class)->getCurrent();
  130. }
  131. public function getCartCurrent(): OrderShopInterface
  132. {
  133. return $this->getOrderShopContainer()->getBuilder()->createIfNotExist(
  134. $this->getSectionCurrent(),
  135. $this->getUserCurrent(),
  136. $this->getVisitorCurrent()
  137. );
  138. }
  139. public function getPriceSolver(): PriceSolver
  140. {
  141. return $this->get(PriceSolver::class);
  142. }
  143. public function getOrderShopContainer(): OrderShopContainer
  144. {
  145. return $this->get(OrderShopContainer::class);
  146. }
  147. public function getAddressContainer(): AddressContainer
  148. {
  149. return $this->get(AddressContainer::class);
  150. }
  151. public function getTaxRateContainer(): TaxRateContainer
  152. {
  153. return $this->get(TaxRateContainer::class);
  154. }
  155. public function getUnitContainer(): UnitContainer
  156. {
  157. return $this->get(UnitContainer::class);
  158. }
  159. public function getCreditHistoryContainer(): CreditHistoryContainer
  160. {
  161. return $this->get(CreditHistoryContainer::class);
  162. }
  163. public function getDocumentContainer(): DocumentContainer
  164. {
  165. return $this->get(DocumentContainer::class);
  166. }
  167. public function getMerchantContainer(): MerchantContainer
  168. {
  169. return $this->get(MerchantContainer::class);
  170. }
  171. public function getOrderPaymentContainer(): OrderPaymentContainer
  172. {
  173. return $this->get(OrderPaymentContainer::class);
  174. }
  175. public function getOrderProductContainer(): OrderProductContainer
  176. {
  177. return $this->get(OrderProductContainer::class);
  178. }
  179. public function getOrderProductReductionCatalogContainer(): OrderProductReductionCatalogContainer
  180. {
  181. return $this->get(OrderProductReductionCatalogContainer::class);
  182. }
  183. public function getOrderProductRefundContainer(): OrderProductRefundContainer
  184. {
  185. return $this->get(OrderProductRefundContainer::class);
  186. }
  187. public function getOrderReductionCartContainer(): OrderReductionCartContainer
  188. {
  189. return $this->get(OrderReductionCartContainer::class);
  190. }
  191. public function getOrderReductionCreditContainer(): OrderReductionCreditContainer
  192. {
  193. return $this->get(OrderReductionCreditContainer::class);
  194. }
  195. public function getOrderRefundContainer(): OrderRefundContainer
  196. {
  197. return $this->get(OrderRefundContainer::class);
  198. }
  199. public function getOrderStatusContainer(): OrderStatusContainer
  200. {
  201. return $this->get(OrderStatusContainer::class);
  202. }
  203. public function getOrderStatusHistoryContainer(): OrderStatusHistoryContainer
  204. {
  205. return $this->get(OrderStatusHistoryContainer::class);
  206. }
  207. public function getPointSaleContainer(): PointSaleContainer
  208. {
  209. return $this->get(PointSaleContainer::class);
  210. }
  211. public function getProductCategoryContainer(): ProductCategoryContainer
  212. {
  213. return $this->get(ProductCategoryContainer::class);
  214. }
  215. public function getProductContainer(): ProductContainer
  216. {
  217. return $this->get(ProductContainer::class);
  218. }
  219. public function getProductFamilyContainer(): ProductFamilyContainer
  220. {
  221. return $this->get(ProductFamilyContainer::class);
  222. }
  223. public function getReductionCartContainer(): ReductionCartContainer
  224. {
  225. return $this->get(ReductionCartContainer::class);
  226. }
  227. public function getReductionCatalogContainer(): ReductionCatalogContainer
  228. {
  229. return $this->get(ReductionCatalogContainer::class);
  230. }
  231. public function getReductionCreditContainer(): ReductionCreditContainer
  232. {
  233. return $this->get(ReductionCreditContainer::class);
  234. }
  235. public function getOpeningContainer(): OpeningContainer
  236. {
  237. return $this->get(OpeningContainer::class);
  238. }
  239. public function getSectionContainer(): SectionContainer
  240. {
  241. return $this->get(SectionContainer::class);
  242. }
  243. public function getMerchantSettingContainer(): MerchantSettingContainer
  244. {
  245. return $this->get(MerchantSettingContainer::class);
  246. }
  247. public function getSectionSettingContainer(): SectionSettingContainer
  248. {
  249. return $this->get(SectionSettingContainer::class);
  250. }
  251. public function getUserMerchantContainer(): UserMerchantContainer
  252. {
  253. return $this->get(UserMerchantContainer::class);
  254. }
  255. public function getUserPointSaleContainer(): UserPointSaleContainer
  256. {
  257. return $this->get(UserPointSaleContainer::class);
  258. }
  259. public function getVisitorContainer(): VisitorContainer
  260. {
  261. return $this->get(VisitorContainer::class);
  262. }
  263. }