Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

324 lines
12KB

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