Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

739 lines
24KB

  1. <?php
  2. namespace Lc\CaracoleBundle\Repository\Order;
  3. use App\Builder\Distribution\DistributionBuilder;
  4. use App\Entity\Distribution\Distribution;
  5. use App\Entity\Order\OrderStatus;
  6. use Doctrine\ORM\EntityManagerInterface;
  7. use Lc\CaracoleBundle\Builder\File\DocumentBuilder;
  8. use Lc\CaracoleBundle\Model\Distribution\DistributionInterface;
  9. use Lc\CaracoleBundle\Model\Order\OrderShopInterface;
  10. use Lc\CaracoleBundle\Model\Product\ProductFamilyInterface;
  11. use Lc\CaracoleBundle\Model\Product\ProductInterface;
  12. use Lc\CaracoleBundle\Model\Reduction\ReductionCartInterface;
  13. use Lc\CaracoleBundle\Model\Reduction\ReductionCreditInterface;
  14. use Lc\CaracoleBundle\Model\Reduction\ReductionCreditModel;
  15. use Lc\CaracoleBundle\Model\User\VisitorInterface;
  16. use Lc\CaracoleBundle\Repository\Merchant\MerchantStore;
  17. use Lc\CaracoleBundle\Repository\MerchantStoreTrait;
  18. use Lc\CaracoleBundle\Repository\Reduction\ReductionCartStore;
  19. use Lc\CaracoleBundle\Repository\Reduction\ReductionCreditStore;
  20. use Lc\CaracoleBundle\Repository\Section\SectionStore;
  21. use Lc\CaracoleBundle\Resolver\OpeningResolver;
  22. use Lc\CaracoleBundle\Repository\SectionStoreTrait;
  23. use Lc\CaracoleBundle\Solver\Order\OrderShopSolver;
  24. use Lc\CaracoleBundle\Solver\Price\PriceSolver;
  25. use Lc\CaracoleBundle\Solver\Reduction\ReductionCartSolver;
  26. use Lc\SovBundle\Model\User\UserInterface;
  27. use Lc\CaracoleBundle\Repository\AbstractStore;
  28. use Lc\SovBundle\Repository\RepositoryQueryInterface;
  29. use Lc\SovBundle\Solver\Setting\SettingSolver;
  30. use Lc\SovBundle\Translation\FlashBagTranslator;
  31. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  32. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  33. class OrderShopStore extends AbstractStore
  34. {
  35. use SectionStoreTrait;
  36. use MerchantStoreTrait;
  37. protected OrderShopRepositoryQuery $query;
  38. protected EntityManagerInterface $entityManager;
  39. protected PriceSolver $priceSolver;
  40. protected DocumentBuilder $documentBuilder;
  41. protected ReductionCreditStore $reductionCreditStore;
  42. protected ReductionCartSolver $reductionCartSolver;
  43. protected SectionStore $sectionStore;
  44. protected OrderProductStore $orderProductStore;
  45. protected MerchantStore $merchantStore;
  46. protected FlashBagTranslator $flashBagTranslator;
  47. protected OpeningResolver $openingResolver;
  48. protected ParameterBagInterface $parameterBag;
  49. protected UrlGeneratorInterface $router;
  50. protected OrderShopSolver $orderShopSolver;
  51. protected ReductionCartStore $reductionCartStore;
  52. protected DistributionBuilder $distributionBuilder;
  53. protected SettingSolver $settingSolver;
  54. public function __construct(
  55. OrderShopRepositoryQuery $query,
  56. EntityManagerInterface $entityManager,
  57. PriceSolver $priceSolver,
  58. DocumentBuilder $documentBuilder,
  59. ReductionCreditStore $reductionCreditStore,
  60. ReductionCartSolver $reductionCartSolver,
  61. SectionStore $sectionStore,
  62. OrderProductStore $orderProductStore,
  63. MerchantStore $merchantStore,
  64. FlashBagTranslator $flashBagTranslator,
  65. ParameterBagInterface $parameterBag,
  66. UrlGeneratorInterface $router,
  67. OrderShopSolver $orderShopSolver,
  68. ReductionCartStore $reductionCartStore,
  69. DistributionBuilder $distributionBuilder,
  70. SettingSolver $settingSolver
  71. )
  72. {
  73. $this->query = $query;
  74. $this->entityManager = $entityManager;
  75. $this->priceSolver = $priceSolver;
  76. $this->documentBuilder = $documentBuilder;
  77. $this->reductionCreditStore = $reductionCreditStore;
  78. $this->reductionCartSolver = $reductionCartSolver;
  79. $this->sectionStore = $sectionStore;
  80. $this->orderProductStore = $orderProductStore;
  81. $this->merchantStore = $merchantStore;
  82. $this->flashBagTranslator = $flashBagTranslator;
  83. $this->parameterBag = $parameterBag;
  84. $this->router = $router;
  85. $this->orderShopSolver = $orderShopSolver;
  86. $this->reductionCartStore = $reductionCartStore;
  87. $this->distributionBuilder = $distributionBuilder;
  88. $this->settingSolver = $settingSolver;
  89. }
  90. public function orderByDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  91. {
  92. //$query->orderBy('id', 'DESC');
  93. return $query;
  94. }
  95. public function filtersDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  96. {
  97. $this
  98. ->addFilterBySectionOptionnal($query)
  99. ->addFilterByMerchantViaSectionOptionnal($query);
  100. return $query;
  101. }
  102. public function relationsDefault(RepositoryQueryInterface $query): RepositoryQueryInterface
  103. {
  104. $query->joinOrderProducts(true);
  105. return $query;
  106. }
  107. // getOrderShopsOfWeek
  108. //getByCurrentCycle
  109. public function getByCurrentDistribution($params = [], $query = null)
  110. {
  111. return $this->getBy(
  112. array_merge(
  113. [
  114. 'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder(
  115. $this->section
  116. ),
  117. 'isValid' => true,
  118. ],
  119. $params
  120. ),
  121. $query
  122. );
  123. }
  124. //public $countOrderShopsOfWeek = null;
  125. // public function countByCurrentCycle(bool $excludeComplementaryOrderShops = true, $query = null)
  126. //countByCurrentCycle
  127. public function countByCurrentDistribution(array $params, $query = null)
  128. {
  129. return $this->countBy(
  130. array_merge(
  131. [
  132. 'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder(
  133. $this->section
  134. ),
  135. 'excludeComplementaryOrderShops' => isset($params['excludeComplementaryOrderShops']) ?? true,
  136. ],
  137. $params
  138. ),
  139. $query
  140. );
  141. // @TODO : optimisation à remettre en place
  142. /*if (is_null($this->countOrderShopsOfWeek)) {
  143. $this->countOrderShopsOfWeek = $this->getByCurrentCycle(
  144. $section,
  145. [
  146. 'count' => true,
  147. 'excludeComplementaryOrderShops' => $excludeComplementaryOrderShops
  148. ]
  149. );
  150. }
  151. return $this->countOrderShopsOfWeek;*/
  152. }
  153. public function getByCurrentDistributionAndUser(UserInterface $user = null, array $params = [], $query = null)
  154. {
  155. return $this->getByCurrentDistribution(
  156. array_merge(
  157. [
  158. 'user' => $user,
  159. 'excludeComplementaryOrderShops' => true
  160. ],
  161. $params
  162. ),
  163. $query
  164. );
  165. }
  166. public function countValidByCurrentDistributionAndUser(UserInterface $user = null, array $params = [], $query = null)
  167. {
  168. return $this->countByCurrentDistribution(
  169. array_merge(
  170. [
  171. 'isValid' => true,
  172. 'user' => $user,
  173. 'excludeComplementaryOrderShops' => true
  174. ],
  175. $params
  176. ),
  177. $query
  178. );
  179. }
  180. // getNextWeekId
  181. public function getNextCycleId(Distribution $distribution, $query = null): int
  182. {
  183. $lastOrder = $this->getOneLastValidByDistribution($distribution, $query);
  184. if ($lastOrder) {
  185. return intval($lastOrder->getCycleId() + 1);
  186. } else {
  187. return 1;
  188. }
  189. }
  190. public function getNextIdValidOrder($query = null): int
  191. {
  192. $lastOrder = $this->getOneLastValid($query);
  193. if ($lastOrder) {
  194. return intval($lastOrder->getIdValidOrder() + 1);
  195. } else {
  196. return 1;
  197. }
  198. }
  199. public function countValidByUserAllMerchant($user, $query = null): int
  200. {
  201. $this->resetContext();
  202. return $this->countBy(
  203. [
  204. 'user' => $user,
  205. 'isValid' => true,
  206. 'excludeComplementaryOrderShops' => true
  207. ],
  208. $query
  209. );
  210. }
  211. public function countValidByUser(UserInterface $user = null, $query = null): int
  212. {
  213. return $this->countBy(
  214. [
  215. 'user' => $user,
  216. 'isValid' => true,
  217. 'excludeComplementaryOrderShops' => true
  218. ],
  219. $query
  220. );
  221. }
  222. //countValidByCurrentCycle
  223. public function countValidByCurrentDistribution($query = null): int
  224. {
  225. return $this->countBy(
  226. [
  227. 'distribution' => $this->distributionBuilder->guessCurrentDistributionOrder($this->section),
  228. 'isValid' => true,
  229. 'excludeComplementaryOrderShops' => true
  230. ],
  231. $query
  232. );
  233. }
  234. // countValidOrderWithReductionCredit
  235. public function countValidWithReductionCredit(
  236. ReductionCreditInterface $reductionCredit,
  237. UserInterface $user = null,
  238. $query = null
  239. ): int
  240. {
  241. //TODO vérifier que ne pas utiliser createDefaultQuery est pertinent
  242. $query = $this->createQuery($query);
  243. if ($user) {
  244. $query->filterByUser($user);
  245. }
  246. $query
  247. ->selectCount()
  248. ->filterByReductionCredit($reductionCredit)
  249. ->filterByStatus(OrderStatus::$statusAliasAsValid);
  250. return $query->count();
  251. }
  252. // countValidOrderWithReductionCart
  253. public function countValidWithReductionCart(
  254. ReductionCartInterface $reductionCart,
  255. $query = null
  256. ): int
  257. {
  258. $query = $this->createQuery($query);
  259. $query
  260. ->selectCount()
  261. ->filterByReductionCart($reductionCart)
  262. ->filterByStatus(OrderStatus::$statusAliasAsValid);
  263. return $query->count();
  264. }
  265. // countValidOrderWithReductionCartPerUser
  266. public function countValidWithReductionCartByUser(
  267. ReductionCartInterface $reductionCart,
  268. UserInterface $user,
  269. $query = null
  270. ): int
  271. {
  272. $query = $this->createQuery($query);
  273. $query
  274. ->selectCount()
  275. ->filterByUser($user)
  276. ->filterByReductionCart($reductionCart)
  277. ->filterByStatus(OrderStatus::$statusAliasAsValid);
  278. return $query->count();
  279. }
  280. public function isFirstOrder(UserInterface $user): bool
  281. {
  282. return $this->countBy([
  283. 'user' => $user,
  284. 'isValid' => true,
  285. 'excludeComplementaryOrderShops' => false
  286. ]) == 1;
  287. }
  288. // findCartCurrent
  289. public function getOneCartCurrent(
  290. UserInterface $user = null,
  291. VisitorInterface $visitor = null,
  292. $query = null
  293. ): ?OrderShopInterface
  294. {
  295. if (is_null($user) && is_null($visitor)) {
  296. return null;
  297. }
  298. $query = $this->createDefaultQuery($query);
  299. if (!is_null($user)) {
  300. $query->filterByUser($user);
  301. } else {
  302. if (!is_null($visitor)) {
  303. $query->filterByVisitor($visitor);
  304. }
  305. }
  306. $query
  307. ->selectOrderReductionCarts()
  308. ->filterByStatus(OrderStatus::$statusAliasAsCart);
  309. return $query->findOne();
  310. }
  311. // findLastOrderValidOfWeek
  312. //getOneLastValidByCycle
  313. public function getOneLastValidByDistribution(
  314. DistributionInterface $distribution,
  315. $query = null
  316. ): ?OrderShopInterface
  317. {
  318. $query = $this->createDefaultQuery($query);
  319. $query
  320. ->filterByDistribution($distribution)
  321. ->filterByStatus(OrderStatus::$statusAliasAsValid)
  322. ->filterIsNotComplementaryOrderShop()
  323. ->orderBy('.cycleId', 'DESC');
  324. return $query->findOne();
  325. }
  326. public function getOneValidByDistributionAndUser(
  327. DistributionInterface $distribution,
  328. UserInterface $user,
  329. $query = null
  330. ): ?OrderShopInterface
  331. {
  332. $query = $this->createDefaultQuery($query);
  333. $query
  334. ->filterByDistribution($distribution)
  335. ->filterByUser($user)
  336. ->filterByStatus(OrderStatus::$statusAliasAsValid)
  337. ->filterIsNotComplementaryOrderShop()
  338. ->orderBy('.cycleId', 'DESC');
  339. return $query->findOne();
  340. }
  341. //findLastOrderValid
  342. public function getOneLastValid($query = null): ?OrderShopInterface
  343. {
  344. $query = $this->createDefaultQuery($query);
  345. $query
  346. ->filterByStatus(OrderStatus::$statusAliasAsValid)
  347. ->filterIsNotComplementaryOrderShop()
  348. ->orderBy('.idValidOrder', 'DESC');
  349. return $query->findOne();
  350. }
  351. public function countBy(array $params = [], $query = null)
  352. {
  353. $query = $this->createDefaultQuery($query);
  354. $query->selectCount();
  355. $this->applyGetByFilters($params, $query);
  356. return $query->count();
  357. }
  358. public function getBy(array $params = [], $query = null): array
  359. {
  360. $query = $this->createDefaultQuery($query);
  361. $this->applyGetByFilters($params, $query);
  362. $orderShops = $query->find();
  363. if (isset($params['mergeComplementaryOrderShops']) && $params['mergeComplementaryOrderShops'] == true) {
  364. $mergeComplementaryOrderShopsSameSection = isset($params['mergeComplementaryOrderShopsSameSection'])
  365. ? $params['mergeComplementaryOrderShopsSameSection'] : false;
  366. foreach ($orderShops as $orderShop) {
  367. $this->orderShopSolver->mergeComplentaryOrderShops($orderShop, true, $mergeComplementaryOrderShopsSameSection);
  368. }
  369. }
  370. return $orderShops;
  371. }
  372. protected function applyGetByFilters(array $params, $query)
  373. {
  374. if (isset($params['isDeliveryHome']) && $params['isDeliveryHome']) {
  375. $query->filterIsDeliveryHome();
  376. }
  377. if (isset($params['isDeliveryPointSale']) && $params['isDeliveryPointSale']) {
  378. $query->filterIsDeliveryPointSale();
  379. }
  380. if (isset($params['isMerchantOnline'])) {
  381. $query->filterIsMerchantOnline();
  382. }
  383. if (isset($params['select'])) {
  384. $query->selectParam($params['select']);
  385. }
  386. if (isset($params['dateStart']) || isset($params['dateEnd'])) {
  387. $params['dateField'] = isset($params['dateField']) ? $params['dateField'] : 'validationDate';
  388. }
  389. if (isset($params['dateStart'])) {
  390. $query->filterByDateStart($params['dateField'], $params['dateStart']);
  391. }
  392. if (isset($params['dateEnd'])) {
  393. $query->filterByDateEnd($params['dateField'], $params['dateEnd']);
  394. }
  395. if (isset($params['distribution'])) {
  396. $query->filterByDistribution($params['distribution']);
  397. }
  398. if (isset($params['distributions'])) {
  399. $query->filterByDistributions($params['distributions']);
  400. }
  401. if (isset($params['isCart'])) {
  402. $query->filterByStatus(OrderStatus::$statusAliasAsCart);
  403. }
  404. if (isset($params['isValid'])) {
  405. $query->filterByStatus(OrderStatus::$statusAliasAsValid);
  406. }
  407. if (isset($params['isWaitingDelivery'])) {
  408. $query->filterByStatus(OrderStatus::$statusAliasWaitingDelivery);
  409. }
  410. if (isset($params['orderStatus'])) {
  411. $query->filterByStatus([$params['orderStatus']]);
  412. }
  413. if (isset($params['user'])) {
  414. $query->filterByUser($params['user']);
  415. }
  416. if (isset($params['address'])) {
  417. $query->filterByAddress($params['address']);
  418. }
  419. if (isset($params['minimumTomorrowDelivery'])) {
  420. $query->filterMinimumTomorrowDelivery();
  421. }
  422. if (isset($params['mergeComplementaryOrderShops']) && $params['mergeComplementaryOrderShops']) {
  423. $query
  424. ->joinComplementaryOrderShops();
  425. }
  426. if (isset($params['isComplementaryOrderShop']) && $params['isComplementaryOrderShop']) {
  427. $query->filterIsComplementaryOrderShop();
  428. if (isset($params['sectionMainOrderShop']) && $params['sectionMainOrderShop']) {
  429. $query->filterSectionMainOrderShop($params['sectionMainOrderShop']);
  430. }
  431. }
  432. if ((isset($params['excludeComplementaryOrderShops']) && $params['excludeComplementaryOrderShops'])
  433. || (isset($params['mergeComplementaryOrderShops']) && $params['mergeComplementaryOrderShops'])) {
  434. $query->filterIsNullMainOrderShop();
  435. }
  436. if (isset($params['joinProductFamily'])) {
  437. $query->joinProductFamily(true);
  438. }
  439. if (isset($params['orderBy'])) {
  440. $sort = isset($params['orderByDirection']) ? $params['orderByDirection'] : 'DESC';
  441. $query->orderBy($params['orderBy'], $sort);
  442. } else {
  443. $query->orderBy('.id', 'DESC');
  444. }
  445. if (isset($params['groupBy'])) {
  446. $query->groupBy($params['groupBy']);
  447. }
  448. return $query;
  449. }
  450. public function isReductionGiftUsed(ReductionCreditInterface $reductionGift, $query = null)
  451. {
  452. if ($this->countValidWithReductionCredit($reductionGift, null, $query)) {
  453. return true;
  454. } else {
  455. return false;
  456. }
  457. }
  458. public function isReductionCreditUsed(
  459. ReductionCreditInterface $reductionCredit,
  460. UserInterface $user = null,
  461. $query = null
  462. )
  463. {
  464. if ($this->countValidWithReductionCredit($reductionCredit, $user, $query)) {
  465. return true;
  466. } else {
  467. return false;
  468. }
  469. }
  470. public function getReductionCreditsAvailableByUser(UserInterface $user): array
  471. {
  472. $reductionCredits = $this->reductionCreditStore
  473. ->setMerchant($this->merchant)
  474. ->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user);
  475. $reductionCreditsArray = [];
  476. foreach ($reductionCredits as $reductionCredit) {
  477. if (!$this->countValidWithReductionCredit($reductionCredit, $user)) {
  478. $reductionCreditsArray[] = $reductionCredit;
  479. }
  480. }
  481. return $reductionCreditsArray;
  482. }
  483. public function getReductionGiftsAvailableByUser(UserInterface $user): array
  484. {
  485. $reductionGifts = $this->reductionCreditStore
  486. ->setMerchant($this->merchant)
  487. ->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user);
  488. $reductionGiftsArray = [];
  489. foreach ($reductionGifts as $reductionGift) {
  490. if (!$this->countValidWithReductionCredit($reductionGift, $user)) {
  491. $reductionGiftsArray[] = $reductionGift;
  492. }
  493. }
  494. return $reductionGiftsArray;
  495. }
  496. // getReductionCartRemainingQuantity
  497. public function getReductionCartRemainingQuantity(ReductionCartInterface $reductionCart): float
  498. {
  499. return $reductionCart->getAvailableQuantity() - $this->countValidWithReductionCart(
  500. $reductionCart
  501. );
  502. }
  503. // getReductionCartUsedQuantityPerUser
  504. public function getReductionCartUsedQuantityByUser(
  505. ReductionCartInterface $reductionCart,
  506. UserInterface $user
  507. ): float
  508. {
  509. return $this->countValidWithReductionCartByUser($reductionCart, $user);
  510. }
  511. // getReductionCartUsedQuantity
  512. public function getReductionCartUsedQuantity(ReductionCartInterface $reductionCart): float
  513. {
  514. return $this->countValidWithReductionCart($reductionCart);
  515. }
  516. // getReductionCartRemainingQuantityPerUser
  517. public function getReductionCartRemainingQuantityByUser(
  518. ReductionCartInterface $reductionCart,
  519. UserInterface $user
  520. ): float
  521. {
  522. if ($reductionCart->getAvailableQuantityPerUser()) {
  523. return $reductionCart->getAvailableQuantityPerUser() - $this->countValidWithReductionCartByUser(
  524. $reductionCart,
  525. $user
  526. );
  527. }
  528. return false;
  529. }
  530. // findAllAvailableForUser / getReductionCartsAvailableByUser
  531. public function getReductionCartAvailableByUser(UserInterface $user, string $type = null, $query = null)
  532. {
  533. $reductionCarts = $this->reductionCartStore
  534. ->setMerchant($this->merchant)
  535. ->getOnline();
  536. $reductionCartsArray = [];
  537. foreach ($reductionCarts as $reductionCart) {
  538. if ($this->reductionCartSolver->matchWithUser($reductionCart, $user)
  539. && $this->reductionCartSolver->matchWithGroupUser($reductionCart, $user)
  540. && $this->getReductionCartRemainingQuantityByUser($reductionCart, $user)
  541. && ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)
  542. && (!$this->merchant || $reductionCart->getMerchant() == $this->merchant)) {
  543. if(!$type || $reductionCart->getType() == $type) {
  544. $reductionCartsArray[] = $reductionCart;
  545. }
  546. }
  547. }
  548. return $reductionCartsArray;
  549. }
  550. //countValidOrderProductsOfCyclesByProducts
  551. public function countValidOrderProductsOfDistributionsByProducts(
  552. array $distributions,
  553. array $products,
  554. ProductFamilyInterface $productFamily,
  555. $query = null
  556. ): array
  557. {
  558. $query = $this->createDefaultQuery($query);
  559. $query
  560. ->filterByAlias(OrderStatus::$statusAliasAsValid)
  561. ->filterByDistributions($distributions)
  562. ->filterByProducts($products)
  563. ->selectSum()
  564. ->groupBy('distribution.cycleNumber, product.id');
  565. //TODO vérifier ou est utilisé cette fonction ???
  566. return $query->find();
  567. }
  568. //countValidOrderProductsOfCycleByProduct
  569. public function countValidOrderProductsOfDistributionByProduct(
  570. DistributionInterface $distribution,
  571. ProductInterface $product,
  572. $query = null
  573. ): float
  574. {
  575. //TODO attention à vérifier
  576. $query = $this->createQuery($query);
  577. $query
  578. ->filterByAlias(OrderStatus::$statusAliasAsValid)
  579. ->filterByDistribution($distribution)
  580. ->filterByProduct($product)
  581. ->selectSumQuantityOrder()
  582. ->joinDistribution()
  583. ->groupBy('distribution.cycleNumber, product.id');
  584. $result = $query->findOne();
  585. if ($result) {
  586. return $result['quantity'];
  587. }
  588. return 0;
  589. }
  590. public function isReductionCreditAllowAddToOrder(
  591. OrderShopInterface $orderShop,
  592. ReductionCreditInterface $reductionCredit
  593. )
  594. {
  595. $user = $orderShop->getUser();
  596. // appartient à l'utilisateur
  597. if (!$reductionCredit->getUsers()->contains($user)) {
  598. // @TODO : déplacer la gestion du flash message
  599. $this->flashBagTranslator->add('error', 'userNotAllow', 'ReductionCredit');
  600. return false;
  601. }
  602. // n'a pas été utilisé
  603. if ($reductionCredit->getType() == ReductionCreditModel::TYPE_CREDIT) {
  604. if ($this->countValidWithReductionCredit($reductionCredit, $user) > 0) {
  605. // @TODO : déplacer la gestion du flash message
  606. $this->flashBagTranslator->add('error', 'alreadyUse', 'ReductionCredit');
  607. return false;
  608. }
  609. } else {
  610. if ($this->countValidWithReductionCredit($reductionCredit) > 0) {
  611. // @TODO : déplacer la gestion du flash message
  612. $this->flashBagTranslator->add('error', 'alreadyUse', 'ReductionCredit');
  613. return false;
  614. }
  615. }
  616. return true;
  617. }
  618. public function getCartAlone($query = null)
  619. {
  620. $query = $this->createQuery($query);
  621. $query->filterByAlias(OrderStatus::$statusAliasAsCart);
  622. $query->filterByUserIsNull();
  623. $query->filterByVisitorIsNull();
  624. return $query->limit(10000)->find();
  625. }
  626. }