Browse Source

UserUtils : setNewsletter

feature/export_comptable
Guillaume 4 years ago
parent
commit
a5fcad5d13
1 changed files with 23 additions and 1 deletions
  1. +23
    -1
      ShopBundle/Services/UserUtils.php

+ 23
- 1
ShopBundle/Services/UserUtils.php View File

namespace Lc\ShopBundle\Services ; namespace Lc\ShopBundle\Services ;


use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Context\MerchantUtilsInterface;
use Symfony\Component\HttpFoundation\Cookie ; use Symfony\Component\HttpFoundation\Cookie ;
use Lc\ShopBundle\Context\VisitorInterface; use Lc\ShopBundle\Context\VisitorInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
protected $utils ; protected $utils ;
protected $requestStack ; protected $requestStack ;
protected $visitorRepository ; 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->em = $em ;
$this->parameterBag = $parameterBag ; $this->parameterBag = $parameterBag ;
$this->utils = $utils ; $this->utils = $utils ;
$this->requestStack = $requestStack ; $this->requestStack = $requestStack ;
$this->visitorRepository = $this->em->getRepository($this->em->getClassMetadata(VisitorInterface::class)->getName()) ; $this->visitorRepository = $this->em->getRepository($this->em->getClassMetadata(VisitorInterface::class)->getName()) ;
$this->merchantUtils = $merchantUtils ;
} }


public function getCookieNameVisitor() public function getCookieNameVisitor()
$this->em->flush() ; $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() ;
}

} }

Loading…
Cancel
Save