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