Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ControllerTrait.php 12KB

vor 3 Jahren
vor 3 Jahren
vor 3 Jahren
vor 3 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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. true
  147. );
  148. }
  149. public function getPriceSolver(): PriceSolver
  150. {
  151. return $this->get(PriceSolver::class);
  152. }
  153. public function getOrderShopContainer(): OrderShopContainer
  154. {
  155. return $this->get(OrderShopContainer::class);
  156. }
  157. public function getAddressContainer(): AddressContainer
  158. {
  159. return $this->get(AddressContainer::class);
  160. }
  161. public function getTaxRateContainer(): TaxRateContainer
  162. {
  163. return $this->get(TaxRateContainer::class);
  164. }
  165. public function getUnitContainer(): UnitContainer
  166. {
  167. return $this->get(UnitContainer::class);
  168. }
  169. public function getCreditHistoryContainer(): CreditHistoryContainer
  170. {
  171. return $this->get(CreditHistoryContainer::class);
  172. }
  173. public function getDocumentContainer(): DocumentContainer
  174. {
  175. return $this->get(DocumentContainer::class);
  176. }
  177. public function getMerchantContainer(): MerchantContainer
  178. {
  179. return $this->get(MerchantContainer::class);
  180. }
  181. public function getOrderPaymentContainer(): OrderPaymentContainer
  182. {
  183. return $this->get(OrderPaymentContainer::class);
  184. }
  185. public function getOrderProductContainer(): OrderProductContainer
  186. {
  187. return $this->get(OrderProductContainer::class);
  188. }
  189. public function getOrderProductReductionCatalogContainer(): OrderProductReductionCatalogContainer
  190. {
  191. return $this->get(OrderProductReductionCatalogContainer::class);
  192. }
  193. public function getOrderProductRefundContainer(): OrderProductRefundContainer
  194. {
  195. return $this->get(OrderProductRefundContainer::class);
  196. }
  197. public function getOrderReductionCartContainer(): OrderReductionCartContainer
  198. {
  199. return $this->get(OrderReductionCartContainer::class);
  200. }
  201. public function getOrderReductionCreditContainer(): OrderReductionCreditContainer
  202. {
  203. return $this->get(OrderReductionCreditContainer::class);
  204. }
  205. public function getOrderRefundContainer(): OrderRefundContainer
  206. {
  207. return $this->get(OrderRefundContainer::class);
  208. }
  209. public function getOrderStatusContainer(): OrderStatusContainer
  210. {
  211. return $this->get(OrderStatusContainer::class);
  212. }
  213. public function getOrderStatusHistoryContainer(): OrderStatusHistoryContainer
  214. {
  215. return $this->get(OrderStatusHistoryContainer::class);
  216. }
  217. public function getPointSaleContainer(): PointSaleContainer
  218. {
  219. return $this->get(PointSaleContainer::class);
  220. }
  221. public function getProductCategoryContainer(): ProductCategoryContainer
  222. {
  223. return $this->get(ProductCategoryContainer::class);
  224. }
  225. public function getProductContainer(): ProductContainer
  226. {
  227. return $this->get(ProductContainer::class);
  228. }
  229. public function getProductFamilyContainer(): ProductFamilyContainer
  230. {
  231. return $this->get(ProductFamilyContainer::class);
  232. }
  233. public function getReductionCartContainer(): ReductionCartContainer
  234. {
  235. return $this->get(ReductionCartContainer::class);
  236. }
  237. public function getReductionCatalogContainer(): ReductionCatalogContainer
  238. {
  239. return $this->get(ReductionCatalogContainer::class);
  240. }
  241. public function getReductionCreditContainer(): ReductionCreditContainer
  242. {
  243. return $this->get(ReductionCreditContainer::class);
  244. }
  245. public function getOpeningContainer(): OpeningContainer
  246. {
  247. return $this->get(OpeningContainer::class);
  248. }
  249. public function getSectionContainer(): SectionContainer
  250. {
  251. return $this->get(SectionContainer::class);
  252. }
  253. public function getMerchantSettingContainer(): MerchantSettingContainer
  254. {
  255. return $this->get(MerchantSettingContainer::class);
  256. }
  257. public function getSectionSettingContainer(): SectionSettingContainer
  258. {
  259. return $this->get(SectionSettingContainer::class);
  260. }
  261. public function getUserMerchantContainer(): UserMerchantContainer
  262. {
  263. return $this->get(UserMerchantContainer::class);
  264. }
  265. public function getUserPointSaleContainer(): UserPointSaleContainer
  266. {
  267. return $this->get(UserPointSaleContainer::class);
  268. }
  269. public function getVisitorContainer(): VisitorContainer
  270. {
  271. return $this->get(VisitorContainer::class);
  272. }
  273. public function getQualityLabelContainer(): QualityLabelContainer
  274. {
  275. return $this->get(QualityLabelContainer::class);
  276. }
  277. }