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.

731 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. // findCartCurrent
  282. public function getOneCartCurrent(
  283. UserInterface $user = null,
  284. VisitorInterface $visitor = null,
  285. $query = null
  286. ): ?OrderShopInterface
  287. {
  288. if (is_null($user) && is_null($visitor)) {
  289. return null;
  290. }
  291. $query = $this->createDefaultQuery($query);
  292. if (!is_null($user)) {
  293. $query->filterByUser($user);
  294. } else {
  295. if (!is_null($visitor)) {
  296. $query->filterByVisitor($visitor);
  297. }
  298. }
  299. $query
  300. ->selectOrderReductionCarts()
  301. ->filterByStatus(OrderStatusModel::$statusAliasAsCart);
  302. return $query->findOne();
  303. }
  304. // findLastOrderValidOfWeek
  305. //getOneLastValidByCycle
  306. public function getOneLastValidByDistribution(
  307. DistributionInterface $distribution,
  308. $query = null
  309. ): ?OrderShopInterface
  310. {
  311. $query = $this->createDefaultQuery($query);
  312. $query
  313. ->filterByDistribution($distribution)
  314. ->filterByStatus(OrderStatusModel::$statusAliasAsValid)
  315. ->filterIsNotComplementaryOrderShop()
  316. ->orderBy('.cycleId', 'DESC');
  317. return $query->findOne();
  318. }
  319. public function getOneValidByDistributionAndUser(
  320. DistributionInterface $distribution,
  321. UserInterface $user,
  322. $query = null
  323. ): ?OrderShopInterface
  324. {
  325. $query = $this->createDefaultQuery($query);
  326. $query
  327. ->filterByDistribution($distribution)
  328. ->filterByUser($user)
  329. ->filterByStatus(OrderStatusModel::$statusAliasAsValid)
  330. ->filterIsNotComplementaryOrderShop()
  331. ->orderBy('.cycleId', 'DESC');
  332. return $query->findOne();
  333. }
  334. //findLastOrderValid
  335. public function getOneLastValid($query = null): ?OrderShopInterface
  336. {
  337. $query = $this->createDefaultQuery($query);
  338. $query
  339. ->filterByStatus(OrderStatusModel::$statusAliasAsValid)
  340. ->filterIsNotComplementaryOrderShop()
  341. ->orderBy('.idValidOrder', 'DESC');
  342. return $query->findOne();
  343. }
  344. public function countBy(array $params = [], $query = null)
  345. {
  346. $query = $this->createDefaultQuery($query);
  347. $query->selectCount();
  348. $this->applyGetByFilters($params, $query);
  349. return $query->count();
  350. }
  351. public function getBy(array $params = [], $query = null): array
  352. {
  353. $query = $this->createDefaultQuery($query);
  354. $this->applyGetByFilters($params, $query);
  355. $orderShops = $query->find();
  356. if (isset($params['mergeComplementaryOrderShops']) && $params['mergeComplementaryOrderShops'] == true) {
  357. $mergeComplementaryOrderShopsSameSection = isset($params['mergeComplementaryOrderShopsSameSection'])
  358. ? $params['mergeComplementaryOrderShopsSameSection'] : false;
  359. foreach ($orderShops as $orderShop) {
  360. $this->orderShopSolver->mergeComplentaryOrderShops($orderShop, true, $mergeComplementaryOrderShopsSameSection);
  361. }
  362. }
  363. return $orderShops;
  364. }
  365. protected function applyGetByFilters(array $params, $query)
  366. {
  367. if (isset($params['isDeliveryHome']) && $params['isDeliveryHome']) {
  368. $query->filterIsDeliveryHome();
  369. }
  370. if (isset($params['isDeliveryPointSale']) && $params['isDeliveryPointSale']) {
  371. $query->filterIsDeliveryPointSale();
  372. }
  373. if (isset($params['isMerchantOnline'])) {
  374. $query->filterIsMerchantOnline();
  375. }
  376. if (isset($params['select'])) {
  377. $query->selectParam($params['select']);
  378. }
  379. if (isset($params['dateStart']) || isset($params['dateEnd'])) {
  380. $params['dateField'] = isset($params['dateField']) ? $params['dateField'] : 'validationDate';
  381. }
  382. if (isset($params['dateStart'])) {
  383. $query->filterByDateStart($params['dateField'], $params['dateStart']);
  384. }
  385. if (isset($params['dateEnd'])) {
  386. $query->filterByDateEnd($params['dateField'], $params['dateEnd']);
  387. }
  388. if (isset($params['distribution'])) {
  389. $query->filterByDistribution($params['distribution']);
  390. }
  391. if (isset($params['distributions'])) {
  392. $query->filterByDistributions($params['distributions']);
  393. }
  394. if (isset($params['isCart'])) {
  395. $query->filterByStatus(OrderStatusModel::$statusAliasAsCart);
  396. }
  397. if (isset($params['isValid'])) {
  398. $query->filterByStatus(OrderStatusModel::$statusAliasAsValid);
  399. }
  400. if (isset($params['isWaitingDelivery'])) {
  401. $query->filterByStatus(OrderStatusModel::$statusAliasWaitingDelivery);
  402. }
  403. if (isset($params['orderStatus'])) {
  404. $query->filterByStatus([$params['orderStatus']]);
  405. }
  406. if (isset($params['user'])) {
  407. $query->filterByUser($params['user']);
  408. }
  409. if (isset($params['address'])) {
  410. $query->filterByAddress($params['address']);
  411. }
  412. if (isset($params['minimumTomorrowDelivery'])) {
  413. $query->filterMinimumTomorrowDelivery();
  414. }
  415. if (isset($params['mergeComplementaryOrderShops']) && $params['mergeComplementaryOrderShops']) {
  416. $query
  417. ->joinComplementaryOrderShops();
  418. }
  419. if (isset($params['isComplementaryOrderShop']) && $params['isComplementaryOrderShop']) {
  420. $query->filterIsComplementaryOrderShop();
  421. if (isset($params['sectionMainOrderShop']) && $params['sectionMainOrderShop']) {
  422. $query->filterSectionMainOrderShop($params['sectionMainOrderShop']);
  423. }
  424. }
  425. if ((isset($params['excludeComplementaryOrderShops']) && $params['excludeComplementaryOrderShops'])
  426. || (isset($params['mergeComplementaryOrderShops']) && $params['mergeComplementaryOrderShops'])) {
  427. $query->filterIsNullMainOrderShop();
  428. }
  429. if (isset($params['joinProductFamily'])) {
  430. $query->joinProductFamily(true);
  431. }
  432. if (isset($params['orderBy'])) {
  433. $sort = isset($params['orderByDirection']) ? $params['orderByDirection'] : 'DESC';
  434. $query->orderBy($params['orderBy'], $sort);
  435. } else {
  436. $query->orderBy('.id', 'DESC');
  437. }
  438. if (isset($params['groupBy'])) {
  439. $query->groupBy($params['groupBy']);
  440. }
  441. return $query;
  442. }
  443. public function isReductionGiftUsed(ReductionCreditInterface $reductionGift, $query = null)
  444. {
  445. if ($this->countValidWithReductionCredit($reductionGift, null, $query)) {
  446. return true;
  447. } else {
  448. return false;
  449. }
  450. }
  451. public function isReductionCreditUsed(
  452. ReductionCreditInterface $reductionCredit,
  453. UserInterface $user = null,
  454. $query = null
  455. )
  456. {
  457. if ($this->countValidWithReductionCredit($reductionCredit, $user, $query)) {
  458. return true;
  459. } else {
  460. return false;
  461. }
  462. }
  463. public function getReductionCreditsAvailableByUser(UserInterface $user): array
  464. {
  465. $reductionCredits = $this->reductionCreditStore
  466. ->setMerchant($this->merchant)
  467. ->getByTypeAndUser(ReductionCreditModel::TYPE_CREDIT, $user);
  468. $reductionCreditsArray = [];
  469. foreach ($reductionCredits as $reductionCredit) {
  470. if (!$this->countValidWithReductionCredit($reductionCredit, $user)) {
  471. $reductionCreditsArray[] = $reductionCredit;
  472. }
  473. }
  474. return $reductionCreditsArray;
  475. }
  476. public function getReductionGiftsAvailableByUser(UserInterface $user): array
  477. {
  478. $reductionGifts = $this->reductionCreditStore
  479. ->setMerchant($this->merchant)
  480. ->getByTypeAndUser(ReductionCreditModel::TYPE_GIFT, $user);
  481. $reductionGiftsArray = [];
  482. foreach ($reductionGifts as $reductionGift) {
  483. if (!$this->countValidWithReductionCredit($reductionGift, $user)) {
  484. $reductionGiftsArray[] = $reductionGift;
  485. }
  486. }
  487. return $reductionGiftsArray;
  488. }
  489. // getReductionCartRemainingQuantity
  490. public function getReductionCartRemainingQuantity(ReductionCartInterface $reductionCart): float
  491. {
  492. return $reductionCart->getAvailableQuantity() - $this->countValidWithReductionCart(
  493. $reductionCart
  494. );
  495. }
  496. // getReductionCartUsedQuantityPerUser
  497. public function getReductionCartUsedQuantityByUser(
  498. ReductionCartInterface $reductionCart,
  499. UserInterface $user
  500. ): float
  501. {
  502. return $this->countValidWithReductionCartByUser($reductionCart, $user);
  503. }
  504. // getReductionCartUsedQuantity
  505. public function getReductionCartUsedQuantity(ReductionCartInterface $reductionCart): float
  506. {
  507. return $this->countValidWithReductionCart($reductionCart);
  508. }
  509. // getReductionCartRemainingQuantityPerUser
  510. public function getReductionCartRemainingQuantityByUser(
  511. ReductionCartInterface $reductionCart,
  512. UserInterface $user
  513. ): float
  514. {
  515. if ($reductionCart->getAvailableQuantityPerUser()) {
  516. return $reductionCart->getAvailableQuantityPerUser() - $this->countValidWithReductionCartByUser(
  517. $reductionCart,
  518. $user
  519. );
  520. }
  521. return false;
  522. }
  523. // findAllAvailableForUser / getReductionCartsAvailableByUser
  524. public function getReductionCartAvailableByUser(UserInterface $user, string $type = null, $query = null)
  525. {
  526. $reductionCarts = $this->reductionCartStore
  527. ->setMerchant($this->merchant)
  528. ->getOnline();
  529. $reductionCartsArray = [];
  530. foreach ($reductionCarts as $reductionCart) {
  531. if ($this->reductionCartSolver->matchWithUser($reductionCart, $user)
  532. && $this->reductionCartSolver->matchWithGroupUser($reductionCart, $user)
  533. && $this->getReductionCartRemainingQuantityByUser($reductionCart, $user)
  534. && ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)
  535. && (!$this->merchant || $reductionCart->getMerchant() == $this->merchant)) {
  536. if(!$type || $reductionCart->getType() == $type) {
  537. $reductionCartsArray[] = $reductionCart;
  538. }
  539. }
  540. }
  541. return $reductionCartsArray;
  542. }
  543. //countValidOrderProductsOfCyclesByProducts
  544. public function countValidOrderProductsOfDistributionsByProducts(
  545. array $distributions,
  546. array $products,
  547. ProductFamilyInterface $productFamily,
  548. $query = null
  549. ): array
  550. {
  551. $query = $this->createDefaultQuery($query);
  552. $query
  553. ->filterByAlias(OrderStatusModel::$statusAliasAsValid)
  554. ->filterByDistributions($distributions)
  555. ->filterByProducts($products)
  556. ->selectSum()
  557. ->groupBy('distribution.cycleNumber, product.id');
  558. //TODO vérifier ou est utilisé cette fonction ???
  559. return $query->find();
  560. }
  561. //countValidOrderProductsOfCycleByProduct
  562. public function countValidOrderProductsOfDistributionByProduct(
  563. DistributionInterface $distribution,
  564. ProductInterface $product,
  565. $query = null
  566. ): float
  567. {
  568. //TODO attention à vérifier
  569. $query = $this->createQuery($query);
  570. $query
  571. ->filterByAlias(OrderStatusModel::$statusAliasAsValid)
  572. ->filterByDistribution($distribution)
  573. ->filterByProduct($product)
  574. ->selectSumQuantityOrder()
  575. ->joinDistribution()
  576. ->groupBy('distribution.cycleNumber, product.id');
  577. $result = $query->findOne();
  578. if ($result) {
  579. return $result['quantity'];
  580. }
  581. return 0;
  582. }
  583. public function isReductionCreditAllowAddToOrder(
  584. OrderShopInterface $orderShop,
  585. ReductionCreditInterface $reductionCredit
  586. )
  587. {
  588. $user = $orderShop->getUser();
  589. // appartient à l'utilisateur
  590. if (!$reductionCredit->getUsers()->contains($user)) {
  591. // @TODO : déplacer la gestion du flash message
  592. $this->flashBagTranslator->add('error', 'userNotAllow', 'ReductionCredit');
  593. return false;
  594. }
  595. // n'a pas été utilisé
  596. if ($reductionCredit->getType() == ReductionCreditModel::TYPE_CREDIT) {
  597. if ($this->countValidWithReductionCredit($reductionCredit, $user) > 0) {
  598. // @TODO : déplacer la gestion du flash message
  599. $this->flashBagTranslator->add('error', 'alreadyUse', 'ReductionCredit');
  600. return false;
  601. }
  602. } else {
  603. if ($this->countValidWithReductionCredit($reductionCredit) > 0) {
  604. // @TODO : déplacer la gestion du flash message
  605. $this->flashBagTranslator->add('error', 'alreadyUse', 'ReductionCredit');
  606. return false;
  607. }
  608. }
  609. return true;
  610. }
  611. public function getCartAlone($query = null)
  612. {
  613. $query = $this->createQuery($query);
  614. $query->filterByAlias(OrderStatusModel::$statusAliasAsCart);
  615. $query->filterByUserIsNull();
  616. $query->filterByVisitorIsNull();
  617. return $query->limit(10000)->find();
  618. }
  619. }