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.

131 lines
5.0KB

  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. public function getValidOrderWithReductionCredit($reductionCredit, $user){
  20. $query = $this->findValidOrderQuery();
  21. $query->andWhere('e.user = :user');
  22. $query->leftJoin('e.orderReductionCredits', 'orc');
  23. $query->andWhere('orc.reductionCredit = :reductionCredit');
  24. $query->setParameter('reductionCredit', $reductionCredit);
  25. $query->setParameter('user', $user);
  26. return $query->getQuery()->getResult();
  27. }
  28. public function findValidOrderQuery(){
  29. $query = $this->findByMerchantQuery();
  30. $query->leftJoin('e.orderStatus', 'os');
  31. $query->andWhere('os.alias IN (:alias)');
  32. $query->setParameter('alias', $this->statusAliasAsValid);
  33. return $query;
  34. }
  35. public function findCartCurrent($params)
  36. {
  37. $query = $this->findByMerchantQuery() ;
  38. if(isset($params['user'])) {
  39. $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
  40. }
  41. if(isset($params['visitor'])) {
  42. $query->andWhere('e.visitor = :visitor')->setParameter('visitor', $params['visitor']) ;
  43. }
  44. $this->filterOrderCart($query, true) ;
  45. $query->leftJoin('e.orderReductionCarts', 'orderReductionCarts')
  46. ->addSelect('orderReductionCarts');
  47. $results = $query->getQuery()->getResult() ;
  48. if($results) {
  49. return $results[0] ;
  50. }
  51. return null ;
  52. }
  53. public function findAllBy($params = [])
  54. {
  55. $query = $this->findByMerchantQuery() ;
  56. if(isset($params['dateStart'])) {
  57. $query->andWhere('e.createdAt >= :dateStart')->setParameter('dateStart', $params['dateStart']) ;
  58. }
  59. if(isset($params['dateEnd'])) {
  60. $query->andWhere('e.createdAt <= :dateEnd')->setParameter('dateEnd', $params['dateEnd']) ;
  61. }
  62. if(!isset($params['isCart'])) {
  63. $this->filterOrderCart($query) ;
  64. }
  65. if(isset($params['user'])) {
  66. $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
  67. }
  68. $query->orderBy('e.id', 'DESC') ;
  69. return $query->getQuery()->getResult() ;
  70. }
  71. public function findAllByDateStartEnd($dateStart, $dateEnd)
  72. {
  73. $query = $this->findByMerchantQuery()
  74. ->andWhere('e.createdAt >= :dateStart')
  75. ->setParameter('dateStart', $dateStart)
  76. ->andWhere('e.createdAt <= :dateEnd')
  77. ->setParameter('dateEnd', $dateEnd);
  78. $this->filterOrderCart($query) ;
  79. $query->leftJoin('e.deliveryAvailabilityZone', 'deliveryAvailabilityZone') ;
  80. $query->leftJoin('deliveryAvailabilityZone.deliverySlot', 'deliverySlotZone') ;
  81. $query->addOrderBy('deliverySlotZone.day', 'ASC') ;
  82. $query->addOrderBy('deliverySlotZone.timeStart', 'ASC') ;
  83. $query->leftJoin('e.deliveryAvailabilityPointSale', 'deliveryAvailabilityPointSale') ;
  84. $query->leftJoin('deliveryAvailabilityPointSale.deliverySlot', 'deliverySlotPointSale') ;
  85. $query->addOrderBy('deliverySlotPointSale.day', 'ASC') ;
  86. $query->addOrderBy('deliverySlotPointSale.timeStart', 'ASC') ;
  87. return $query->getQuery()->getResult() ;
  88. }
  89. public function filterOrderCart($query, $isCart = false)
  90. {
  91. $operator = $isCart ? '=' : '!=' ;
  92. return $query->leftJoin('e.orderStatus', 'orderStatus')
  93. ->andWhere('orderStatus.alias '.$operator.' :orderStatus')
  94. ->setParameter('orderStatus', 'cart');
  95. }
  96. //getValidOrders()
  97. }