You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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