You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ControllerTrait.php 11KB

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