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.

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