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.

599 line
24KB

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