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.

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