選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

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