|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
-
- namespace Lc\ShopBundle\Repository;
-
- use Doctrine\ORM\EntityManager;
- use Lc\ShopBundle\Context\DefaultRepositoryInterface;
- use Lc\ShopBundle\Context\MerchantUtilsInterface;
- use Lc\ShopBundle\Context\OrderUtilsInterface;
- use Lc\ShopBundle\Context\ReductionCartInterface;
-
-
- class ReductionCartRepository extends BaseRepository implements DefaultRepositoryInterface
- {
- protected $orderUtils ;
-
- public function __construct(EntityManager $entityManager, MerchantUtilsInterface $merchantUtils, OrderUtilsInterface $orderUtils)
- {
- parent::__construct($entityManager, $merchantUtils);
- $this->orderUtils = $orderUtils ;
- }
-
- public function getInterfaceClass()
- {
- return ReductionCartInterface::class;
- }
-
- public function findOneByCode($code)
- {
- $query = $this->findByMerchantQuery() ;
- $query->andWhere('e.codes LIKE :code')->setParameter('code', '%'.$code.'%') ;
- return $query->getQuery()->getOneOrNullResult() ;
- }
-
- public function getValuesOfFieldType(){
- $query = $this->findByMerchantQuery() ;
- $query->select('DISTINCT e.type');
- $query->andWhere('e.status = 1');
-
- return $query->getQuery()->getResult() ;
-
- }
-
- public function getValuesOfFieldCode(){
- $query = $this->findByMerchantQuery() ;
- $query->select('DISTINCT e.codes');
- $query->andWhere('e.status = 1');
-
- return $query->getQuery()->getResult() ;
-
- }
-
- public function getEligibleReductionCart($order)
- {
- $query = $this->findByMerchantQuery() ;
- $query->andWhere('e.status = 1');
-
- return $query->getQuery()->getResult();
- }
-
- public function findAllAvailableForUser($user)
- {
- $reductionCarts = $this->findAll() ;
-
- $reductionCartsArray = [] ;
- foreach($reductionCarts as $reductionCart) {
- if($this->orderUtils->isReductionCartMatchWithUser($reductionCart, $user)
- && $this->orderUtils->isReductionCartMatchWithGroupUser($reductionCart, $user)
- && $this->orderUtils->countReductionCartAvailableForUser($reductionCart, $user)) {
-
- $reductionCartsArray[] = $reductionCart ;
- }
- }
-
- return $reductionCartsArray ;
- }
- }
|