|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- <?php
-
- namespace Lc\ShopBundle\Repository;
-
- use Doctrine\ORM\QueryBuilder;
- use Lc\ShopBundle\Context\DefaultRepositoryInterface;
- use Lc\ShopBundle\Context\OrderShopInterface;
-
- /**
- * @method OrderShopInterface|null find($id, $lockMode = null, $lockVersion = null)
- * @method OrderShopInterface|null findOneBy(array $criteria, array $orderBy = null)
- * @method OrderShopInterface[] findAll()
- * @method OrderShopInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
- */
- class OrderShopRepository extends BaseRepository implements DefaultRepositoryInterface
- {
-
- public function getInterfaceClass()
- {
- return OrderShopInterface::class;
- }
-
-
- //TODO : AJOUTER un champ valid ds orderSTATUS
- protected $statusAliasAsValid = array('paid-online', 'paid-by-credit', 'waiting-delivery', 'waiting-delivery-with-payment', 'delivered-without-payment', 'done');
- protected $statusAliasAsCart = array('cart', 'waiting-payment-online', 'waiting-payment-credit', 'waiting-payment-on-delivery', 'error-payment-online');
-
-
- public function countValidOrderWithReductionCredit($reductionCredit, $user){
- $query = $this->findByMerchantQuery();
- $query = $this->filterOrderValid($query);
- $query->select('count(e.id)');
- $query->andWhere('e.user = :user');
- $query->innerJoin('e.orderReductionCredits', 'orc');
- $query->andWhere('orc.reductionCredit = :reductionCredit');
- $query->setParameter('reductionCredit', $reductionCredit);
- $query->setParameter('user', $user);
- return $query->getQuery()->getSingleScalarResult();
- }
-
-
- public function countValidOrderWithReductionCart($reductionCart){
- $query = $this->findByMerchantQuery();
- $query = $this->filterOrderValid($query);
- $query->select('count(e.id)');
- $query->join('e.orderReductionCarts', 'orc');
- $query->andWhere('orc.reductionCart = :reductionCart');
- $query->setParameter('reductionCart', $reductionCart);
- return $query->getQuery()->getSingleScalarResult();
- }
-
-
- public function countValidOrderWithReductionCartPerUser($reductionCart, $user){
- $query = $this->findByMerchantQuery();
- $query = $this->filterOrderValid($query);
- $query->select('count(e.id)');
- $query->andWhere('e.user = :user');
- $query->join('e.orderReductionCarts', 'orc');
- $query->andWhere('orc.reductionCart = :reductionCart');
- $query->setParameter('reductionCart', $reductionCart);
- $query->setParameter('user', $user);
- return $query->getQuery()->getSingleScalarResult();
- }
-
-
- public function filterOrderValid(?QueryBuilder $query) :QueryBuilder {
-
- $query->leftJoin('e.orderStatus', 'os');
- $query->andWhere('os.alias IN (:alias)');
- $query->setParameter('alias', $this->statusAliasAsValid);
-
- return $query;
- }
-
- public function filterOrderCart($query)
- {
- $query->leftJoin('e.orderStatus', 'os');
- $query->andWhere('os.alias IN (:alias)');
- $query->setParameter('alias', $this->statusAliasAsCart);
-
- return $query;
- }
-
- public function findCartCurrent($params)
- {
- $query = $this->findByMerchantQuery() ;
-
-
- if(isset($params['user'])) {
- $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
- }
-
- if(isset($params['visitor'])) {
- $query->andWhere('e.visitor = :visitor')->setParameter('visitor', $params['visitor']) ;
- }
-
- $query = $this->filterOrderCart($query);
-
- $query->leftJoin('e.orderReductionCarts', 'orderReductionCarts')
- ->addSelect('orderReductionCarts');
-
- $results = $query->getQuery()->getResult() ;
-
- if($results) {
- return $results[0] ;
- }
-
- return null ;
- }
-
- public function findAllBy($params = [])
- {
- $query = $this->findByMerchantQuery() ;
-
- if(isset($params['count']) && $params['count']) {
- $query->select('count(e.id)') ;
- }
-
- if(isset($params['dateStart']) || isset($params['dateEnd'])) {
- $params['dateField'] = isset($params['dateField']) ? $params['dateField'] : 'validationDate' ;
- }
-
- if(isset($params['dateStart'])) {
- $query->andWhere('e.'.$params['dateField'].' >= :dateStart')->setParameter('dateStart', $params['dateStart']) ;
- }
- if(isset($params['dateEnd'])) {
- $query->andWhere('e.'.$params['dateField'].' <= :dateEnd')->setParameter('dateEnd', $params['dateEnd']) ;
- }
-
- if(isset($params['isCart'])) {
- $query = $this->filterOrderCart($query) ;
- }
-
- if(isset($params['isValid'])) {
- $query = $this->filterOrderValid($query) ;
- }
-
- if(isset($params['user'])) {
- $query->andWhere('e.user = :user')->setParameter('user', $params['user']) ;
- }
-
- $query->orderBy('e.id', 'DESC') ;
-
- $query->leftJoin('e.deliveryAvailabilityZone', 'deliveryAvailabilityZone') ;
- $query->leftJoin('deliveryAvailabilityZone.deliverySlot', 'deliverySlotZone') ;
- $query->addOrderBy('deliverySlotZone.day', 'ASC') ;
- $query->addOrderBy('deliverySlotZone.timeStart', 'ASC') ;
-
- $query->leftJoin('e.deliveryAvailabilityPointSale', 'deliveryAvailabilityPointSale') ;
- $query->leftJoin('deliveryAvailabilityPointSale.deliverySlot', 'deliverySlotPointSale') ;
- $query->addOrderBy('deliverySlotPointSale.day', 'ASC') ;
- $query->addOrderBy('deliverySlotPointSale.timeStart', 'ASC') ;
-
- if(isset($params['count']) && $params['count']) {
- return $query->getQuery()->getSingleScalarResult();
- }
- else {
- return $query->getQuery()->getResult() ;
- }
- }
- }
|