Browse Source

Frontend : switch merchant

reduction
Guillaume 4 years ago
parent
commit
6e26cdc111
3 changed files with 22 additions and 8 deletions
  1. +1
    -1
      ShopBundle/Controller/Admin/MerchantController.php
  2. +5
    -0
      ShopBundle/Services/Utils.php
  3. +16
    -7
      ShopBundle/Twig/FrontendTwigExtension.php

+ 1
- 1
ShopBundle/Controller/Admin/MerchantController.php View File

$newMerchantConfig = new $classMerchantConfig ; $newMerchantConfig = new $classMerchantConfig ;
$newMerchantConfig $newMerchantConfig
->setName($key) ->setName($key)
->setMerchant($this->security->getUser()->getMerchant()) ;
->setMerchant($entity) ;
if(isset($option['default'])) { if(isset($option['default'])) {
$newMerchantConfig->setValue($option['default']) ; $newMerchantConfig->setValue($option['default']) ;
} }

+ 5
- 0
ShopBundle/Services/Utils.php View File

return $this->em->getRepository($class)->findOneByDevAlias($devAlias) ; return $this->em->getRepository($class)->findOneByDevAlias($devAlias) ;
} }


public function isServerLocalhost()
{
return in_array($_SERVER['REMOTE_ADDR'], ['127.0.0.1', '::1']) ;
}

} }

+ 16
- 7
ShopBundle/Twig/FrontendTwigExtension.php View File



namespace Lc\ShopBundle\Twig; namespace Lc\ShopBundle\Twig;


use App\Repository\HubRepository;
use App\Services\GlobalParam; use App\Services\GlobalParam;
use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\EntityManagerInterface;
use Lc\ShopBundle\Form\Frontend\NewsletterType; use Lc\ShopBundle\Form\Frontend\NewsletterType;
{ {
protected $em ; protected $em ;
protected $security ; protected $security ;
protected $repositoryProductCategory ;
protected $globalParam ; protected $globalParam ;
protected $formFactory ; protected $formFactory ;
protected $productCategoryRepository ;
protected $hubRepository ;


public function __construct(EntityManagerInterface $em, Security $security, ProductCategoryRepository $repositoryProductCategory,
GlobalParam $globalParam, FormFactoryInterface $formFactory)
public function __construct(EntityManagerInterface $em, Security $security, ProductCategoryRepository $productCategoryRepository,
GlobalParam $globalParam, FormFactoryInterface $formFactory, HubRepository $hubRepository)
{ {
$this->em = $em ; $this->em = $em ;
$this->security = $security ; $this->security = $security ;
$this->repositoryProductCategory = $repositoryProductCategory ;
$this->productCategoryRepository = $productCategoryRepository ;
$this->hubRepository = $hubRepository ;
$this->globalParam = $globalParam ; $this->globalParam = $globalParam ;
$this->formFactory = $formFactory ; $this->formFactory = $formFactory ;
} }
return array( return array(
new TwigFunction('get_product_categories', [$this, 'getProductCategories']), new TwigFunction('get_product_categories', [$this, 'getProductCategories']),
new TwigFunction('get_form_newsletter', [$this, 'getFormNewsletter']), new TwigFunction('get_form_newsletter', [$this, 'getFormNewsletter']),
new TwigFunction('get_merchants', [$this, 'getMerchants']),
); );
} }


public function getFilters() public function getFilters()
{ {
return [ return [
new TwigFilter('format_price', [$this, 'format_price']),
new TwigFilter('format_price', [$this, 'formatPrice']),
]; ];
} }


public function getProductCategories() public function getProductCategories()
{ {
$categories = $this->repositoryProductCategory->findAllParents($this->globalParam->getCurrentMerchant()) ;
$categories = $this->productCategoryRepository->findAllParents($this->globalParam->getCurrentMerchant()) ;
return $categories ; return $categories ;
} }


return $form->createView() ; return $form->createView() ;
} }


public function format_price($price)
public function formatPrice($price)
{ {
$price = number_format($price, 2) ; $price = number_format($price, 2) ;
$price = str_replace('.',',',$price) ; $price = str_replace('.',',',$price) ;
return $price ; return $price ;
} }


public function getMerchants()
{
return $this->hubRepository->findAll() ;
}

} }

Loading…
Cancel
Save