<?php | |||||
namespace Lc\ShopBundle\Context; | |||||
interface MerchantUtilsInterface | |||||
{ | |||||
/** | |||||
* Retourne la tva par défaut du merchant courant | |||||
* | |||||
* @return TaxRateInterface | |||||
*/ | |||||
public function getMerchantCurrentTaxRate(); | |||||
} |
use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | use EasyCorp\Bundle\EasyAdminBundle\Event\EasyAdminEvents; | ||||
use FOS\UserBundle\Model\UserManagerInterface; | use FOS\UserBundle\Model\UserManagerInterface; | ||||
use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface; | use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface; | ||||
use Lc\ShopBundle\Context\GlobalParamInterface; | |||||
use Lc\ShopBundle\Context\MerchantInterface; | use Lc\ShopBundle\Context\MerchantInterface; | ||||
use Lc\ShopBundle\Context\SortableInterface; | |||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||||
use Lc\ShopBundle\Context\StatusInterface; | use Lc\ShopBundle\Context\StatusInterface; | ||||
use Lc\ShopBundle\Context\TreeInterface; | use Lc\ShopBundle\Context\TreeInterface; | ||||
use Lc\ShopBundle\Form\AbstractEditPositionType; | use Lc\ShopBundle\Form\AbstractEditPositionType; | ||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType; | use Symfony\Bridge\Doctrine\Form\Type\EntityType; | ||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | use Symfony\Component\Form\Extension\Core\Type\ChoiceType; | ||||
use Symfony\Component\Form\Extension\Core\Type\CollectionType; | use Symfony\Component\Form\Extension\Core\Type\CollectionType; | ||||
use Symfony\Component\Form\Extension\Core\Type\RadioType; | |||||
use Symfony\Component\Form\FormEvent; | use Symfony\Component\Form\FormEvent; | ||||
use Symfony\Component\Form\FormEvents; | use Symfony\Component\Form\FormEvents; | ||||
use Symfony\Component\Security\Core\Security; | use Symfony\Component\Security\Core\Security; | ||||
protected $userManager; | protected $userManager; | ||||
protected $em; | protected $em; | ||||
protected $utils; | protected $utils; | ||||
protected $globalParam ; | |||||
protected $merchantUtils ; | |||||
protected $mailjetTransport ; | protected $mailjetTransport ; | ||||
public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, Utils $utils, | public function __construct(Security $security, UserManagerInterface $userManager, EntityManagerInterface $em, Utils $utils, | ||||
GlobalParamInterface $globalParam, MailjetTransport $mailjetTransport) | |||||
MerchantUtilsInterface $merchantUtils, MailjetTransport $mailjetTransport) | |||||
{ | { | ||||
$this->security = $security; | $this->security = $security; | ||||
$this->userManager = $userManager; | $this->userManager = $userManager; | ||||
$this->em = $em; | $this->em = $em; | ||||
$this->utils = $utils; | $this->utils = $utils; | ||||
$this->globalParam = $globalParam ; | |||||
$this->merchantUtils = $merchantUtils ; | |||||
$this->mailjetTransport = $mailjetTransport ; | $this->mailjetTransport = $mailjetTransport ; | ||||
} | } | ||||
{ | { | ||||
$idNews = $this->request->get('id') ; | $idNews = $this->request->get('id') ; | ||||
$newsletter = $this->globalParam->getCurrentMerchant()->getNewsletter() ; | |||||
$newsletter = $this->merchantUtils->getMerchantCurrent()->getNewsletter() ; | |||||
if($newsletter) { | if($newsletter) { | ||||
$users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findAllByNewsletter($newsletter) ; | $users = $this->em->getRepository($this->em->getClassMetadata(UserInterface::class)->getName())->findAllByNewsletter($newsletter) ; |
namespace Lc\ShopBundle\Controller\Frontend ; | namespace Lc\ShopBundle\Controller\Frontend ; | ||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\ShopBundle\Context\GlobalParamInterface; | |||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; | ||||
class BaseController extends AbstractController | class BaseController extends AbstractController | ||||
{ | { | ||||
protected $em ; | protected $em ; | ||||
protected $globalParam ; | |||||
protected $merchantUtils ; | |||||
public function __construct(EntityManagerInterface $em, GlobalParamInterface $globalParam) | |||||
public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils) | |||||
{ | { | ||||
$this->em = $em ; | $this->em = $em ; | ||||
$this->globalParam = $globalParam ; | |||||
$this->merchantUtils = $merchantUtils ; | |||||
} | } | ||||
} | } |
use App\Form\Frontend\OrderProductsType; | use App\Form\Frontend\OrderProductsType; | ||||
use CKSource\CKFinder\Response\JsonResponse; | use CKSource\CKFinder\Response\JsonResponse; | ||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\ShopBundle\Context\GlobalParamInterface; | |||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||||
use Lc\ShopBundle\Context\ProductFamilyInterface; | use Lc\ShopBundle\Context\ProductFamilyInterface; | ||||
use Symfony\Component\HttpFoundation\Request; | use Symfony\Component\HttpFoundation\Request; | ||||
{ | { | ||||
protected $productFamilyRepository ; | protected $productFamilyRepository ; | ||||
public function __construct(EntityManagerInterface $em, GlobalParamInterface $globalParam) | |||||
public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils) | |||||
{ | { | ||||
parent::__construct($em, $globalParam); | |||||
parent::__construct($em, $merchantUtils); | |||||
$this->productFamilyRepository = $this->em->getRepository($this->em->getClassMetaData(ProductFamilyInterface::class)->getName()) ; | $this->productFamilyRepository = $this->em->getRepository($this->em->getClassMetaData(ProductFamilyInterface::class)->getName()) ; | ||||
} | } | ||||
<?php | <?php | ||||
# src/EventSubscriber/EasyAdminSubscriber.php | |||||
namespace Lc\ShopBundle\EventSubscriber; | namespace Lc\ShopBundle\EventSubscriber; | ||||
use Lc\ShopBundle\Context\FilterMerchantInterface; | use Lc\ShopBundle\Context\FilterMerchantInterface; | ||||
use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface; | use Lc\ShopBundle\Context\FilterMultipleMerchantsInterface; | ||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||||
use Lc\ShopBundle\Context\SortableInterface; | use Lc\ShopBundle\Context\SortableInterface; | ||||
use Lc\ShopBundle\Context\StatusInterface; | use Lc\ShopBundle\Context\StatusInterface; | ||||
use Lc\ShopBundle\Context\TreeInterface; | use Lc\ShopBundle\Context\TreeInterface; | ||||
use Lc\ShopBundle\Services\GlobalParam; | |||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||||
use Symfony\Component\EventDispatcher\GenericEvent; | use Symfony\Component\EventDispatcher\GenericEvent; | ||||
use Symfony\Component\Security\Core\Security; | |||||
class EditEventSubscriber implements EventSubscriberInterface | class EditEventSubscriber implements EventSubscriberInterface | ||||
{ | { | ||||
public $globalParam; | |||||
public $merchantUtils; | |||||
public function __construct(GlobalParam $globalParam) | |||||
public function __construct(MerchantUtilsInterface $merchantUtils) | |||||
{ | { | ||||
$this->globalParam = $globalParam; | |||||
$this->merchantUtils = $merchantUtils; | |||||
} | } | ||||
public static function getSubscribedEvents() | public static function getSubscribedEvents() | ||||
} | } | ||||
private function setMerchantProperty($entity){ | private function setMerchantProperty($entity){ | ||||
$entity->setMerchant($this->globalParam->getCurrentMerchant()); | |||||
$entity->setMerchant($this->merchantUtils->getMerchantCurrent()); | |||||
} | } | ||||
private function setMultipleMerchantProperty($entity){ | private function setMultipleMerchantProperty($entity){ | ||||
if ($entity->getMerchants()->isEmpty()) { | if ($entity->getMerchants()->isEmpty()) { | ||||
$entity->addMerchant($this->globalParam->getCurrentMerchant()); | |||||
$entity->addMerchant($this->merchantUtils->getMerchantCurrent()); | |||||
} | } | ||||
} | } | ||||
use Doctrine\ORM\Mapping as ORM; | use Doctrine\ORM\Mapping as ORM; | ||||
use Gedmo\Mapping\Annotation as Gedmo; | use Gedmo\Mapping\Annotation as Gedmo; | ||||
use Lc\ShopBundle\Context\GlobalParamInterface; | |||||
use Lc\ShopBundle\Context\UserInterface; | use Lc\ShopBundle\Context\UserInterface; | ||||
use Lc\ShopBundle\Services\Utils; | |||||
/** | /** | ||||
* @ORM\MappedSuperclass | * @ORM\MappedSuperclass |
use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface; | use Doctrine\Bundle\DoctrineBundle\Repository\ServiceEntityRepositoryInterface; | ||||
use Doctrine\ORM\EntityManager; | use Doctrine\ORM\EntityManager; | ||||
use Doctrine\ORM\EntityRepository; | use Doctrine\ORM\EntityRepository; | ||||
use Lc\ShopBundle\Context\DefaultRepositoryInterface; | |||||
use Lc\ShopBundle\Context\FilterMerchantInterface; | use Lc\ShopBundle\Context\FilterMerchantInterface; | ||||
use Lc\ShopBundle\Context\GlobalParamInterface; | |||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||||
use Lc\ShopBundle\Context\StatusInterface; | use Lc\ShopBundle\Context\StatusInterface; | ||||
use Symfony\Component\Security\Core\Security; | |||||
class BaseRepository extends EntityRepository implements ServiceEntityRepositoryInterface | class BaseRepository extends EntityRepository implements ServiceEntityRepositoryInterface | ||||
{ | { | ||||
public $globalParam; | |||||
public $merchantUtils; | |||||
/** | /** | ||||
* @param string $entityClass The class name of the entity this repository manages | * @param string $entityClass The class name of the entity this repository manages | ||||
*/ | */ | ||||
public function __construct(EntityManager $entityManager, GlobalParamInterface $globalParam) | |||||
public function __construct(EntityManager $entityManager, MerchantUtilsInterface $merchantUtils) | |||||
{ | { | ||||
$this->globalParam = $globalParam; | |||||
$this->merchantUtils = $merchantUtils; | |||||
parent::__construct($entityManager, $entityManager->getClassMetadata($this->getInterfaceClass())); | parent::__construct($entityManager, $entityManager->getClassMetadata($this->getInterfaceClass())); | ||||
} | } | ||||
{ | { | ||||
return $this->createQueryBuilder('e') | return $this->createQueryBuilder('e') | ||||
->where('e.merchant = :currentMerchant') | ->where('e.merchant = :currentMerchant') | ||||
->setParameter('currentMerchant', $this->globalParam->getCurrentMerchant()->getId()) ; | |||||
->setParameter('currentMerchant', $this->merchantUtils->getMerchantCurrent()->getId()) ; | |||||
} | } | ||||
public function findAll() | public function findAll() | ||||
} | } | ||||
if($entity instanceof FilterMerchantInterface){ | if($entity instanceof FilterMerchantInterface){ | ||||
if (!isset($criteria['merchant'])) $criteria['merchant'] = $this->globalParam->getCurrentMerchant(); | |||||
if (!isset($criteria['merchant'])) $criteria['merchant'] = $this->merchantUtils->getMerchantCurrent(); | |||||
if ($criteria['merchant'] === false) unset($criteria['merchant']); | if ($criteria['merchant'] === false) unset($criteria['merchant']); | ||||
} | } | ||||
} | } | ||||
if($entity instanceof FilterMerchantInterface){ | if($entity instanceof FilterMerchantInterface){ | ||||
if (!isset($criteria['merchant'])) $criteria['merchant'] = $this->globalParam->getCurrentMerchant(); | |||||
if (!isset($criteria['merchant'])) $criteria['merchant'] = $this->merchantUtils->getMerchantCurrent(); | |||||
if ($criteria['merchant'] === false) unset($criteria['merchant']); | if ($criteria['merchant'] === false) unset($criteria['merchant']); | ||||
} | } | ||||
return $this->createQueryBuilder('e') | return $this->createQueryBuilder('e') | ||||
->where(':currentMerchant MEMBER OF e.merchants') | ->where(':currentMerchant MEMBER OF e.merchants') | ||||
->andWhere('e.isPublic = 1') | ->andWhere('e.isPublic = 1') | ||||
->setParameter('currentMerchant', $this->globalParam->getCurrentMerchant()) | |||||
->setParameter('currentMerchant', $this->merchantUtils->getMerchantCurrent()) | |||||
->getQuery() | ->getQuery() | ||||
->getResult() ; | ->getResult() ; | ||||
} | } |
<?php | |||||
namespace Lc\ShopBundle\Services; | |||||
use App\Repository\HubRepository; | |||||
use Lc\ShopBundle\Context\GlobalParamInterface; | |||||
use Lc\ShopBundle\Repository\MerchantRepository; | |||||
use Symfony\Component\Security\Core\Security; | |||||
class GlobalParam | |||||
{ | |||||
protected $security; | |||||
public function __construct(Security $security) | |||||
{ | |||||
$this->security = $security ; | |||||
} | |||||
public function getCurrentMerchant() | |||||
{ | |||||
$user = $this->security->getUser() ; | |||||
if($user && $user->getMerchant()) { | |||||
return $user->getMerchant() ; | |||||
} | |||||
else { | |||||
return false ; | |||||
} | |||||
} | |||||
public function getCurrentMerchantTaxRate() | |||||
{ | |||||
return $this->getCurrentMerchant()->getTaxRate(); | |||||
} | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Services ; | |||||
class MerchantUtils | |||||
{ | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Services ; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||||
use Lc\ShopBundle\Context\TaxRateInterface; | |||||
class TaxRateUtils | |||||
{ | |||||
protected $em ; | |||||
protected $merchantUtils ; | |||||
public function __construct(EntityManagerInterface $em, MerchantUtilsInterface $merchantUtils) | |||||
{ | |||||
$this->em = $em ; | |||||
$this->merchantUtils = $merchantUtils ; | |||||
} | |||||
public function getTaxRatesList() | |||||
{ | |||||
$taxRatesList =array(); | |||||
$taxRates = $this->em->getRepository(TaxRateInterface::class)->findAll(); | |||||
foreach ($taxRates as $taxRate){ | |||||
$taxRatesList[$taxRate->getId()]['title'] = $taxRate->getTitle(); | |||||
$taxRatesList[$taxRate->getId()]['value'] = $taxRate->getValue(); | |||||
} | |||||
$taxRatesList['default']['title'] = $this->merchantUtils->getMerchantCurrentTaxRate()->getTitle(); | |||||
$taxRatesList['default']['value'] = $this->merchantUtils->getMerchantCurrentTaxRate()->getValue(); | |||||
return $taxRatesList; | |||||
} | |||||
} |
<?php | |||||
namespace Lc\ShopBundle\Services ; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Lc\ShopBundle\Context\UnitInterface; | |||||
class UnitUtils | |||||
{ | |||||
protected $em ; | |||||
protected $merchantUtils ; | |||||
public function __construct(EntityManagerInterface $em) | |||||
{ | |||||
$this->em = $em ; | |||||
} | |||||
public function getUnitsList() | |||||
{ | |||||
$unitsList =array(); | |||||
$units = $this->em->getRepository(UnitInterface::class)->findAll(); | |||||
foreach ($units as $unit){ | |||||
$unitsList[$unit->getId()]['unit'] = $unit->getUnit(); | |||||
$unitsList[$unit->getId()]['wordingUnit'] = $unit->getWordingUnit(); | |||||
$unitsList[$unit->getId()]['wording'] = $unit->getWording(); | |||||
$unitsList[$unit->getId()]['wordingShort'] = $unit->getWordingShort(); | |||||
$unitsList[$unit->getId()]['coefficient'] = $unit->getCoefficient(); | |||||
$unitsList[$unit->getId()]['unitReference'] = $unit->getUnitReference()->getId(); | |||||
} | |||||
return $unitsList; | |||||
} | |||||
} | |||||
<?php | |||||
namespace Lc\ShopBundle\Services ; | |||||
use Doctrine\ORM\EntityManagerInterface; | |||||
use Symfony\Component\HttpFoundation\Cookie ; | |||||
use Lc\ShopBundle\Context\VisitorInterface; | |||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | |||||
use Symfony\Component\HttpFoundation\RequestStack; | |||||
class UserUtils | |||||
{ | |||||
protected $parameterBag ; | |||||
protected $em ; | |||||
protected $utils ; | |||||
protected $requestStack ; | |||||
protected $visitorRepository ; | |||||
public function __construct(ParameterBagInterface $parameterBag, EntityManagerInterface $em, Utils $utils, RequestStack $requestStack) | |||||
{ | |||||
$this->em = $em ; | |||||
$this->parameterBag = $parameterBag ; | |||||
$this->utils = $utils ; | |||||
$this->requestStack = $requestStack ; | |||||
$this->visitorRepository = $this->em->getRepository($this->em->getClassMetadata(VisitorInterface::class)->getName()) ; | |||||
} | |||||
public function getCookieNameVisitor() | |||||
{ | |||||
return $this->parameterBag->get('app.cookie_name_visitor') ; | |||||
} | |||||
public function cryptCookie($data) | |||||
{ | |||||
return base64_encode($data); | |||||
} | |||||
public function decryptCookie($data) | |||||
{ | |||||
return base64_decode($data); | |||||
} | |||||
public function setCookieVisitor($response, $cookie) | |||||
{ | |||||
$response->headers->setCookie(Cookie::create($this->getCookieNameVisitor(), $this->cryptCookie($cookie), 0, '/', $this->utils->getCookieDomain())); | |||||
} | |||||
public function getVisitor($cookie) | |||||
{ | |||||
return $this->visitorRepository->findOneBy(['cookie' => $cookie]) ; | |||||
} | |||||
public function getVisitorCurrent() | |||||
{ | |||||
$cookie = $this->requestStack->getCurrentRequest()->cookies->get($this->getCookieNameVisitor()) ; | |||||
return $this->getVisitor($cookie) ; | |||||
} | |||||
public function addVisitor($cookie, $ip) | |||||
{ | |||||
$classVisitor = $this->em->getClassMetadata(VisitorInterface::class)->getName() ; | |||||
$visitor = new $classVisitor ; | |||||
$visitor->setCookie($cookie) ; | |||||
$visitor->setIp($ip) ; | |||||
$visitor->setTotalVisit(1) ; | |||||
$visitor->setLastAccess(new \DateTime()) ; | |||||
$this->em->persist($visitor); | |||||
$this->em->flush() ; | |||||
} | |||||
public function updateVisitor($visitor) | |||||
{ | |||||
$totalVisit = $visitor->getTotalVisit() + 1 ; | |||||
$visitor->setTotalVisit($totalVisit) ; | |||||
$visitor->setLastAccess(new \DateTime()) ; | |||||
$this->em->persist($visitor); | |||||
$this->em->flush() ; | |||||
} | |||||
} |
use Cocur\Slugify\Slugify; | use Cocur\Slugify\Slugify; | ||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||||
use Lc\ShopBundle\Context\PageInterface; | use Lc\ShopBundle\Context\PageInterface; | ||||
use Lc\ShopBundle\Context\TaxRateInterface; | use Lc\ShopBundle\Context\TaxRateInterface; | ||||
use Lc\ShopBundle\Context\UnitInterface; | use Lc\ShopBundle\Context\UnitInterface; | ||||
class Utils | class Utils | ||||
{ | { | ||||
protected $em ; | protected $em ; | ||||
protected $globalParam ; | |||||
/*public function getUnitsListFormatedForType() | |||||
{ | |||||
$choices = [] ; | |||||
foreach ($this->unitsArray as $unit=>$unitInfo){ | |||||
$choices[$unitInfo['wording_unit']] = $unit; | |||||
}; | |||||
return $choices; | |||||
} | |||||
public function getUnitsList() | |||||
{ | |||||
return $this->unitsArray; | |||||
} | |||||
public function getUnitProperty($unit, $property) | |||||
{ | |||||
$unitsArray = $this->getUnitsList() ; | |||||
if(isset($unitsArray[$unit][$property])) { | |||||
return $unitsArray[$unit][$property] ; | |||||
} | |||||
return false ; | |||||
} | |||||
public function getUnitWording($unit, $type = 'wording_short') | |||||
{ | |||||
return $this->getUnitProperty($unit, $type) ; | |||||
} | |||||
public function getUnitRef($unit) | |||||
{ | |||||
return $this->getUnitProperty($unit, 'ref') ; | |||||
} | |||||
public function getUnitCoefficient($unit) | |||||
{ | |||||
return $this->getUnitProperty($unit, 'coefficient') ; | |||||
}*/ | |||||
public function __construct(EntityManagerInterface $em, GlobalParam $globalParam) | |||||
public function __construct(EntityManagerInterface $em) | |||||
{ | { | ||||
$this->em = $em ; | $this->em = $em ; | ||||
$this->globalParam = $globalParam; | |||||
} | |||||
public function getUnitsList() | |||||
{ | |||||
$unitsList =array(); | |||||
$units = $this->em->getRepository(UnitInterface::class)->findAll(); | |||||
foreach ($units as $unit){ | |||||
$unitsList[$unit->getId()]['unit'] = $unit->getUnit(); | |||||
$unitsList[$unit->getId()]['wordingUnit'] = $unit->getWordingUnit(); | |||||
$unitsList[$unit->getId()]['wording'] = $unit->getWording(); | |||||
$unitsList[$unit->getId()]['wordingShort'] = $unit->getWordingShort(); | |||||
$unitsList[$unit->getId()]['coefficient'] = $unit->getCoefficient(); | |||||
$unitsList[$unit->getId()]['unitReference'] = $unit->getUnitReference()->getId(); | |||||
} | |||||
return $unitsList; | |||||
} | |||||
public function getTaxRatesList() | |||||
{ | |||||
$taxRatesList =array(); | |||||
$taxRates = $this->em->getRepository(TaxRateInterface::class)->findAll(); | |||||
foreach ($taxRates as $taxRate){ | |||||
$taxRatesList[$taxRate->getId()]['title'] = $taxRate->getTitle(); | |||||
$taxRatesList[$taxRate->getId()]['value'] = $taxRate->getValue(); | |||||
} | |||||
$taxRatesList['default']['title'] = $this->globalParam->getCurrentMerchantTaxRate()->getTitle(); | |||||
$taxRatesList['default']['value'] = $this->globalParam->getCurrentMerchantTaxRate()->getValue(); | |||||
return $taxRatesList; | |||||
} | } | ||||
public static function getDayByNumber($number, $lang = 'fr') | public static function getDayByNumber($number, $lang = 'fr') | ||||
return in_array($_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']) ; | return in_array($_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']) ; | ||||
} | } | ||||
public function getCookieDomain() | |||||
{ | |||||
return ($this->isServerLocalhost()) ? null : $this->parameterBag->get('app.cookie_domain_distant') ; | |||||
} | |||||
function limitText($text, $limit) { | function limitText($text, $limit) { | ||||
if (str_word_count($text, 0) > $limit) { | if (str_word_count($text, 0) > $limit) { | ||||
$words = str_word_count($text, 2); | $words = str_word_count($text, 2); | ||||
return $text; | return $text; | ||||
} | } | ||||
public function isBot() | |||||
{ | |||||
if (isset($_SERVER['HTTP_USER_AGENT']) && preg_match('/bot|crawl|slurp|spider/i', $_SERVER['HTTP_USER_AGENT'])) { | |||||
return TRUE; | |||||
} else { | |||||
return FALSE; | |||||
} | |||||
} | |||||
public function slugify($string) | public function slugify($string) | ||||
{ | { | ||||
$slugify = new Slugify(); | $slugify = new Slugify(); |
use Lc\ShopBundle\Context\PageInterface; | use Lc\ShopBundle\Context\PageInterface; | ||||
use Lc\ShopBundle\Form\Frontend\NewsletterType; | use Lc\ShopBundle\Form\Frontend\NewsletterType; | ||||
use Lc\ShopBundle\Services\TaxRateUtils; | |||||
use Lc\ShopBundle\Services\UnitUtils; | |||||
use Lc\ShopBundle\Services\Utils; | use Lc\ShopBundle\Services\Utils; | ||||
use Twig\Extension\AbstractExtension; | use Twig\Extension\AbstractExtension; | ||||
use Twig\TwigFilter; | use Twig\TwigFilter; | ||||
class BridgeTwigExtension extends AbstractExtension | class BridgeTwigExtension extends AbstractExtension | ||||
{ | { | ||||
private $utils ; | private $utils ; | ||||
private $taxRateUtils ; | |||||
private $unitUtils ; | |||||
public function __construct(Utils $utils) | |||||
public function __construct(Utils $utils, TaxRateUtils $taxRateUtils, UnitUtils $unitUtils) | |||||
{ | { | ||||
$this->utils = $utils ; | $this->utils = $utils ; | ||||
$this->taxRateUtils = $taxRateUtils ; | |||||
$this->unitUtils = $unitUtils ; | |||||
} | } | ||||
public function getFunctions() | public function getFunctions() | ||||
public function getUnitsList() | public function getUnitsList() | ||||
{ | { | ||||
return $this->utils->getUnitsList() ; | |||||
return $this->unitUtils->getUnitsList() ; | |||||
} | } | ||||
public function getTaxRatesList() | public function getTaxRatesList() | ||||
{ | { | ||||
return $this->utils->getTaxRatesList() ; | |||||
return $this->taxRateUtils->getTaxRatesList() ; | |||||
} | } | ||||
public function getElementByDevAlias($devAlias, $class = PageInterface::class) | public function getElementByDevAlias($devAlias, $class = PageInterface::class) |
namespace Lc\ShopBundle\Twig; | namespace Lc\ShopBundle\Twig; | ||||
use App\Repository\HubRepository; | |||||
use App\Services\GlobalParam; | |||||
use Doctrine\ORM\EntityManagerInterface; | use Doctrine\ORM\EntityManagerInterface; | ||||
use Lc\ShopBundle\Context\GlobalParamInterface; | |||||
use Lc\ShopBundle\Context\MerchantInterface; | use Lc\ShopBundle\Context\MerchantInterface; | ||||
use Lc\ShopBundle\Context\MerchantUtilsInterface; | |||||
use Lc\ShopBundle\Context\ProductCategoryInterface; | use Lc\ShopBundle\Context\ProductCategoryInterface; | ||||
use Lc\ShopBundle\Context\ProductFamilyInterface; | use Lc\ShopBundle\Context\ProductFamilyInterface; | ||||
use Lc\ShopBundle\Form\Frontend\NewsletterType; | use Lc\ShopBundle\Form\Frontend\NewsletterType; | ||||
use Lc\ShopBundle\Repository\ProductCategoryRepository; | |||||
use Liip\ImagineBundle\Imagine\Cache\CacheManager; | use Liip\ImagineBundle\Imagine\Cache\CacheManager; | ||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||||
use Symfony\Component\Form\FormFactoryInterface; | use Symfony\Component\Form\FormFactoryInterface; | ||||
{ | { | ||||
protected $em ; | protected $em ; | ||||
protected $security ; | protected $security ; | ||||
protected $globalParam ; | |||||
protected $merchantUtils ; | |||||
protected $formFactory ; | protected $formFactory ; | ||||
protected $requestStack ; | protected $requestStack ; | ||||
protected $productCategoryRepository ; | protected $productCategoryRepository ; | ||||
protected $liipCacheHelper ; | protected $liipCacheHelper ; | ||||
protected $parameterBag ; | protected $parameterBag ; | ||||
public function __construct(EntityManagerInterface $em, Security $security, GlobalParamInterface $globalParam, | |||||
public function __construct(EntityManagerInterface $em, Security $security, MerchantUtilsInterface $merchantUtils, | |||||
FormFactoryInterface $formFactory, RequestStack $requestStack, CacheManager $liipCacheHelper, | FormFactoryInterface $formFactory, RequestStack $requestStack, CacheManager $liipCacheHelper, | ||||
ParameterBagInterface $parameterBag) | ParameterBagInterface $parameterBag) | ||||
{ | { | ||||
$this->em = $em ; | $this->em = $em ; | ||||
$this->security = $security ; | $this->security = $security ; | ||||
$this->globalParam = $globalParam ; | |||||
$this->merchantUtils = $merchantUtils ; | |||||
$this->formFactory = $formFactory ; | $this->formFactory = $formFactory ; | ||||
$this->requestStack = $requestStack ; | $this->requestStack = $requestStack ; | ||||
$this->productCategoryRepository = $this->em->getRepository($this->em->getClassMetadata(ProductCategoryInterface::class)->getName()) ; | $this->productCategoryRepository = $this->em->getRepository($this->em->getClassMetadata(ProductCategoryInterface::class)->getName()) ; | ||||
public function getProductCategories() | public function getProductCategories() | ||||
{ | { | ||||
$categories = $this->productCategoryRepository->findAllParents($this->globalParam->getCurrentMerchant()) ; | |||||
$categories = $this->productCategoryRepository->findAllParents($this->merchantUtils->getMerchantCurrent()) ; | |||||
return $categories ; | return $categories ; | ||||
} | } | ||||