瀏覽代碼

UserUtils : setNewsletter

feature/export_comptable
Guillaume 4 年之前
父節點
當前提交
a5fcad5d13
共有 1 個檔案被更改,包括 23 行新增1 行删除
  1. +23
    -1
      ShopBundle/Services/UserUtils.php

+ 23
- 1
ShopBundle/Services/UserUtils.php 查看文件

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

}

Loading…
取消
儲存