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.

84 lines
3.0KB

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