Procházet zdrojové kódy

UserUtils : setNewsletter

feature/export_comptable
Guillaume před 4 roky
rodič
revize
a5fcad5d13
1 změnil soubory, kde provedl 23 přidání a 1 odebrání
  1. +23
    -1
      ShopBundle/Services/UserUtils.php

+ 23
- 1
ShopBundle/Services/UserUtils.php Zobrazit soubor

@@ -3,6 +3,7 @@
namespace Lc\ShopBundle\Services ;

use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Symfony\Component\HttpFoundation\Cookie ;
use Lc\ShopBundle\Context\VisitorInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
@@ -15,14 +16,17 @@ class UserUtils
protected $utils ;
protected $requestStack ;
protected $visitorRepository ;
protected $merchantUtils ;

public function __construct(ParameterBagInterface $parameterBag, EntityManagerInterface $em, Utils $utils, RequestStack $requestStack)
public function __construct(ParameterBagInterface $parameterBag, EntityManagerInterface $em, Utils $utils,
RequestStack $requestStack, MerchantUtilsInterface $merchantUtils)
{
$this->em = $em ;
$this->parameterBag = $parameterBag ;
$this->utils = $utils ;
$this->requestStack = $requestStack ;
$this->visitorRepository = $this->em->getRepository($this->em->getClassMetadata(VisitorInterface::class)->getName()) ;
$this->merchantUtils = $merchantUtils ;
}

public function getCookieNameVisitor()
@@ -80,4 +84,22 @@ class UserUtils
$this->em->flush() ;
}

public function setNewsletter($user, $subscribeNewsletter)
{
$currentMerchant = $this->merchantUtils->getMerchantCurrent() ;
$newsletters = $currentMerchant->getNewsletters() ;

if(isset($newsletters[0]) && $newsletters[0]) {
if($subscribeNewsletter) {
$user->addNewsletter($newsletters[0]) ;
}
else {
$user->removeNewsletter($newsletters[0]) ;
}
}

$this->em->persist($user) ;
$this->em->flush() ;
}

}

Načítá se…
Zrušit
Uložit