Parcourir la source

CreditUtils

feature/export_comptable
Guillaume il y a 4 ans
Parent
révision
4804c56b69
1 fichiers modifiés avec 12 ajouts et 4 suppressions
  1. +12
    -4
      ShopBundle/Services/CreditUtils.php

+ 12
- 4
ShopBundle/Services/CreditUtils.php Voir le fichier

@@ -9,23 +9,31 @@ use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Lc\ShopBundle\Context\UserInterface;
use Lc\ShopBundle\Context\UserMerchantInterface;
use Lc\ShopBundle\Model\CreditHistory;
use Symfony\Component\Security\Core\Security;

class CreditUtils
{
protected $em ;
protected $security ;
protected $merchantUtils ;
protected $userMerchantRepository ;

public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils)
public function __construct(EntityManagerInterface $em, Security $security, MerchantUtilsInterface $merchantUtils)
{
$this->em = $em ;
$this->security = $security ;
$this->merchantUtils = $merchantUtils ;
$this->userMerchantRepository = $this->em->getRepository($this->em->getClassMetadata(UserMerchantInterface::class)->getName()) ;
}

public function getUserMerchant(UserInterface $user, MerchantInterface $merchant = null)
public function getUserMerchant(UserInterface $user = null, MerchantInterface $merchant = null)
{
if(!$user) {
$user = $this->security->getUser() ;
}

$merchant = $this->getMerchant($merchant) ;

$userMerchant = $this->userMerchantRepository->findOneBy([
'user' => $user,
'merchant' => $merchant
@@ -75,10 +83,10 @@ class CreditUtils
return $this->updateCreditActive($user, $merchant, false) ;
}

public function checkCreditActive(UserMerchantInterface $userMerchant)
public function checkCreditActive($userMerchant)
{
if(!$userMerchant || ($userMerchant && !$userMerchant->isCreditActive())) {
throw new \ErrorException("L'utilisateur n'a pas de compte prépayé activé pour ce marchand.") ;
return false ;
}

return true ;

Chargement…
Annuler
Enregistrer