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.

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