Explorar el Código

ReductionCredit

feature/export_comptable
Guillaume hace 4 años
padre
commit
0e473144ee
Se han modificado 4 ficheros con 25 adiciones y 6 borrados
  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 Ver fichero

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

+ 6
- 4
ShopBundle/Repository/ReductionCreditRepository.php Ver fichero

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

}


}

+ 17
- 0
ShopBundle/Services/OrderUtils.php Ver fichero

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

}

+ 1
- 1
ShopBundle/Services/OrderUtilsReductionTrait.php Ver fichero

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

Cargando…
Cancelar
Guardar