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.

OrderShopRepository.php 5.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <?php
  2. namespace Lc\ShopBundle\Repository;
  3. use Lc\ShopBundle\Context\DefaultRepositoryInterface;
  4. use Lc\ShopBundle\Context\OrderShopInterface;
  5. /**
  6. * @method OrderShopInterface|null find($id, $lockMode = null, $lockVersion = null)
  7. * @method OrderShopInterface|null findOneBy(array $criteria, array $orderBy = null)
  8. * @method OrderShopInterface[] findAll()
  9. * @method OrderShopInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  10. */
  11. class OrderShopRepository extends BaseRepository implements DefaultRepositoryInterface
  12. {
  13. public function getInterfaceClass()
  14. {
  15. return OrderShopInterface::class;
  16. }
  17. //TODO : AJOUTER un champ valid ds orderSTATUS
  18. protected $statusAliasAsValid = array('paid-online', 'paid-by-credit', 'waiting-delivery', 'waiting-delivery-with-payment', 'delivered-without-payment', 'done');
  19. protected $statusAliasAsCart = array('cart', 'waiting-payment-online', 'waiting-payment-credit', 'waiting-payment-on-delivery', 'error-payment-online');
  20. public function findValidOrderWithReductionCredit($reductionCredit, $user){
  21. $query = $this->findByMerchantQuery();
  22. $query = $this->filterOrderValid($query);
  23. $query->andWhere('e.user = :user');
  24. $query->leftJoin('e.orderReductionCredits', 'orc');
  25. $query->andWhere('orc.reductionCredit = :reductionCredit');
  26. $query->setParameter('reductionCredit', $reductionCredit);
  27. $query->setParameter('user', $user);
  28. return $query->getQuery()->getResult();
  29. }
  30. public function filterOrderValid($query){
  31. $query->leftJoin('e.orderStatus', 'os');
  32. $query->andWhere('os.alias IN (:alias)');
  33. $query->setParameter('alias', $this->statusAliasAsValid);
  34. return $query;
  35. }
  36. public function filterOrderCart($query)
  37. {
  38. $query->leftJoin('e.orderStatus', 'os');
  39. $query->andWhere('os.alias IN (:alias)');
  40. $query->setParameter('alias', $this->statusAliasAsCart);
  41. return $query;
  42. }
  43. public function findCartCurrent($params)
  44. {
  45. $query = $this->findByMerchantQuery() ;
  46. if(isset($params['user'])) {
  47. $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
  48. }
  49. if(isset($params['visitor'])) {
  50. $query->andWhere('e.visitor = :visitor')->setParameter('visitor', $params['visitor']) ;
  51. }
  52. $query = $this->filterOrderCart($query);
  53. $query->leftJoin('e.orderReductionCarts', 'orderReductionCarts')
  54. ->addSelect('orderReductionCarts');
  55. $results = $query->getQuery()->getResult() ;
  56. if($results) {
  57. return $results[0] ;
  58. }
  59. return null ;
  60. }
  61. public function findAllBy($params = [])
  62. {
  63. $query = $this->findByMerchantQuery() ;
  64. if(isset($params['count']) && $params['count']) {
  65. $query->select('count(e.id)') ;
  66. }
  67. if(isset($params['dateStart']) || isset($params['dateEnd'])) {
  68. $params['dateField'] = isset($params['dateField']) ? $params['dateField'] : 'validationDate' ;
  69. }
  70. if(isset($params['dateStart'])) {
  71. $query->andWhere('e.'.$params['dateField'].' >= :dateStart')->setParameter('dateStart', $params['dateStart']) ;
  72. }
  73. if(isset($params['dateEnd'])) {
  74. $query->andWhere('e.'.$params['dateField'].' <= :dateEnd')->setParameter('dateEnd', $params['dateEnd']) ;
  75. }
  76. if(isset($params['isCart'])) {
  77. $query = $this->filterOrderCart($query) ;
  78. }
  79. if(isset($params['isValid'])) {
  80. $query = $this->filterOrderValid($query) ;
  81. }
  82. if(isset($params['user'])) {
  83. $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
  84. }
  85. $query->orderBy('e.id', 'DESC') ;
  86. $query->leftJoin('e.deliveryAvailabilityZone', 'deliveryAvailabilityZone') ;
  87. $query->leftJoin('deliveryAvailabilityZone.deliverySlot', 'deliverySlotZone') ;
  88. $query->addOrderBy('deliverySlotZone.day', 'ASC') ;
  89. $query->addOrderBy('deliverySlotZone.timeStart', 'ASC') ;
  90. $query->leftJoin('e.deliveryAvailabilityPointSale', 'deliveryAvailabilityPointSale') ;
  91. $query->leftJoin('deliveryAvailabilityPointSale.deliverySlot', 'deliverySlotPointSale') ;
  92. $query->addOrderBy('deliverySlotPointSale.day', 'ASC') ;
  93. $query->addOrderBy('deliverySlotPointSale.timeStart', 'ASC') ;
  94. if(isset($params['count']) && $params['count']) {
  95. return $query->getQuery()->getSingleScalarResult();
  96. }
  97. else {
  98. return $query->getQuery()->getResult() ;
  99. }
  100. }
  101. }