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.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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['dateStart']) || isset($params['dateEnd'])) {
  65. $params['dateField'] = isset($params['dateField']) ? $params['dateField'] : 'validationDate' ;
  66. }
  67. if(isset($params['dateStart'])) {
  68. $query->andWhere('e.'.$params['dateField'].' >= :dateStart')->setParameter('dateStart', $params['dateStart']) ;
  69. }
  70. if(isset($params['dateEnd'])) {
  71. $query->andWhere('e.'.$params['dateField'].' <= :dateEnd')->setParameter('dateEnd', $params['dateEnd']) ;
  72. }
  73. if(isset($params['isCart'])) {
  74. $query = $this->filterOrderCart($query) ;
  75. }
  76. if(isset($params['isValid'])) {
  77. $query = $this->filterOrderValid($query) ;
  78. }
  79. if(isset($params['user'])) {
  80. $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
  81. }
  82. $query->orderBy('e.id', 'DESC') ;
  83. $query->leftJoin('e.deliveryAvailabilityZone', 'deliveryAvailabilityZone') ;
  84. $query->leftJoin('deliveryAvailabilityZone.deliverySlot', 'deliverySlotZone') ;
  85. $query->addOrderBy('deliverySlotZone.day', 'ASC') ;
  86. $query->addOrderBy('deliverySlotZone.timeStart', 'ASC') ;
  87. $query->leftJoin('e.deliveryAvailabilityPointSale', 'deliveryAvailabilityPointSale') ;
  88. $query->leftJoin('deliveryAvailabilityPointSale.deliverySlot', 'deliverySlotPointSale') ;
  89. $query->addOrderBy('deliverySlotPointSale.day', 'ASC') ;
  90. $query->addOrderBy('deliverySlotPointSale.timeStart', 'ASC') ;
  91. return $query->getQuery()->getResult() ;
  92. }
  93. }