$builder | $builder | ||||
->add('reductionCredit', EntityType::class, array( | ->add('reductionCredit', EntityType::class, array( | ||||
'class' => $reductionCreditClass->getName(), | 'class' => $reductionCreditClass->getName(), | ||||
'choices' => $reductionCreditRepo->getReductionCreditByUser($entity->getUser()), | |||||
'choices' => $reductionCreditRepo->findReductionCreditsByUser($entity->getUser()), | |||||
//'choices' => $this->orderUtils->getReductionCreditsAvailable($entity), | //'choices' => $this->orderUtils->getReductionCreditsAvailable($entity), | ||||
'required' => true, | 'required' => true, |
namespace Lc\ShopBundle\Repository; | namespace Lc\ShopBundle\Repository; | ||||
use Doctrine\ORM\EntityManager; | |||||
use Lc\ShopBundle\Context\DefaultRepositoryInterface; | use Lc\ShopBundle\Context\DefaultRepositoryInterface; | ||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||||
use Lc\ShopBundle\Context\ReductionCreditInterface; | use Lc\ShopBundle\Context\ReductionCreditInterface; | ||||
/** | /** | ||||
*/ | */ | ||||
class ReductionCreditRepository extends BaseRepository implements DefaultRepositoryInterface | class ReductionCreditRepository extends BaseRepository implements DefaultRepositoryInterface | ||||
{ | { | ||||
public function getInterfaceClass() | public function getInterfaceClass() | ||||
{ | { | ||||
return ReductionCreditInterface::class; | return ReductionCreditInterface::class; | ||||
} | } | ||||
public function getReductionCreditByUser($user){ | |||||
public function findReductionCreditsByUser($user) | |||||
{ | |||||
$query = $this->findByMerchantQuery() ; | $query = $this->findByMerchantQuery() ; | ||||
$query->andWhere('e.status = 1'); | $query->andWhere('e.status = 1'); | ||||
$query->andWhere(':user MEMBER OF e.users'); | $query->andWhere(':user MEMBER OF e.users'); | ||||
$query->setParameter('user', $user); | $query->setParameter('user', $user); | ||||
return $query->getQuery()->getResult() ; | return $query->getQuery()->getResult() ; | ||||
} | } | ||||
} | } |
protected $userUtils; | protected $userUtils; | ||||
protected $merchantUtils; | protected $merchantUtils; | ||||
protected $orderShopRepo; | protected $orderShopRepo; | ||||
protected $reductionCreditRepo ; | |||||
protected $priceUtils; | protected $priceUtils; | ||||
protected $productFamilyUtils; | protected $productFamilyUtils; | ||||
protected $documentUtils; | protected $documentUtils; | ||||
$this->userUtils = $userUtils; | $this->userUtils = $userUtils; | ||||
$this->merchantUtils = $merchantUtils; | $this->merchantUtils = $merchantUtils; | ||||
$this->orderShopRepo = $this->em->getRepository($this->em->getClassMetadata(OrderShopInterface::class)->getName()); | $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->priceUtils = $priceUtils; | ||||
$this->productFamilyUtils = $productFamilyUtils; | $this->productFamilyUtils = $productFamilyUtils; | ||||
$this->documentUtils = $documentUtils; | $this->documentUtils = $documentUtils; | ||||
public function isCartAllowToBeOrder($order){ | public function isCartAllowToBeOrder($order){ | ||||
return true; | 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 ; | |||||
} | |||||
} | } |
return $orderReductionCart; | return $orderReductionCart; | ||||
} | } | ||||
public function isReductionCreditAllowToBeAddToOrder($orderShop, $reductionCredit) | |||||
public function isReductionCreditAllowAddToOrder($orderShop, $reductionCredit) | |||||
{ | { | ||||
if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $orderShop->getUser()) > 0) { | if ($this->orderShopRepo->countValidOrderWithReductionCredit($reductionCredit, $orderShop->getUser()) > 0) { |