Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

364 lines
13KB

  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. }