Browse Source

ReductionCredit

feature/export_comptable
Guillaume 4 years ago
parent
commit
0e473144ee
4 changed files with 25 additions and 6 deletions
  1. +1
    -1
      ShopBundle/Form/Backend/Order/OrderReductionCreditType.php
  2. +6
    -4
      ShopBundle/Repository/ReductionCreditRepository.php
  3. +17
    -0
      ShopBundle/Services/OrderUtils.php
  4. +1
    -1
      ShopBundle/Services/OrderUtilsReductionTrait.php

+ 1
- 1
ShopBundle/Form/Backend/Order/OrderReductionCreditType.php View File

$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,

+ 6
- 4
ShopBundle/Repository/ReductionCreditRepository.php View File



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() ;

} }


} }

+ 17
- 0
ShopBundle/Services/OrderUtils.php View File

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 ;
}

} }

+ 1
- 1
ShopBundle/Services/OrderUtilsReductionTrait.php View File

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) {

Loading…
Cancel
Save