|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?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;
- use Lc\ShopBundle\Services\Utils;
-
- /**
- * @method ReductionCartInterface|null find($id, $lockMode = null, $lockVersion = null)
- * @method ReductionCartInterface|null findOneBy(array $criteria, array $orderBy = null)
- * @method ReductionCartInterface[] findAll()
- * @method ReductionCartInterface[] findBy(array $criteria, array $orderBy = null, $limit = null, $offset = null)
- */
- class ReductionCartRepository extends BaseRepository implements DefaultRepositoryInterface
- {
- protected $orderUtils ;
-
- public function __construct(EntityManager $entityManager, MerchantUtilsInterface $merchantUtils, Utils $utils, OrderUtilsInterface $orderUtils)
- {
- parent::__construct($entityManager, $merchantUtils, $utils);
- $this->orderUtils = $orderUtils ;
- }
-
- public function getInterfaceClass()
- {
- return ReductionCartInterface::class;
- }
-
- public function findByCode($code)
- {
- $query = $this->findByMerchantQuery() ;
- $query->andWhere('e.codes LIKE :code')->setParameter('code', '%'.$code.'%') ;
- return $query->getQuery()->getResult() ;
- }
-
- 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 getOnlineReductionCart()
- {
- $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)
- && ($reductionCart->getUsers()->count() > 0 || $reductionCart->getGroupUsers()->count() > 0)) {
-
- $reductionCartsArray[] = $reductionCart ;
- }
- }
-
- return $reductionCartsArray ;
- }
- }
|