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.

82 lines
2.9KB

  1. <?php
  2. namespace Lc\ShopBundle\Repository;
  3. use Doctrine\ORM\EntityManager;
  4. use Lc\ShopBundle\Context\DefaultRepositoryInterface;
  5. use Lc\ShopBundle\Context\MerchantUtilsInterface;
  6. use Lc\ShopBundle\Context\OrderUtilsInterface;
  7. use Lc\ShopBundle\Context\ReductionCartInterface;
  8. /**
  9. * @method ReductionCartInterface|null find($id, $lockMode = null, $lockVersion = null)
  10. * @method ReductionCartInterface|null findOneBy(array $criteria, array $orderBy = null)
  11. * @method ReductionCartInterface[] findAll()
  12. * @method ReductionCartInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
  13. */
  14. class ReductionCartRepository extends BaseRepository implements DefaultRepositoryInterface
  15. {
  16. protected $orderUtils ;
  17. public function __construct(EntityManager $entityManager, MerchantUtilsInterface $merchantUtils, OrderUtilsInterface $orderUtils)
  18. {
  19. parent::__construct($entityManager, $merchantUtils);
  20. $this->orderUtils = $orderUtils ;
  21. }
  22. public function getInterfaceClass()
  23. {
  24. return ReductionCartInterface::class;
  25. }
  26. public function findByCode($code)
  27. {
  28. $query = $this->findByMerchantQuery() ;
  29. $query->andWhere('e.codes LIKE :code')->setParameter('code', '%'.$code.'%') ;
  30. return $query->getQuery()->getResult() ;
  31. }
  32. public function getValuesOfFieldType(){
  33. $query = $this->findByMerchantQuery() ;
  34. $query->select('DISTINCT e.type');
  35. $query->andWhere('e.status = 1');
  36. return $query->getQuery()->getResult() ;
  37. }
  38. public function getValuesOfFieldCode(){
  39. $query = $this->findByMerchantQuery() ;
  40. $query->select('DISTINCT e.codes');
  41. $query->andWhere('e.status = 1');
  42. return $query->getQuery()->getResult() ;
  43. }
  44. public function getOnlineReductionCart()
  45. {
  46. $query = $this->findByMerchantQuery() ;
  47. $query->andWhere('e.status = 1');
  48. return $query->getQuery()->getResult();
  49. }
  50. public function findAllAvailableForUser($user)
  51. {
  52. $reductionCarts = $this->findAll() ;
  53. $reductionCartsArray = [] ;
  54. foreach($reductionCarts as $reductionCart) {
  55. if($this->orderUtils->isReductionCartMatchWithUser($reductionCart, $user)
  56. && $this->orderUtils->isReductionCartMatchWithGroupUser($reductionCart, $user)
  57. && $this->orderUtils->countReductionCartAvailableForUser($reductionCart, $user)) {
  58. $reductionCartsArray[] = $reductionCart ;
  59. }
  60. }
  61. return $reductionCartsArray ;
  62. }
  63. }