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

610 行
25KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Builder\Order;
  3. use App\Builder\Distribution\DistributionBuilder;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Lc\CaracoleBundle\Builder\File\DocumentBuilder;
  6. use Lc\CaracoleBundle\Event\Order\OrderShopChangeStatusEvent;
  7. use Lc\CaracoleBundle\Factory\File\DocumentFactory;
  8. use Lc\CaracoleBundle\Factory\Order\OrderPaymentFactory;
  9. use Lc\CaracoleBundle\Factory\Order\OrderProductFactory;
  10. use Lc\CaracoleBundle\Factory\Order\OrderProductReductionCatalogFactory;
  11. use Lc\CaracoleBundle\Factory\Order\OrderReductionCartFactory;
  12. use Lc\CaracoleBundle\Factory\Order\OrderReductionCreditFactory;
  13. use Lc\CaracoleBundle\Factory\Order\OrderShopFactory;
  14. use Lc\CaracoleBundle\Factory\Order\OrderStatusHistoryFactory;
  15. use Lc\CaracoleBundle\Model\Address\AddressInterface;
  16. use Lc\CaracoleBundle\Model\File\DocumentInterface;
  17. use Lc\CaracoleBundle\Model\File\DocumentModel;
  18. use Lc\CaracoleBundle\Model\Order\OrderProductInterface;
  19. use Lc\CaracoleBundle\Model\Order\OrderReductionCartInterface;
  20. use Lc\CaracoleBundle\Model\Order\OrderReductionCreditInterface;
  21. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  22. use Lc\CaracoleBundle\Model\Order\OrderStatusInterface;
  23. use Lc\CaracoleBundle\Model\Order\OrderStatusModel;
  24. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  25. use Lc\CaracoleBundle\Model\Product\ProductFamilyModel;
  26. use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
  27. use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
  28. use Lc\CaracoleBundle\Model\Section\SectionInterface;
  29. use Lc\CaracoleBundle\Model\Section\SectionModel;
  30. use Lc\CaracoleBundle\Model\User\VisitorInterface;
  31. use Lc\CaracoleBundle\Repository\Order\OrderProductStore;
  32. use Lc\CaracoleBundle\Repository\Order\OrderShopStore;
  33. use Lc\CaracoleBundle\Repository\Order\OrderStatusStore;
  34. use Lc\CaracoleBundle\Repository\Product\ProductFamilyStore;
  35. use Lc\CaracoleBundle\Resolver\OpeningResolver;
  36. use Lc\CaracoleBundle\Resolver\OrderShopResolver;
  37. use Lc\CaracoleBundle\Solver\Order\OrderProductReductionCatalogSolver;
  38. use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
  39. use Lc\CaracoleBundle\Solver\Price\PriceSolver;
  40. use Lc\CaracoleBundle\Solver\Product\ProductSolver;
  41. use Lc\CaracoleBundle\Statistic\Product\ProductsSalesStatistic;
  42. use Lc\SovBundle\Model\User\UserInterface;
  43. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  44. use Symfony\Component\HttpFoundation\Session\Flash\FlashBagInterface;
  45. class OrderShopBuilder
  46. {
  47. protected EntityManagerInterface $entityManager;
  48. protected OrderStatusStore $orderStatusStore;
  49. protected OrderProductStore $orderProductStore;
  50. protected OrderShopStore $orderShopStore;
  51. protected OrderShopSolver $orderShopSolver;
  52. protected ProductFamilyStore $productFamilyStore;
  53. protected PriceSolver $priceSolver;
  54. protected OrderProductBuilder $orderProductBuilder;
  55. protected DocumentBuilder $documentBuilder;
  56. protected EventDispatcherInterface $eventDispatcher;
  57. protected FlashBagInterface $flashBag;
  58. protected OpeningResolver $openingResolver;
  59. protected ProductSolver $productSolver;
  60. protected OrderShopResolver $orderShopResolver;
  61. protected OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver;
  62. protected DistributionBuilder $distributionBuilder;
  63. public function __construct(
  64. EntityManagerInterface $entityManager,
  65. OrderShopStore $orderShopStore,
  66. OrderShopSolver $orderShopSolver,
  67. OrderStatusStore $orderStatusStore,
  68. OrderProductStore $orderProductStore,
  69. ProductFamilyStore $productFamilyStore,
  70. OrderProductBuilder $orderProductBuilder,
  71. DocumentBuilder $documentBuilder,
  72. PriceSolver $priceSolver,
  73. EventDispatcherInterface $eventDispatcher,
  74. FlashBagInterface $flashBag,
  75. OpeningResolver $openingResolver,
  76. ProductSolver $productSolver,
  77. OrderShopResolver $orderShopResolver,
  78. OrderProductReductionCatalogSolver $orderProductReductionCatalogSolver,
  79. DistributionBuilder $distributionBuilder
  80. ) {
  81. $this->entityManager = $entityManager;
  82. $this->orderShopStore = $orderShopStore;
  83. $this->orderShopSolver = $orderShopSolver;
  84. $this->orderStatusStore = $orderStatusStore;
  85. $this->orderProductStore = $orderProductStore;
  86. $this->productFamilyStore = $productFamilyStore;
  87. $this->orderProductBuilder = $orderProductBuilder;
  88. $this->documentBuilder = $documentBuilder;
  89. $this->priceSolver = $priceSolver;
  90. $this->eventDispatcher = $eventDispatcher;
  91. $this->flashBag = $flashBag;
  92. $this->openingResolver = $openingResolver;
  93. $this->productSolver = $productSolver;
  94. $this->orderShopResolver = $orderShopResolver;
  95. $this->orderProductReductionCatalogSolver = $orderProductReductionCatalogSolver;
  96. $this->distributionBuilder = $distributionBuilder;
  97. }
  98. public function create(
  99. SectionInterface $section,
  100. UserInterface $user = null,
  101. VisitorInterface $visitor = null
  102. ): OrderShopInterface {
  103. $orderShopFactory = new OrderShopFactory();
  104. $orderShop = $orderShopFactory->create($section, $user, $visitor);
  105. $this->setOrderStatus($orderShop, OrderStatusModel::ALIAS_CART);
  106. $this->entityManager->create($orderShop);
  107. $this->entityManager->flush();
  108. return $orderShop;
  109. }
  110. public function createIfNotExist(
  111. SectionInterface $section,
  112. UserInterface $user = null,
  113. VisitorInterface $visitor = null
  114. ): OrderShopInterface {
  115. $cart = $this->orderShopStore
  116. ->setSection($section)
  117. ->getOneCartCurrent($user, $visitor);
  118. if (!$cart) {
  119. $cart = $this->create($section, $user, $visitor);
  120. }
  121. return $cart;
  122. }
  123. public function setOrderStatus(
  124. OrderShopInterface $orderShop,
  125. string $alias,
  126. bool $forceByAdmin = false
  127. ): OrderShopInterface {
  128. $orderStatus = $this->orderStatusStore->getOneByAlias($alias);
  129. if ($orderStatus) {
  130. if ($orderShop->getOrderStatus() === null
  131. || $orderShop->getOrderStatus()->getNextStatusAllowed()->contains($orderStatus)) {
  132. $this->applyChangeOrderStatus($orderShop, $orderStatus, $forceByAdmin);
  133. }
  134. } else {
  135. throw new \ErrorException('La statut demandé n\'existe pas.');
  136. }
  137. return $orderShop;
  138. }
  139. public function applyChangeOrderStatus(
  140. OrderShopInterface $orderShop,
  141. OrderStatusInterface $orderStatus,
  142. bool $forceByAdmin = false
  143. ): void {
  144. $this->eventDispatcher->dispatch(
  145. new OrderShopChangeStatusEvent($orderShop, $orderStatus, $forceByAdmin),
  146. OrderShopChangeStatusEvent::PRE_CHANGE_STATUS
  147. );
  148. $orderShop->setOrderStatusProtected($orderStatus);
  149. $orderStatusHistoryFactory = new OrderStatusHistoryFactory();
  150. $orderStatusHistory = $orderStatusHistoryFactory->create($orderShop, $orderStatus);
  151. $orderShop->addOrderStatusHistory($orderStatusHistory);
  152. $this->eventDispatcher->dispatch(
  153. new OrderShopChangeStatusEvent($orderShop, $orderStatus, $forceByAdmin),
  154. OrderShopChangeStatusEvent::POST_CHANGE_STATUS
  155. );
  156. }
  157. public function addOrderProduct(
  158. OrderShopInterface $orderShop,
  159. OrderProductInterface $orderProductAdd,
  160. bool $persist = true
  161. ): bool {
  162. $return = false;
  163. if ($this->orderShopSolver->isOrderProductAvailableAddCart($orderProductAdd, $orderShop)) {
  164. if ($orderProductAdd->getQuantityOrder() > 0) {
  165. $updated = false;
  166. $this->orderProductBuilder->init($orderProductAdd);
  167. $productFamily = $this->productFamilyStore->getOneBySlug(
  168. $orderProductAdd->getProduct()->getProductFamily()->getSlug()
  169. );
  170. if ($productFamily) {
  171. $reductionCatalog = $productFamily->getReductionCatalog();
  172. if ($reductionCatalog) {
  173. $orderProductReductionCatalogFactory = new OrderProductReductionCatalogFactory();
  174. $orderProductReductionCatalog = $orderProductReductionCatalogFactory->create(
  175. $reductionCatalog->getTitle(),
  176. $reductionCatalog->getValue(),
  177. $reductionCatalog->getUnit(),
  178. $reductionCatalog->getBehaviorTaxRate()
  179. );
  180. $orderProductAdd->setOrderProductReductionCatalog($orderProductReductionCatalog);
  181. }
  182. }
  183. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  184. if ($orderProduct->getProduct()->getId() == $orderProductAdd->getProduct()->getId()
  185. && $orderProduct->getRedelivery() == $orderProductAdd->getRedelivery()
  186. && (string)$this->priceSolver->getPrice($orderProduct)
  187. == (string)$this->priceSolver->getPrice($orderProductAdd)
  188. && $orderProduct->getOrderProductReductionCatalog()
  189. && $orderProductAdd->getOrderProductReductionCatalog()
  190. && $this->orderProductReductionCatalogSolver->compare(
  191. $orderProduct->getOrderProductReductionCatalog(),
  192. $orderProductAdd->getOrderProductReductionCatalog()
  193. )) {
  194. $orderProduct->setQuantityOrder(
  195. $orderProduct->getQuantityOrder() + $orderProductAdd->getQuantityOrder()
  196. );
  197. if ($persist) {
  198. $this->entityManager->persist($orderProduct);
  199. }
  200. $updated = true;
  201. $return = true;
  202. break;
  203. }
  204. }
  205. if (!$updated) {
  206. $orderShop->addOrderProduct($orderProductAdd);
  207. if ($persist) {
  208. if (isset($orderProductReductionCatalog)) {
  209. $this->entityManager->create($orderProductReductionCatalog);
  210. }
  211. //TODO est-ce un update ou un create ???
  212. $this->entityManager->persist($orderProductAdd);
  213. $this->entityManager->update($orderShop);
  214. }
  215. $return = true;
  216. }
  217. if ($persist) {
  218. $this->entityManager->flush();
  219. }
  220. // @TODO : dispatch event cart change
  221. //$this->eventCartChange($orderShop);
  222. }
  223. } else {
  224. // @TODO : retourner le message d'erreur et faire le addFlash dans le contrôleur
  225. /*$availableQuantity = $orderProductAdd->getProduct()->getAvailableQuantityInherited();
  226. $textError = "Le produit <strong>" . $orderProductAdd->getTitleOrderShop(
  227. ) . "</strong> n'est pas disponible";
  228. if ($availableQuantity !== false && $availableQuantity > 0) {
  229. $unit = '';
  230. if ($orderProductAdd->getProduct()->getProductFamily()->getBehaviorCountStock(
  231. ) == ProductFamily::BEHAVIOR_COUNT_STOCK_BY_MEASURE) {
  232. $unit = $orderProductAdd->getProduct()->getUnitInherited()->getUnitReference()->getUnit();
  233. }
  234. $textError .= ' dans cette quantité ';
  235. $user = $this->security->getUser();
  236. if ($user && $user->hasRole('ROLE_USER')) {
  237. $textError .= '<br />' . $availableQuantity . $unit . ' disponible(s) dont ' . $this->getQuantityOrderByProduct(
  238. $orderShop,
  239. $orderProductAdd->getProduct()
  240. ) . $unit . ' déjà dans votre panier.';
  241. }
  242. }
  243. $this->utils->addFlash('error', $textError);*/
  244. }
  245. return $return;
  246. }
  247. public function merge(
  248. OrderShopInterface $orderShop1,
  249. OrderShopInterface $orderShop2,
  250. $persist = true
  251. ): OrderShopInterface {
  252. if ($orderShop1 && $orderShop2) {
  253. foreach ($orderShop2->getOrderProducts() as $orderProduct) {
  254. $orderProductAlreadyInCart = $orderShop1->hasOrderProductAlreadyInCart($orderProduct);
  255. if ($orderProductAlreadyInCart) {
  256. if ($orderProduct->getQuantityOrder() > $orderProductAlreadyInCart->getQuantityOrder()) {
  257. $orderShop1->removeOrderProduct($orderProductAlreadyInCart);
  258. $this->addOrderProduct($orderShop1, $orderProduct);
  259. }
  260. } else {
  261. $this->addOrderProduct($orderShop1, $orderProduct);
  262. }
  263. if ($persist) {
  264. $this->entityManager->delete($orderProduct);
  265. }
  266. }
  267. if ($persist) {
  268. $this->entityManager->delete($orderShop2);
  269. $this->entityManager->update($orderShop1);
  270. $this->entityManager->flush();
  271. }
  272. return $orderShop1;
  273. }
  274. }
  275. public function addPayment(OrderShopInterface $orderShop, string $meanPayment, float $amount): OrderShopInterface
  276. {
  277. $orderPaymentFactory = new OrderPaymentFactory();
  278. $orderPayment = $orderPaymentFactory->create($orderShop, $meanPayment, $amount);
  279. $orderShop->addOrderPayment($orderPayment);
  280. if ($this->orderShopResolver->isPaid($orderShop)) {
  281. $nextStatus = OrderStatusModel::ALIAS_PAID;
  282. } else {
  283. $nextStatus = OrderStatusModel::ALIAS_PARTIAL_PAYMENT;
  284. }
  285. if ($orderShop->getOrderStatus()->getAlias() != $nextStatus) {
  286. $this->changeOrderStatus($orderShop, $nextStatus);
  287. }
  288. $this->entityManager->create($orderPayment);
  289. $this->entityManager->update($orderShop);
  290. $this->entityManager->flush();
  291. return $orderShop;
  292. }
  293. public function initStatsInfo(OrderShopInterface $orderShop, $flush = true)
  294. {
  295. $orderShop->setStatTotal($this->priceSolver->getTotal($orderShop));
  296. $orderShop->setStatTotalWithTax($this->priceSolver->getTotalWithTax($orderShop));
  297. $orderShop->setStatTotalOrderProductsWithReductions(
  298. $this->priceSolver->getTotalOrderProductsWithReductions($orderShop)
  299. );
  300. $orderShop->setStatTotalOrderProductsWithTaxAndReductions(
  301. $this->priceSolver->getTotalOrderProductsWithTaxAndReductions($orderShop)
  302. );
  303. $orderShop->setStatMarginOrderProductsWithReductions(
  304. $this->priceSolver->getMarginOrderProductsWithReductions($orderShop)
  305. );
  306. $orderShop->setStatDeliveryPriceWithReduction($this->priceSolver->getDeliveryPriceWithReduction($orderShop));
  307. $orderShop->setStatDeliveryPriceWithTaxAndReduction(
  308. $this->priceSolver->getDeliveryPriceWithTaxAndReduction($orderShop)
  309. );
  310. $this->entityManager->persist($orderShop);
  311. if ($flush) {
  312. $this->entityManager->flush();
  313. }
  314. }
  315. //initCycleNumber
  316. public function initDistribution(OrderShopInterface $orderShop): void
  317. {
  318. $distribution = $this->distributionBuilder->guessDistributionByDeliveryDate(
  319. $orderShop->getDeliveryDate(),
  320. $orderShop->getSection()
  321. );
  322. $orderShop->setDistribution($distribution);
  323. }
  324. public function createDocumentInvoice(OrderShopInterface $orderShop): DocumentInterface
  325. {
  326. $documentFactory = new DocumentFactory();
  327. $document = $documentFactory->create($orderShop->getSection(), DocumentModel::TYPE_INVOICE);
  328. $this->documentBuilder->initFromOrderShop($document, $orderShop);
  329. return $document;
  330. }
  331. public function addReductionCart(
  332. OrderShopInterface $orderShop,
  333. ReductionCartInterface $reductionCart
  334. ): ?OrderReductionCartInterface {
  335. $orderReductionCartFactory = new OrderReductionCartFactory();
  336. $orderReductionCart = $orderReductionCartFactory->create($orderShop, $reductionCart);
  337. $orderShop->addOrderReductionCart($orderReductionCart);
  338. if ($this->orderShopResolver->isPositiveAmount($orderShop)
  339. && $this->orderShopResolver->isPositiveAmountRemainingToBePaid($orderShop)) {
  340. $this->entityManager->create($orderReductionCart);
  341. $this->entityManager->flush();
  342. return $orderReductionCart;
  343. } else {
  344. //TODO vérifier ce case ! Avec le null en valeur de retour
  345. $orderShop->removeOrderReductionCart($orderReductionCart);
  346. return null;
  347. }
  348. }
  349. // createOrderReductionCredit
  350. public function addReductionCredit(
  351. OrderShopInterface $orderShop,
  352. ReductionCreditInterface $reductionCredit
  353. ): ?OrderReductionCreditInterface {
  354. $orderReductionCreditFactory = new OrderReductionCreditFactory();
  355. $orderReductionCredit = $orderReductionCreditFactory->create($orderShop, $reductionCredit);
  356. $orderShop->addOrderReductionCredit($orderReductionCredit);
  357. if ($this->isOrderShopPositiveAmount($orderShop)
  358. && $this->isOrderShopPositiveAmountRemainingToBePaid($orderShop)) {
  359. $this->entityManager->create($orderReductionCredit);
  360. $this->entityManager->flush();
  361. return $orderReductionCredit;
  362. } else {
  363. $orderShop->removeOrderReductionCredit($orderReductionCredit);
  364. return null;
  365. }
  366. }
  367. public function deductAvailabilityProduct(OrderShopInterface $orderShop): void
  368. {
  369. foreach ($orderShop->getOrderProducts() as $orderProduct) {
  370. $this->applyDeductAvailabilityProduct($orderShop, $orderProduct);
  371. }
  372. }
  373. public function applyDeductAvailabilityProduct(
  374. OrderShopInterface $orderShop,
  375. OrderProductInterface $orderProduct
  376. ): void {
  377. switch ($orderProduct->getProduct()->getProductFamily()->getBehaviorCountStock()) {
  378. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_MEASURE :
  379. //Disponibilité par unité de référence
  380. $oldAvailability = $this->productSolver->getAvailableQuantityInherited($orderProduct->getProduct());
  381. $newAvailability = $oldAvailability - ($orderProduct->getQuantityOrder(
  382. ) * ($orderProduct->getQuantityProduct() / $orderProduct->getUnit()->getCoefficient()));
  383. $productFamily = $orderProduct->getProduct()->getProductFamily();
  384. $productFamily->setAvailableQuantity($newAvailability);
  385. $productFamily->setUpdatedBy($orderShop->getUser());
  386. $this->entityManager->update($productFamily);
  387. break;
  388. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT_FAMILY :
  389. $oldAvailability = $this->productSolver->getAvailableQuantityInherited($orderProduct->getProduct());
  390. $newAvailability = $oldAvailability - $orderProduct->getQuantityOrder();
  391. $productFamily = $orderProduct->getProduct()->getProductFamily();
  392. $productFamily->setAvailableQuantity($newAvailability);
  393. $productFamily->setUpdatedBy($orderShop->getUser());
  394. $this->entityManager->update($productFamily);
  395. break;
  396. case ProductFamilyModel::BEHAVIOR_COUNT_STOCK_BY_PRODUCT :
  397. $oldAvailability = $this->productSolver->getAvailableQuantityInherited($orderProduct->getProduct());
  398. $newAvailability = $oldAvailability - $orderProduct->getQuantityOrder();
  399. $product = $orderProduct->getProduct();
  400. $product->setAvailableQuantity($newAvailability);
  401. $product->setUpdatedBy($orderShop->getUser());
  402. $this->entityManager->update($product);
  403. break;
  404. }
  405. $this->entityManager->flush();
  406. }
  407. public function updatePriceByProductFamily(ProductFamilyInterface $productFamily)
  408. {
  409. // @TODO : faire la vérification isOpenSale depuis la méthode appelante
  410. if (!$this->openingResolver->isOpenSale(
  411. $productFamily->getSection(),
  412. null,
  413. OpeningResolver::OPENING_CONTEXT_BACKEND
  414. )) {
  415. $countOrderProductUpdated = 0;
  416. foreach ($productFamily->getProducts() as $product) {
  417. $orderProducts = $this->orderProductStore->getInCartsByProduct($product);
  418. foreach ($orderProducts as $orderProduct) {
  419. $quantityOrder = $orderProduct->getQuantityOrder();
  420. $orderShop = $orderProduct->getOrderShop();
  421. $orderShop->removeOrderProduct($orderProduct);
  422. $this->entityManager->delete($orderProduct);
  423. $this->entityManager->flush();
  424. $this->entityManager->refresh($orderShop);
  425. $orderProductFactory = new OrderProductFactory();
  426. $addOrderProduct = $orderProductFactory->create($product, $quantityOrder);
  427. $this->addOrderProduct($orderShop, $addOrderProduct);
  428. $countOrderProductUpdated++;
  429. }
  430. }
  431. if ($countOrderProductUpdated) {
  432. // @TODO : faire le add flash dans le controller
  433. /*$this->utils->addFlash(
  434. 'success',
  435. 'success.OrderShop.orderProductUpdated',
  436. array(),
  437. array('%count%' => $countOrderProductUpdated)
  438. );*/
  439. $this->entityManager->flush();
  440. }
  441. return $countOrderProductUpdated;
  442. }
  443. }
  444. public function setStatsInfo(OrderShopInterface $orderShop, $flush = true)
  445. {
  446. $orderShop->setStatTotal($this->priceSolver->getTotal($orderShop));
  447. $orderShop->setStatTotalWithTax($this->priceSolver->getTotalWithTax($orderShop));
  448. $orderShop->setStatTotalOrderProductsWithReductions(
  449. $this->priceSolver->getTotalOrderProductsWithReductions($orderShop)
  450. );
  451. $orderShop->setStatTotalOrderProductsWithTaxAndReductions(
  452. $this->priceSolver->getTotalOrderProductsWithTaxAndReductions($orderShop)
  453. );
  454. $orderShop->setStatMarginOrderProductsWithReductions(
  455. $this->priceSolver->getMarginOrderProductsWithReductions($orderShop)
  456. );
  457. $orderShop->setStatDeliveryPriceWithReduction($this->priceSolver->getDeliveryPriceWithReduction($orderShop));
  458. $orderShop->setStatDeliveryPriceWithTaxAndReduction(
  459. $this->priceSolver->getDeliveryPriceWithTaxAndReduction($orderShop)
  460. );
  461. $this->entityManager->update($orderShop);
  462. if ($flush) {
  463. $this->entityManager->flush();
  464. }
  465. }
  466. public function setHasReach(int $reachStep, OrderShopInterface $orderShop)
  467. {
  468. if ($orderShop->getHasReach() === null || $orderShop->getHasReach() < $reachStep) {
  469. $orderShop->setHasReach($reachStep);
  470. $this->entityManager->persist($orderShop);
  471. $this->entityManager->flush($orderShop);
  472. }
  473. }
  474. public function initComplementaryOrderShop(OrderShopInterface $orderShop, OrderShopInterface $mainOrderShop): void
  475. {
  476. $orderShop->setMainOrderShop($mainOrderShop);
  477. $orderShop->setDeliveryPrice(0);
  478. if ($mainOrderShop->getDeliveryAddress()) {
  479. $this->initDeliveryAddress($orderShop, $mainOrderShop->getDeliveryAddress());
  480. }
  481. $orderShop->setInvoiceAddress($mainOrderShop->getInvoiceAddress());
  482. }
  483. // setDeliveryAddress
  484. public function initDeliveryAddress(OrderShopInterface $orderShop, AddressInterface $address = null): void
  485. {
  486. $orderShop->setDeliveryAddress($address);
  487. $orderShop->setDeliveryInfos($address ? $address->getDeliveryInfos() : null);
  488. }
  489. // resetOrderShopInfos
  490. public function reset(OrderShopInterface $orderShop)
  491. {
  492. $this->initDeliveryAddress($orderShop, null);
  493. $orderShop->setMainOrderShop(null);
  494. $orderShop->setDeliveryPrice(null);
  495. $orderShop->setInvoiceAddress(null);
  496. $orderShop->setDeclineComplementaryOrderShop(false);
  497. }
  498. public function getProductsSalesStatistic(SectionInterface $section, $entity, $nbWeek = 2)
  499. {
  500. $productsSalesStatistic = new ProductsSalesStatistic(
  501. $this->entityManager,
  502. $entity,
  503. $nbWeek,
  504. $this->productSolver
  505. );
  506. $productsSalesStatistic->init($section, $this->orderShopSolver, $this->openingResolver);
  507. $productsSalesStatistic->populateProperties($this->orderShopStore);
  508. return $productsSalesStatistic->getAsArray();
  509. }
  510. }