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.

ControllerTrait.php 13KB

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