Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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