Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

FrontendTwigExtension.php 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace Lc\ShopBundle\Twig;
  3. use App\Services\GlobalParam;
  4. use Doctrine\ORM\EntityManagerInterface;
  5. use Lc\ShopBundle\Form\Frontend\NewsletterType;
  6. use Lc\ShopBundle\Repository\ProductCategoryRepository;
  7. use Symfony\Component\Form\FormFactoryInterface;
  8. use Symfony\Component\Security\Core\Security;
  9. use Twig\Extension\AbstractExtension;
  10. use Twig\TwigFilter;
  11. use Twig\TwigFunction;
  12. class FrontendTwigExtension extends AbstractExtension
  13. {
  14. protected $em ;
  15. protected $security ;
  16. protected $repositoryProductCategory ;
  17. protected $globalParam ;
  18. protected $formFactory ;
  19. public function __construct(EntityManagerInterface $em, Security $security, ProductCategoryRepository $repositoryProductCategory,
  20. GlobalParam $globalParam, FormFactoryInterface $formFactory)
  21. {
  22. $this->em = $em ;
  23. $this->security = $security ;
  24. $this->repositoryProductCategory = $repositoryProductCategory ;
  25. $this->globalParam = $globalParam ;
  26. $this->formFactory = $formFactory ;
  27. }
  28. public function getFunctions()
  29. {
  30. return array(
  31. new TwigFunction('get_product_categories', [$this, 'getProductCategories']),
  32. new TwigFunction('get_form_newsletter', [$this, 'getFormNewsletter']),
  33. );
  34. }
  35. public function getFilters()
  36. {
  37. return [
  38. new TwigFilter('format_price', [$this, 'format_price']),
  39. ];
  40. }
  41. public function getProductCategories()
  42. {
  43. $categories = $this->repositoryProductCategory->findAllParents($this->globalParam->getCurrentMerchant()) ;
  44. return $categories ;
  45. }
  46. public function getFormNewsletter()
  47. {
  48. $form = $this->formFactory->create(NewsletterType::class);
  49. return $form->createView() ;
  50. }
  51. public function format_price($price)
  52. {
  53. $price = number_format($price, 2) ;
  54. $price = str_replace('.',',',$price) ;
  55. $price = $price .'&nbsp;€' ;
  56. return $price ;
  57. }
  58. }