|
|
@@ -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,6 +83,7 @@ class CreditUtils |
|
|
|
return $this->updateCreditActive($user, $merchant, false) ; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function isCreditActive(UserInterface $user, MerchantInterface $merchant = null){ |
|
|
|
$userMerchant = $this->getUserMerchant($user, $merchant); |
|
|
|
if($userMerchant && $userMerchant->isCreditActive()) { |
|
|
@@ -84,10 +93,10 @@ class CreditUtils |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public function checkCreditActive(UserMerchantInterface $userMerchant) |
|
|
|
{ |
|
|
|
public function checkCreditActive(UserMerchantInterface $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 ; |