Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

ControllerTrait.php 13KB

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