@@ -5,6 +5,7 @@ namespace Lc\ShopBundle\Repository; | |||
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface; | |||
use Doctrine\ORM\EntityManager; | |||
use Doctrine\ORM\EntityRepository; | |||
use Doctrine\ORM\QueryBuilder; | |||
use Lc\ShopBundle\Context\FilterMerchantInterface; | |||
use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface; | |||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||
@@ -24,7 +25,7 @@ class BaseRepository extends EntityRepository implements ServiceEntityRepository | |||
} | |||
public function findByMerchantQuery() | |||
public function findByMerchantQuery() :QueryBuilder | |||
{ | |||
return $this->createQueryBuilder('e') | |||
->where('e.merchant = :currentMerchant') |
@@ -2,6 +2,7 @@ | |||
namespace Lc\ShopBundle\Repository; | |||
use Doctrine\ORM\QueryBuilder; | |||
use Lc\ShopBundle\Context\DefaultRepositoryInterface; | |||
use Lc\ShopBundle\Context\OrderShopInterface; | |||
@@ -30,7 +31,7 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt | |||
$query = $this->filterOrderValid($query); | |||
$query->select('count(e.id)'); | |||
$query->andWhere('e.user = :user'); | |||
$query->leftJoin('e.orderReductionCredits', 'orc'); | |||
$query->join('e.orderReductionCredits', 'orc'); | |||
$query->andWhere('orc.reductionCredit = :reductionCredit'); | |||
$query->setParameter('reductionCredit', $reductionCredit); | |||
$query->setParameter('user', $user); | |||
@@ -42,7 +43,7 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt | |||
$query = $this->findByMerchantQuery(); | |||
$query = $this->filterOrderValid($query); | |||
$query->select('count(e.id)'); | |||
$query->leftJoin('e.orderReductionCart', 'orc'); | |||
$query->join('e.orderReductionCart', 'orc'); | |||
$query->andWhere('orc.reductionCart = :reductionCart'); | |||
$query->setParameter('reductionCart', $reductionCart); | |||
return $query->getQuery()->getSingleScalarResult(); | |||
@@ -54,7 +55,7 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt | |||
$query = $this->filterOrderValid($query); | |||
$query->select('count(e.id)'); | |||
$query->andWhere('e.user = :user'); | |||
$query->leftJoin('e.orderReductionCart', 'orc'); | |||
$query->join('e.orderReductionCart', 'orc'); | |||
$query->andWhere('orc.reductionCart = :reductionCart'); | |||
$query->setParameter('reductionCart', $reductionCart); | |||
$query->setParameter('user', $user); | |||
@@ -62,7 +63,7 @@ class OrderShopRepository extends BaseRepository implements DefaultRepositoryInt | |||
} | |||
public function filterOrderValid($query){ | |||
public function filterOrderValid(?QueryBuilder $query) :QueryBuilder { | |||
$query->leftJoin('e.orderStatus', 'os'); | |||
$query->andWhere('os.alias IN (:alias)'); |
@@ -20,6 +20,7 @@ use Lc\ShopBundle\Context\ReductionCreditInterface; | |||
use Lc\ShopBundle\Context\UserInterface; | |||
use Lc\ShopBundle\Model\Document; | |||
use Lc\ShopBundle\Form\Backend\Order\OrderReductionCreditType; | |||
use Lc\ShopBundle\Model\ReductionCart; | |||
use Symfony\Component\HttpFoundation\Session\SessionInterface; | |||
use Symfony\Component\Security\Core\Security; | |||
@@ -27,12 +28,12 @@ trait OrderUtilsReductionTrait | |||
{ | |||
public function compareOrderProductReductionCatalog($orderProductReductionCatalog1, $orderProductReductionCatalog2) | |||
{ | |||
return (!$orderProductReductionCatalog1 && !$orderProductReductionCatalog2) | |||
return (!$orderProductReductionCatalog1 && !$orderProductReductionCatalog2) | |||
|| ($orderProductReductionCatalog1 | |||
&& $orderProductReductionCatalog2 | |||
&& $orderProductReductionCatalog1->getUnit() == $orderProductReductionCatalog2->getUnit() | |||
&& (string) $orderProductReductionCatalog1->getValue() == (string) $orderProductReductionCatalog2->getValue() | |||
&& $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate()) ; | |||
&& (string)$orderProductReductionCatalog1->getValue() == (string)$orderProductReductionCatalog2->getValue() | |||
&& $orderProductReductionCatalog1->getBehaviorTaxRate() == $orderProductReductionCatalog2->getBehaviorTaxRate()); | |||
} | |||
@@ -70,21 +71,33 @@ trait OrderUtilsReductionTrait | |||
$orderReductionCart->setAppliedTo($reductionCart->getAppliedTo()); | |||
$orderReductionCart->setType($reductionCart->getType()); | |||
$this->em->persist($orderReductionCart) ; | |||
$this->em->flush() ; | |||
$this->em->persist($orderReductionCart); | |||
$this->em->flush(); | |||
return $orderReductionCart; | |||
} | |||
public function isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit){ | |||
public function isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit) | |||
{ | |||
if($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $orderShop->getUser())>0){ | |||
if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $orderShop->getUser()) > 0) { | |||
return false; | |||
}else{ | |||
} else { | |||
return true; | |||
} | |||
} | |||
public function getReductionCartRemainingQuantity($reductionCart) :float | |||
{ | |||
return $reductionCart->getAvailableQuantity() - $this->orderShopRepo->countValidOrderWithReductionCart(); | |||
} | |||
public function getReductionCartRemainingQuantityPerUser($reductionCart) :float | |||
{ | |||
return $reductionCart->getAvailableQuantityPerUser() - $this->orderShopRepo->countValidOrderWithReductionCartPerUser(); | |||
} | |||
public function createOrderReductionCredit(OrderShopInterface $orderShop, ReductionCreditInterface $reductionCredit) | |||
{ | |||
$orderReductionCreditClass = $this->em->getClassMetadata(OrderReductionCreditInterface::class); | |||
@@ -112,5 +125,4 @@ trait OrderUtilsReductionTrait | |||
}*/ | |||
} |