@@ -42,7 +42,7 @@ class OrderReductionCreditType extends AbstractType | |||
$builder | |||
->add('reductionCredit', EntityType::class, array( | |||
'class' => $reductionCreditClass->getName(), | |||
'choices' => $reductionCreditRepo->getReductionCreditByUser($entity->getUser()), | |||
'choices' => $reductionCreditRepo->findReductionCreditsByUser($entity->getUser()), | |||
//'choices' => $this->orderUtils->getReductionCreditsAvailable($entity), | |||
'required' => true, |
@@ -2,7 +2,9 @@ | |||
namespace Lc\ShopBundle\Repository; | |||
use Doctrine\ORM\EntityManager; | |||
use Lc\ShopBundle\Context\DefaultRepositoryInterface; | |||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||
use Lc\ShopBundle\Context\ReductionCreditInterface; | |||
/** | |||
@@ -13,19 +15,19 @@ use Lc\ShopBundle\Context\ReductionCreditInterface; | |||
*/ | |||
class ReductionCreditRepository extends BaseRepository implements DefaultRepositoryInterface | |||
{ | |||
public function getInterfaceClass() | |||
{ | |||
return ReductionCreditInterface::class; | |||
} | |||
public function getReductionCreditByUser($user){ | |||
public function findReductionCreditsByUser($user) | |||
{ | |||
$query = $this->findByMerchantQuery() ; | |||
$query->andWhere('e.status = 1'); | |||
$query->andWhere(':user MEMBER OF e.users'); | |||
$query->setParameter('user', $user); | |||
return $query->getQuery()->getResult() ; | |||
} | |||
} |
@@ -34,6 +34,7 @@ class OrderUtils | |||
protected $userUtils; | |||
protected $merchantUtils; | |||
protected $orderShopRepo; | |||
protected $reductionCreditRepo ; | |||
protected $priceUtils; | |||
protected $productFamilyUtils; | |||
protected $documentUtils; | |||
@@ -48,6 +49,7 @@ class OrderUtils | |||
$this->userUtils = $userUtils; | |||
$this->merchantUtils = $merchantUtils; | |||
$this->orderShopRepo = $this->em->getRepository($this->em->getClassMetadata(OrderShopInterface::class)->getName()); | |||
$this->reductionCreditRepo = $this->em->getRepository($this->em->getClassMetadata(ReductionCreditInterface::class)->getName()); | |||
$this->priceUtils = $priceUtils; | |||
$this->productFamilyUtils = $productFamilyUtils; | |||
$this->documentUtils = $documentUtils; | |||
@@ -456,4 +458,19 @@ class OrderUtils | |||
public function isCartAllowToBeOrder($order){ | |||
return true; | |||
} | |||
public function getReductionCreditsAvailableByUser($user) | |||
{ | |||
$reductionCredits = $this->reductionCreditRepo->findReductionCreditsByUser($user) ; | |||
$reductionCreditsArray = [] ; | |||
foreach($reductionCredits as $reductionCredit) { | |||
if(!$this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $user)) { | |||
$reductionCreditsArray[] = $reductionCredit ; | |||
} | |||
} | |||
return $reductionCreditsArray ; | |||
} | |||
} |
@@ -77,7 +77,7 @@ trait OrderUtilsReductionTrait | |||
return $orderReductionCart; | |||
} | |||
public function isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit) | |||
public function isReductionCreditAllowAddToOrder($orderShop, $reductionCredit) | |||
{ | |||
if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $orderShop->getUser()) > 0) { |