|
|
@@ -2,6 +2,7 @@ |
|
|
|
|
|
|
|
namespace Lc\ShopBundle\Twig; |
|
|
|
|
|
|
|
use App\Repository\HubRepository; |
|
|
|
use App\Services\GlobalParam; |
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
|
|
use Lc\ShopBundle\Form\Frontend\NewsletterType; |
|
|
@@ -16,16 +17,18 @@ class FrontendTwigExtension extends AbstractExtension |
|
|
|
{ |
|
|
|
protected $em ; |
|
|
|
protected $security ; |
|
|
|
protected $repositoryProductCategory ; |
|
|
|
protected $globalParam ; |
|
|
|
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->security = $security ; |
|
|
|
$this->repositoryProductCategory = $repositoryProductCategory ; |
|
|
|
$this->productCategoryRepository = $productCategoryRepository ; |
|
|
|
$this->hubRepository = $hubRepository ; |
|
|
|
$this->globalParam = $globalParam ; |
|
|
|
$this->formFactory = $formFactory ; |
|
|
|
} |
|
|
@@ -35,19 +38,20 @@ class FrontendTwigExtension extends AbstractExtension |
|
|
|
return array( |
|
|
|
new TwigFunction('get_product_categories', [$this, 'getProductCategories']), |
|
|
|
new TwigFunction('get_form_newsletter', [$this, 'getFormNewsletter']), |
|
|
|
new TwigFunction('get_merchants', [$this, 'getMerchants']), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
public function getFilters() |
|
|
|
{ |
|
|
|
return [ |
|
|
|
new TwigFilter('format_price', [$this, 'format_price']), |
|
|
|
new TwigFilter('format_price', [$this, 'formatPrice']), |
|
|
|
]; |
|
|
|
} |
|
|
|
|
|
|
|
public function getProductCategories() |
|
|
|
{ |
|
|
|
$categories = $this->repositoryProductCategory->findAllParents($this->globalParam->getCurrentMerchant()) ; |
|
|
|
$categories = $this->productCategoryRepository->findAllParents($this->globalParam->getCurrentMerchant()) ; |
|
|
|
return $categories ; |
|
|
|
} |
|
|
|
|
|
|
@@ -57,7 +61,7 @@ class FrontendTwigExtension extends AbstractExtension |
|
|
|
return $form->createView() ; |
|
|
|
} |
|
|
|
|
|
|
|
public function format_price($price) |
|
|
|
public function formatPrice($price) |
|
|
|
{ |
|
|
|
$price = number_format($price, 2) ; |
|
|
|
$price = str_replace('.',',',$price) ; |
|
|
@@ -65,4 +69,9 @@ class FrontendTwigExtension extends AbstractExtension |
|
|
|
return $price ; |
|
|
|
} |
|
|
|
|
|
|
|
public function getMerchants() |
|
|
|
{ |
|
|
|
return $this->hubRepository->findAll() ; |
|
|
|
} |
|
|
|
|
|
|
|
} |