src/Controller/TaxonController.php line 202

Open in your IDE?
  1. <?php 
  2. declare(strict_types=1);
  3. namespace App\Controller;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Sylius\Component\Locale\Context\LocaleContextInterface;
  8. use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
  9. use Sylius\Component\Core\Repository\ProductRepositoryInterface;
  10. use Sylius\Component\Core\Repository\ProductVariantRepositoryInterface;
  11. use Sylius\Component\Product\Repository\ProductAttributeValueRepositoryInterface;
  12. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  13. use WhiteOctober\BreadcrumbsBundle\Model\Breadcrumbs;
  14. use App\Services\ElasticSearchService;
  15. use App\Entity\SiteArticle;
  16. use App\Entity\SiteCollection;
  17. use App\Entity\SiteFilterFacet;
  18. use Symfony\Component\HttpFoundation\JsonResponse;
  19. use Twig\Environment;
  20. use Symfony\Contracts\Translation\TranslatorInterface;
  21. class TaxonController extends AbstractController
  22. {
  23.     /**
  24.      * Page catégorie
  25.      */
  26.     public function indexAction(
  27.         Request $request,
  28.         LocaleContextInterface $localeContext,
  29.         TaxonRepositoryInterface $taxonRepository,
  30.         ProductRepositoryInterface $productRepository,
  31.         ProductVariantRepositoryInterface $productVariantRepository,
  32.         ProductAttributeValueRepositoryInterface $productAttributeValueRepository,
  33.         ElasticSearchService $elasticSearch,
  34.         Breadcrumbs $breadcrumbs,
  35.         TranslatorInterface $translator,
  36.         $slug
  37.     ) {
  38.         $em $this->get('doctrine')->getManager();
  39.         // Récupère la catégorie
  40.         $taxon $taxonRepository->findOneBySlug($slug$localeContext->getLocaleCode());
  41.         
  42.         if (empty($taxon)) {
  43.             // return;
  44.             // dump($localeContext->getLocaleCode());
  45.             if (str_contains$slug'nos-produits') && $localeContext->getLocaleCode() == 'en_US') {
  46.                 $taxon $taxonRepository->findOneBySlug($slug,  'fr_FR');
  47.                 if (!empty($taxon)) {
  48.                     $conn $em->getConnection();
  49.                     $sql '
  50.                         SELECT * FROM sylius_taxon_translation
  51.                         WHERE translatable_id = :translatable_id
  52.                         AND locale = "en_US"
  53.                     ';
  54.                     $stmt $conn->prepare($sql);
  55.                     $resultSet $stmt->executeQuery(['translatable_id' => $taxon->getId()]);            
  56.                     // returns an array of arrays (i.e. a raw data set)
  57.                     $result $resultSet->fetchAllAssociative();
  58.                     if(count($result) > 0){
  59.                         return $this->redirectToRoute('sylius_shop_product_index', ['slug' => $result[0]['slug']]);
  60.                     }else{
  61.                         throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
  62.                     }
  63.                     // return $this->redirect('http://symfony.com/doc');
  64.                 }else{
  65.                     throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
  66.                 }
  67.             }elseif(str_contains$slug'our-products') && $localeContext->getLocaleCode() == 'fr_FR'){
  68.                 $taxon $taxonRepository->findOneBySlug($slug,  'en_US');
  69.                 if (!empty($taxon)) {
  70.                     $conn $em->getConnection();
  71.                     $sql '
  72.                         SELECT * FROM sylius_taxon_translation
  73.                         WHERE translatable_id = :translatable_id
  74.                         AND locale = "fr_FR"
  75.                     ';
  76.                     $stmt $conn->prepare($sql);
  77.                     $resultSet $stmt->executeQuery(['translatable_id' => $taxon->getId()]);            
  78.                     // returns an array of arrays (i.e. a raw data set)
  79.                     $result $resultSet->fetchAllAssociative();
  80.                     if(count($result) > 0){
  81.                         return $this->redirectToRoute('sylius_shop_product_index', ['slug' => $result[0]['slug']]);
  82.                     }else{
  83.                         throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
  84.                     }
  85.                     // return $this->redirect('http://symfony.com/doc');
  86.                 }else{
  87.                     throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
  88.                 }
  89.             }elseif(str_contains$slug'fabrics-and-small-haberdashery') && $localeContext->getLocaleCode() == 'fr_FR'){
  90.                 $taxon $taxonRepository->findOneBySlug($slug,  'en_US');
  91.                 if (!empty($taxon)) {
  92.                     $conn $em->getConnection();
  93.                     $sql '
  94.                         SELECT * FROM sylius_taxon_translation
  95.                         WHERE translatable_id = :translatable_id
  96.                         AND locale = "fr_FR"
  97.                     ';
  98.                     $stmt $conn->prepare($sql);
  99.                     $resultSet $stmt->executeQuery(['translatable_id' => $taxon->getId()]);            
  100.                     // returns an array of arrays (i.e. a raw data set)
  101.                     $result $resultSet->fetchAllAssociative();
  102.                     if(count($result) > 0){
  103.                         return $this->redirectToRoute('sylius_shop_product_index', ['slug' => $result[0]['slug']]);
  104.                     }else{
  105.                         throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
  106.                     }
  107.                     // return $this->redirect('http://symfony.com/doc');
  108.                 }else{
  109.                     throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
  110.                 }
  111.             }elseif(str_contains$slug'tissus-et-petite-mercerie') && $localeContext->getLocaleCode() == 'en_US'){
  112.                 $taxon $taxonRepository->findOneBySlug($slug,  'fr_FR');
  113.                 if (!empty($taxon)) {
  114.                     $conn $em->getConnection();
  115.                     $sql '
  116.                         SELECT * FROM sylius_taxon_translation
  117.                         WHERE translatable_id = :translatable_id
  118.                         AND locale = "en_US"
  119.                     ';
  120.                     $stmt $conn->prepare($sql);
  121.                     $resultSet $stmt->executeQuery(['translatable_id' => $taxon->getId()]);            
  122.                     // returns an array of arrays (i.e. a raw data set)
  123.                     $result $resultSet->fetchAllAssociative();
  124.                     if(count($result) > 0){
  125.                         return $this->redirectToRoute('sylius_shop_product_index', ['slug' => $result[0]['slug']]);
  126.                     }else{
  127.                         throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
  128.                     }
  129.                     // return $this->redirect('http://symfony.com/doc');
  130.                 }else{
  131.                     throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
  132.                 }
  133.             }else{
  134.                 throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
  135.             }
  136.             
  137.         }
  138.         // Fil d'ariane
  139.         $taxonParent $taxon;
  140.         // dump( $taxonParent);
  141.         // dump( $taxon->getRoot());
  142.         while ($taxonParent->getId() != $taxon->getRoot()->getId()) {
  143.             // dump( $taxonParent);
  144.             $breadcrumbs->prependRouteItem($taxonParent"sylius_shop_product_index", [
  145.                 'slug' => $taxonParent->getSlug()
  146.             ]);
  147.             // dump( $taxonParent);
  148.             $taxonParent $taxonParent->getParent();
  149.         }
  150.         $breadcrumbs->prependRouteItem($taxon->getRoot()->getName(), "sylius_shop_product_index", [
  151.             'slug' => $taxon->getRoot()->getSlug()
  152.         ]);
  153.         $breadcrumbs->prependRouteItem("sylius.ui.home""sylius_shop_homepage");
  154.         // Catégorie de "niveau 1" - On affiche uniquement les sous catégories
  155.         if ($taxon->getLevel() == 0) {
  156.            
  157.             // foreach($taxon->getChildren() as $child){
  158.             //     dump($child->getSlug());
  159.             // }
  160.             return $this->render('site_taxon_level1_show.html.twig', [
  161.                 'taxon' => $taxon
  162.             ]);
  163.         }
  164.         $em $this->get('doctrine')->getManager();
  165.         // Récupère les articles dans la catégorie d'articles associé
  166.         $articles = [];
  167.         if (empty($taxon->getSingleArticleCategory()) == false) {
  168.             $articles $em->getRepository(SiteArticle::class)
  169.             ->createQueryBuilder('a')
  170.             ->where('a.articleCategory = :category')
  171.             ->andWhere('a.dateDiffusion < :today')
  172.             ->setParameter('today'date("Y-m-d H:i:s"))
  173.             ->orderBy('a.createdAt''DESC')
  174.             ->setParameter('category'$taxon->getSingleArticleCategory())
  175.             ->getQuery()
  176.             ->getResult();
  177.         }
  178.         // Récupère tous les filtres à facettes disponible pour 
  179.         // cette "recherche"
  180.         $siteFilterFacets $em->getRepository(SiteFilterFacet::class)
  181.         ->findBy([
  182.             'enabled' => true
  183.         ], [
  184.             'position' => 'ASC'
  185.         ]);
  186.         // dump($siteFilterFacets);
  187.         $esAggregations $elasticSearch->getFilterFacetsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), array_map(function ($row) {
  188.             return $row->getId();
  189.         }, $siteFilterFacets));
  190.         dump$esAggregations);
  191.         $siteFilterShape = [];
  192.         if (count($esAggregations['shape']['buckets']) > 1) {
  193.             $siteFilterShape $productRepository->findBy([
  194.                 'id' => array_map(function ($row) {
  195.                     return $row['key'];
  196.                 }, $esAggregations['shape']['buckets']),
  197.                 'enabled' => true
  198.             ], [
  199.                 'code' => 'ASC'
  200.             ]);
  201.             usort($siteFilterShape, function ($a$b) {
  202.                 // dump($a->getTranslation()->getName());
  203.                
  204.                 return strcmp(str_replace('É''e',$a->getTranslation()->getName()) , str_replace('É''e'$b->getTranslation()->getName()) );
  205.             });
  206.         }
  207.         dump($siteFilterShape);
  208.         // dump($esAggregations) ;
  209.         $siteFilterColor = [];
  210.         if (count($esAggregations['color']['buckets']) > 1) {
  211.             $siteFilterColor $em->getRepository(SiteCollection::class)->findBy([
  212.                 'productOptionValue' => array_map(function ($row) {
  213.                     return $row['key'];
  214.                 }, $esAggregations['color']['buckets']),
  215.             ]);
  216.         }
  217.         usort($siteFilterColor, function($a$b) {
  218.             return $a->getDateRelease() < $b->getDateRelease();
  219.         });
  220.         $siteFilterFacetsValues = [];
  221.         foreach ($esAggregations as $keyEsAggregation => $rowEsAggregation) {
  222.             // dump( $keyEsAggregation);
  223.             // dump( $rowEsAggregation);
  224.             if (isset($rowEsAggregation['buckets']) && count($rowEsAggregation['buckets']) > 1) {
  225.                 $siteFilterFacetsValues[$keyEsAggregation] = array_map(function ($row) {
  226.                     return $row['key'];
  227.                 }, $rowEsAggregation['buckets']);
  228.                 // On met dans l'ordre alphabétique
  229.                 sort($siteFilterFacetsValues[$keyEsAggregation]);
  230.             }
  231.         }
  232.         dump$siteFilterFacetsValues);
  233.         // Conserve que les filtres à facettes disponible pour cette recherche
  234.         $siteFilterFacets array_filter($siteFilterFacets, function ($row) use (&$siteFilterFacetsValues) {
  235.             return in_array($row->getId(), array_keys($siteFilterFacetsValues));
  236.         });
  237.         $siteFilterBadge = [];
  238.         $siteFilterBadgeVariants = [];
  239.         if (count($esAggregations['badge']['buckets']) > 1) {
  240.             foreach($esAggregations['badge']['buckets'] as $badge){
  241.                 $siteFilterBadge[] = array(
  242.                     'name' => $translator->trans("app.ui.product_callout.".$badge['key']),
  243.                     'id' => $badge['key'],
  244.                 );
  245.             }
  246.             // $siteFilterBadgeVariants = $productVariantRepository->findBy([
  247.             //     'badge' => array_map(function ($row) {
  248.             //         return $row['key'];
  249.             //     }, $esAggregations['badge']['buckets']),
  250.             //     'enabled' => true
  251.             // ], [
  252.             //     'code' => 'ASC'
  253.             // ]);
  254.             
  255.             // if(count($siteFilterBadgeVariants) > 0){
  256.             //     foreach($siteFilterBadgeVariants as $siteFilterBadgeVariant){
  257.             //         $siteFilterBadge[$siteFilterBadgeVariant->getBadge()] = array(
  258.             //             'name' => $translator->trans("app.ui.product_callout.".$siteFilterBadgeVariant->getBadge()),
  259.             //             'id' => $siteFilterBadgeVariant->getBadge(),
  260.             //         );
  261.             //     }
  262.             // }
  263.         }
  264.         // dump( $esAggregations);
  265.         // Récupère tous les produits dans cette catégorie avec 
  266.         // l'applique du filtre à facette et/ou de l'ordre 
  267.         $sorting $request->query->get('sorting');
  268.         $sortBy null;
  269.         $sortOrder null;
  270.         if (is_array($sorting)) {
  271.             $sortBy key($sorting);
  272.             $sortOrder $sorting[key($sorting)];
  273.         }
  274.         $selectedFacets = (array) $request->query->get('facets', []);
  275.         $results $elasticSearch->getElementsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), 0$selectedFacets$sortBy$sortOrder);
  276.         $variants = [];
  277.         if (count($results['hits']['hits']) > 0) {
  278.             $variants $productVariantRepository->findByIdsAndOrderByFieldId(array_map(function ($row) {
  279.                 return str_ireplace('VARIANT_'''$row['_id']);
  280.             }, $results['hits']['hits']));
  281.         }
  282.         dump($taxon->getLevel());
  283.         // Récupère les liens pour la partie référencement
  284.         $referencementllinks = [];
  285.         if (!empty($taxon->getSeoLinks())) {
  286.             $referencementllinks $taxonRepository->findBy([
  287.                 'id' => $taxon->getSeoLinks()
  288.             ]);
  289.         }       
  290.         // Catégorie de "niveau 2"
  291.         if ($taxon->getLevel() == 1) {
  292.             // Récupère les produits avec le badge "nouveau" de la catégorie
  293.             $newestProducts $productVariantRepository->findNewestEnabledByTaxonsAndLocale(
  294.                 array_merge(
  295.                     [$taxon], 
  296.                     $taxonRepository->findAllChildren($taxon->getCode(), $localeContext->getLocaleCode())
  297.                 ),
  298.                 $localeContext->getLocaleCode(),
  299.                 10 // nombre de produits minimum avec le badge "newest"/"nouveauté"
  300.             );
  301.             // $newestProducts = [];
  302.             // dump($newestProducts );
  303.             // dump($localeContext->getLocaleCode());
  304.             
  305.             if($localeContext->getLocaleCode() == 'fr_FR'){
  306.                 $ctas = empty($taxon->getCtas()) ? $taxon->getRoot()->getCtas() : $taxon->getCtas();
  307.             }else{
  308.                 $ctas = empty($taxon->getCtasEn()) ? $taxon->getRoot()->getCtasEn() : $taxon->getCtasEn();
  309.             }
  310.             
  311.             return $this->render('site_taxon_level2_show.html.twig', [
  312.                 'taxon' => $taxon,
  313.                 'referencementllinks' => $referencementllinks,
  314.                 'variants' => $variants,
  315.                 'articles' => $articles,
  316.                 'newestProducts' => $newestProducts,
  317.                 'ctas' => $ctas,
  318.                 'selectedFacets' => $selectedFacets,
  319.                 'siteFilterShape' => $siteFilterShape,
  320.                 'siteFilterColor' => $siteFilterColor,
  321.                 'siteFilterBadge' => $siteFilterBadge,
  322.                 'siteFilterFacets' => $siteFilterFacets,
  323.                 'siteFilterFacetsValues' => $siteFilterFacetsValues,
  324.                 'siteFilterMinPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MIN]['value'],
  325.                 'siteFilterMaxPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MAX]['value'],
  326.                 'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS,
  327.                 'totalResults' => $results['hits']['total']['value'],
  328.                 'filtreUrl' => ''
  329.             ]);
  330.         }
  331.         
  332.            // dump($siteFilterFacets);
  333.         // dump($siteFilterFacetsValues);
  334.         // Catégorie de "niveau 3"
  335.         return $this->render('site_taxon_lastlevel_show.html.twig', [
  336.             'taxon' => $taxon,
  337.             'referencementllinks' => $referencementllinks,
  338.             'variants' => $variants,
  339.             'selectedFacets' => $selectedFacets,
  340.             'siteFilterShape' => $siteFilterShape,
  341.             'siteFilterColor' => $siteFilterColor,
  342.             'siteFilterBadge' => $siteFilterBadge,
  343.             'siteFilterFacets' => $siteFilterFacets,
  344.             'siteFilterFacetsValues' => $siteFilterFacetsValues,
  345.             'siteFilterMinPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MIN]['value'],
  346.             'siteFilterMaxPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MAX]['value'],
  347.             'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS,
  348.             'totalResults' => $results['hits']['total']['value'],
  349.             'filtreUrl' => ''
  350.         ]);
  351.     }
  352.     public function ajaxTaxonProductList(
  353.         Request $request
  354.         ElasticSearchService $elasticSearch
  355.         LocaleContextInterface $localeContext,
  356.         ProductVariantRepositoryInterface $productVariantRepository,
  357.         TaxonRepositoryInterface $taxonRepository,
  358.         Environment $twigEnvironment,
  359.         ProductRepositoryInterface $productRepository,
  360.         TranslatorInterface $translator,
  361.         $taxonId
  362.     ) {
  363.        
  364.         $tstart microtime(true);
  365.         // Récupère la catégorie
  366.         $taxon $taxonRepository->findOneById($taxonId);
  367.         
  368.         if (empty($taxon)) {
  369.             return new Response('');
  370.         }
  371.         $t1 microtime(true);
  372.         // OFFSET
  373.         $offset intval($request->request->get('offset'0));
  374.         $offset min(max($offset0), ElasticSearchService::MAX_WINDOW_RESULTS ElasticSearchService::MAX_SEARCH_RESULTS);
  375.         // SORT BY
  376.         $sorting $request->request->get('sorting');
  377.         $sortBy null;
  378.         $sortOrder null;
  379.         if (is_array($sorting)) {
  380.             $sortBy key($sorting);
  381.             $sortOrder $sorting[key($sorting)];
  382.         }
  383.         $selectedFacets = (array) $request->request->get('facets', []);
  384.         $fromPage $request->query->get('filtre');
  385.         // $selectedFacetsFromPage = array();
  386.         // if(!empty($fromPage)){
  387.         //     // si badge
  388.         //     if (str_contains( $fromPage, 'badge')) {
  389.         //         $filtreArr = explode("=", $fromPage);
  390.         //         $badge = $filtreArr[1];
  391.         //         $selectedFacetsFromPage = ['badge' => $badge];
  392.         //     }else{
  393.         //         $selectedFacetsFromPage = $fromPage;
  394.         //     }
  395.         // }
  396.         // if(count($selectedFacetsFromPage) > 0){
  397.         //     $selectedFacets = array_merge($selectedFacets,$selectedFacetsFromPage);
  398.         // }
  399.         // 
  400.         // dump($selectedFacets);
  401.         // dump($selectedFacetsFromPage);
  402.         
  403.         // dump($selectedFacets);
  404.         $fromCat $taxon->getId();
  405.         if(isset($selectedFacets['taxons'])){
  406.             foreach($selectedFacets['taxons'] as $taxonId){
  407.                  //si recherche tissu, la cat de base est 222 
  408.                  $is_tissu = array(222223225226228229230231224234232233290285235);
  409.                  if (in_array($taxonId$is_tissu)) {
  410.                     $fromCat 222;
  411.                 }
  412.             }           
  413.         }
  414.         // die($fromCat.'aaa');
  415.         if(count($selectedFacets) == && !empty($fromPage)){
  416.             $results = array();
  417.         }elseif($offset != 0){
  418.             $results $elasticSearch->getElementsByTaxon($localeContext->getLocaleCode(), $fromCat$offset$selectedFacets$sortBy$sortOrderfalse);
  419.         }else{
  420.             $results $elasticSearch->getElementsByTaxon($localeContext->getLocaleCode(), $fromCat$offset$selectedFacets$sortBy$sortOrdertrue);
  421.         }
  422.         $t2 microtime(true);
  423.         // dump($fromCat); 
  424.         $variants = [];
  425.         if (isset($results['hits']) && count($results['hits']['hits']) > 0) {
  426.             $variants $productVariantRepository->findByIdsAndOrderByFieldId(array_map(function ($row) {
  427.                 return str_ireplace('VARIANT_'''$row['_id']);
  428.             }, $results['hits']['hits']));
  429.         }
  430.         $t3 microtime(true);
  431.         $em $this->get('doctrine')->getManager();
  432.         $siteFilterFacets $em->getRepository(SiteFilterFacet::class)
  433.         ->findBy([
  434.             'enabled' => true
  435.         ], [
  436.             'position' => 'ASC'
  437.         ]);
  438.         $t4 microtime(true);
  439.         // dump($siteFilterFacets);
  440.         $esAggregations $elasticSearch->getFilterFacetsByTaxon($localeContext->getLocaleCode(), $fromCatarray_map(function ($row) {
  441.             return $row->getId();
  442.         }, $siteFilterFacets));
  443.         // dump($taxon);
  444.         // dump($esAggregations) ;
  445.         $siteFilterFacetsValues = [];
  446.         foreach ($esAggregations as $keyEsAggregation => $rowEsAggregation) {
  447.             // dump( $keyEsAggregation);
  448.             // dump( $rowEsAggregation);
  449.             if (isset($rowEsAggregation['buckets']) && count($rowEsAggregation['buckets']) > 1) {
  450.                 $siteFilterFacetsValues[$keyEsAggregation] = array_map(function ($row) {
  451.                     return $row['key'];
  452.                 }, $rowEsAggregation['buckets']);
  453.                 // On met dans l'ordre alphabétique
  454.                 sort($siteFilterFacetsValues[$keyEsAggregation]);
  455.             }
  456.         }
  457.         $t5 microtime(true);
  458.         // dump($siteFilterFacetsValues);
  459.          // Conserve que les filtres à facettes disponible pour cette recherche
  460.          $siteFilterFacets array_filter($siteFilterFacets, function ($row) use (&$siteFilterFacetsValues) {
  461.             return in_array($row->getId(), array_keys($siteFilterFacetsValues));
  462.         });
  463.         // dump($siteFilterFacets);
  464.         // dump($variants);
  465.         $t6 microtime(true);
  466.         $siteFilterShape = [];
  467.         if (count($esAggregations['shape']['buckets']) > 1) {
  468.             $siteFilterShape $productRepository->findBy([
  469.                 'id' => array_map(function ($row) {
  470.                     return $row['key'];
  471.                 }, $esAggregations['shape']['buckets']),
  472.                 'enabled' => true
  473.             ], [
  474.                 'code' => 'ASC'
  475.             ]);
  476.             usort($siteFilterShape, function ($a$b) {
  477.                 // dump($a->getTranslation()->getName());
  478.                
  479.                 return strcmp(str_replace('É''e',$a->getTranslation()->getName()) , str_replace('É''e'$b->getTranslation()->getName()) );
  480.             });
  481.         }
  482.         
  483.         $t7 microtime(true);
  484.         dump($siteFilterShape);
  485.         $siteFilterColor = [];
  486.         if (count($esAggregations['color']['buckets']) > 1) {
  487.             $siteFilterColor $em->getRepository(SiteCollection::class)->findBy([
  488.                 'productOptionValue' => array_map(function ($row) {
  489.                     return $row['key'];
  490.                 }, $esAggregations['color']['buckets']),
  491.             ]);
  492.         }
  493.         usort($siteFilterColor, function($a$b) {
  494.             return $a->getDateRelease() < $b->getDateRelease();
  495.         });
  496.         $t8 microtime(true);
  497.         $siteFilterBadge = [];
  498.         $siteFilterBadgeVariants = [];
  499.         if (count($esAggregations['badge']['buckets']) > 1) {
  500.             foreach($esAggregations['badge']['buckets'] as $badge){
  501.                 $siteFilterBadge[] = array(
  502.                     'name' => $translator->trans("app.ui.product_callout.".$badge['key']),
  503.                     'id' => $badge['key'],
  504.                 );
  505.             }
  506.             // $siteFilterBadgeVariants = $productVariantRepository->findBy([
  507.             //     'badge' => array_map(function ($row) {
  508.             //         return $row['key'];
  509.             //     }, $esAggregations['badge']['buckets']),
  510.             //     'enabled' => true
  511.             // ], [
  512.             //     'code' => 'ASC'
  513.             // ]);
  514.             
  515.             // if(count($siteFilterBadgeVariants) > 0){
  516.             //     foreach($siteFilterBadgeVariants as $siteFilterBadgeVariant){
  517.             //         $siteFilterBadge[$siteFilterBadgeVariant->getBadge()] = array(
  518.             //             'name' => $translator->trans("app.ui.product_callout.".$siteFilterBadgeVariant->getBadge()),
  519.             //             'id' => $siteFilterBadgeVariant->getBadge(),
  520.             //         );
  521.             //     }
  522.             // }
  523.         }
  524.         dump$esAggregations);
  525.         dump$siteFilterBadge);
  526.         $t9 microtime(true);
  527.         $log = [];
  528.         $log[] = 'Time to retrieve taxon: ' . ($t1 $tstart) . ' seconds';
  529.         $log[] = 'Time to retrieve elements by taxon: ' . ($t2 $t1) . ' seconds';
  530.         $log[] = 'Time to retrieve variants: ' . ($t3 $t2) . ' seconds';
  531.         $log[] = 'Time to retrieve site filter facets: ' . ($t4 $t3) . ' seconds';
  532.         $log[] = 'Time to retrieve filter facets by taxon: ' . ($t5 $t4) . ' seconds';
  533.         $log[] = 'Time to filter site filter facets: ' . ($t6 $t5) . ' seconds';
  534.         $log[] = 'Time to retrieve site filter shape: ' . ($t7 $t6) . ' seconds';
  535.         $log[] = 'Time to retrieve site filter color: ' . ($t8 $t7) . ' seconds';
  536.         $log[] = 'Time to retrieve site filter badge: ' . ($t9 $t8) . ' seconds';
  537.         dump($log);
  538.         // $filtreUrl = '';
  539.         // if(!empty($request->get('filtre')) && !empty($request->get('filtrevalue'))){
  540.         //     $filtreUrl = $request->get('filtre').'/'.$request->get('filtrevalue');
  541.         // }
  542.         if (count($variants) <= 0) {
  543.             return new JsonResponse([
  544.                 'variants' => $twigEnvironment->render('taxons/taxon_list_products_ajax.html.twig', [
  545.                     'variants' => '',
  546.                     'taxon' => $taxon
  547.                 ]),
  548.                 'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS_AJAX,
  549.                 'totalResults' => 0,
  550.                 // 'siteFilterFacets' => $siteFilterFacets
  551.                 'siteFilterFacets' => $twigEnvironment->render('partials/block-facet-filters.html.twig', [
  552.                     'siteFilterFacets' => $siteFilterFacets,
  553.                     'siteFilterShape' => $siteFilterShape,
  554.                     'siteFilterBadgeVariants' => $siteFilterBadgeVariants,
  555.                     'siteFilterColor' => $siteFilterColor,
  556.                     'siteFilterBadge' => $siteFilterBadge,
  557.                     'siteFilterFacetsValues' => $siteFilterFacetsValues,
  558.                     'ajaxUrl'=> $this->get('router')->generate('app_taxon_ajax_list', array('taxonId' => $taxon->getId()))
  559.                 ]),
  560.                 // 'filtreUrl' => $filtreUrl,
  561.             ]); 
  562.         }else{
  563.             if(isset( $selectedFacets['color'])){
  564.                 $shapeMatch = array();
  565.                 foreach($variants as $variant){
  566.                     $shapeMatch[$variant->getProduct()->getId()] = $variant->getProduct()->getId();                  
  567.                 }
  568.         
  569.                 $siteFilterShapeVariants = array();
  570.                 foreach($siteFilterShape as $shape){
  571.                     if (in_array($shape->getId(), $shapeMatch)) {
  572.                         $siteFilterShapeVariants[] = $shape
  573.                     }
  574.                 }
  575.     
  576.             }else{
  577.                 $siteFilterShapeVariants $siteFilterShape;
  578.             }
  579.             
  580.             if(isset( $selectedFacets['shape'])){       
  581.         
  582.                 $collectionMatch = array();
  583.                 foreach($variants as $variant){
  584.                     if($variant->getOptionValues()->first()){
  585.                         $collectionMatch[$variant->getOptionValues()->first()->getId()] = $variant->getOptionValues()->first()->getId();  
  586.                     }
  587.                                    
  588.                 }
  589.     
  590.                 $siteFilterColorVariants = array();
  591.                 foreach($siteFilterColor as $color){
  592.                     if (in_array($color->getProductOptionValue()->getId(), $collectionMatch)) {
  593.                         $siteFilterColorVariants[] = $color
  594.                     }
  595.                 }
  596.     
  597.             }else{
  598.                 $siteFilterColorVariants $siteFilterColor;
  599.             }
  600.             $badgeMatch = array();
  601.             foreach($variants as $variant){
  602.                 $badgeMatch[$variant->getBadge()] = $variant->getBadge();                  
  603.             }
  604.             $siteFilterBadgeVariants = array();
  605.             foreach($siteFilterBadge as $badge){
  606.                 if (in_array($badge['id'], $badgeMatch)) {
  607.                     $siteFilterBadgeVariants[] = $badge
  608.                 }
  609.             }
  610.             $filtersMatch = array();
  611.             foreach($variants as $variant){               
  612.                 // $variant->getProduct()->getAttributeValue()
  613.                 foreach($variant->getProduct()->getAttributes() as $attr){                    
  614.                     $value $attr->getValue();
  615.                     // $filtersMatch[$attr->getAttribute()->getId()][$variant->getProduct()->getId()][$attr->getId()] = $value[0];    
  616.                     if(isset($value[0])){     
  617.                         $filtersMatch[$attr->getAttribute()->getId()][$value[0]] = $attr->getId();        
  618.                     }        
  619.                    
  620.                 }
  621.             }
  622.             $siteFilterOtherVariants = array();
  623.             foreach($siteFilterFacets as $key => $facet){
  624.                 // dump($facet);
  625.                 // dump($facet->getProductAttribute());
  626.                 if (isset($filtersMatch[$facet->getProductAttribute()->getId()])/* && in_array($facet->getProductAttribute()->getOptionValues(), $filtersMatch[$facet->getProductAttribute()->getId()])*/) {
  627.                     $siteFilterOtherVariants[] = $facet
  628.                     // foreach($facet->getProductAttribute()->getConfiguration()['choices'] as $key => $choice){
  629.                     // }
  630.                 }
  631.             }
  632.             
  633.             // dump($variants);
  634.             // dump($filtersMatch);
  635.             // dump($siteFilterFacets);
  636.             // dump($siteFilterFacetsValues);
  637.             // // dump($esAggregations);
  638.             // dump($siteFilterOtherVariants);
  639.             // // dump($siteFilterColor);
  640.             // // dump($collectionMatch);
  641.             // // dump($siteFilterColorVariants);
  642.         }
  643.         $tend microtime(true);
  644.         // dump($t1 - $tstart);
  645.         
  646.         $log[] = 'Total execution time: ' . ($tend $tstart) . ' seconds';
  647.         dump($log);
  648.         // $logger = $this->get('logger');
  649.         // $logger->info('Time to retrieve taxon: ' . ($t1 - $tstart) . ' seconds');
  650.         // $logger->info('Time to retrieve elements by taxon: ' . ($t2 - $t1) . ' seconds');
  651.         // $logger->info('Time to retrieve variants: ' . ($t3 - $t2) . ' seconds');
  652.         // $logger->info('Time to retrieve site filter facets: ' . ($t4 - $t3) . ' seconds');
  653.         // $logger->info('Time to retrieve filter facets by taxon: ' . ($t5 - $t4) . ' seconds');
  654.         // $logger->info('Time to filter site filter facets: ' . ($t6 - $t5) . ' seconds');
  655.         // $logger->info('Time to retrieve site filter shape: ' . ($t7 - $t6) . ' seconds');
  656.         // $logger->info('Time to retrieve site filter color: ' . ($t8 - $t7) . ' seconds');
  657.         // $logger->info('Time to retrieve site filter badge: ' . ($t9 - $t8) . ' seconds');
  658.         // $logger->info('Total execution time: ' . ($tend - $tstart) . ' seconds');
  659.         // Renvoyer les résultats
  660.         // return $this->render('taxons/taxon_list_products_ajax.html.twig', [
  661.         //     'variants' => $variants,
  662.         //     'taxon' => $taxon
  663.         // ]);
  664.         return new JsonResponse([
  665.             'variants' => $twigEnvironment->render('taxons/taxon_list_products_ajax.html.twig', [
  666.                 'variants' => $variants,
  667.                 'taxon' => $taxon
  668.             ]),
  669.             'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS_AJAX,
  670.             'totalResults' => $results['hits']['total']['value'],
  671.             // 'siteFilterFacets' => $siteFilterFacets
  672.             'siteFilterFacets' => $twigEnvironment->render('partials/block-facet-filters.html.twig', [
  673.                 'siteFilterFacets' => $siteFilterOtherVariants,
  674.                 'siteFilterShape' => $siteFilterShapeVariants,
  675.                 'siteFilterColor' => $siteFilterColorVariants,
  676.                 'siteFilterBadge' => $siteFilterBadgeVariants,
  677.                 'siteFilterFacetsValues' => $siteFilterFacetsValues,
  678.                 'ajaxUrl'=> $this->get('router')->generate('app_taxon_ajax_list', array('taxonId' => $taxon->getId())),                
  679.             ]),
  680.             // 'filtreUrl' => $filtreUrl,
  681.         ]);  
  682.     }
  683.     
  684.     
  685.     public function indexWithFiltreAction(
  686.         Request $request,
  687.         LocaleContextInterface $localeContext,
  688.         TaxonRepositoryInterface $taxonRepository,
  689.         ProductRepositoryInterface $productRepository,
  690.         ProductVariantRepositoryInterface $productVariantRepository,
  691.         ProductAttributeValueRepositoryInterface $productAttributeValueRepository,
  692.         ElasticSearchService $elasticSearch,
  693.         Breadcrumbs $breadcrumbs,
  694.         TranslatorInterface $translator,
  695.         $cat1,
  696.         $cat2
  697.     ) {
  698.       
  699.         $slug 'nos-produits/'.$cat1.'/'.$cat2;
  700.         //si filtre deja engagé
  701.         $filtreUrl '';
  702.         if(!empty($request->get('filtre')) && !empty($request->get('filtrevalue'))){
  703.             $filtreUrl $request->get('filtre').'/'.$request->get('filtrevalue');
  704.         }
  705.         // Récupère la catégorie
  706.         $taxon $taxonRepository->findOneBySlug($slug$localeContext->getLocaleCode());
  707.        
  708.         if (empty($taxon)) {
  709.             // return;
  710.             throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
  711.         }
  712.         // Fil d'ariane
  713.         $taxonParent $taxon;
  714.         while ($taxonParent != $taxon->getRoot()) {
  715.             $breadcrumbs->prependRouteItem($taxonParent"sylius_shop_product_index", [
  716.                 'slug' => $taxonParent->getSlug()
  717.             ]);
  718.             $taxonParent $taxonParent->getParent();
  719.         }
  720.         $breadcrumbs->prependRouteItem($taxon->getRoot()->getName(), "sylius_shop_product_index", [
  721.             'slug' => $taxon->getRoot()->getSlug()
  722.         ]);
  723.         $breadcrumbs->prependRouteItem("sylius.ui.home""sylius_shop_homepage");
  724.       
  725.         // Catégorie de "niveau 1" - On affiche uniquement les sous catégories
  726.         if ($taxon->getLevel() == 0) {
  727.             return $this->render('site_taxon_level1_show.html.twig', [
  728.                 'taxon' => $taxon
  729.             ]);
  730.         }
  731.         $em $this->get('doctrine')->getManager();
  732.         // Récupère les articles dans la catégorie d'articles associé
  733.         $articles = [];
  734.         if (empty($taxon->getSingleArticleCategory()) == false) {
  735.             $articles $em->getRepository(SiteArticle::class)
  736.             ->createQueryBuilder('a')
  737.             ->where('a.articleCategory = :category')
  738.             ->andWhere('a.dateDiffusion < :today')
  739.             ->setParameter('today'date("Y-m-d H:i:s"))
  740.             ->orderBy('a.createdAt''DESC')
  741.             ->setParameter('category'$taxon->getSingleArticleCategory())
  742.             ->getQuery()
  743.             ->getResult();
  744.         }
  745.         // Récupère tous les filtres à facettes disponible pour 
  746.         // cette "recherche"
  747.         $siteFilterFacets $em->getRepository(SiteFilterFacet::class)
  748.         ->findBy([
  749.             'enabled' => true
  750.         ], [
  751.             'position' => 'ASC'
  752.         ]);
  753.         $esAggregations $elasticSearch->getFilterFacetsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), array_map(function ($row) {
  754.             return $row->getId();
  755.         }, $siteFilterFacets));
  756.         dump($esAggregations) ;
  757.         $siteFilterShape = [];
  758.         if (count($esAggregations['shape']['buckets']) > 1) {
  759.             $siteFilterShape $productRepository->findBy([
  760.                 'id' => array_map(function ($row) {
  761.                     return $row['key'];
  762.                 }, $esAggregations['shape']['buckets']),
  763.                 'enabled' => true
  764.             ], [
  765.                 'code' => 'ASC'
  766.             ]);
  767.             usort($siteFilterShape, function ($a$b) {
  768.                 // dump($a->getTranslation()->getName());
  769.                
  770.                 return strcmp(str_replace('É''e',$a->getTranslation()->getName()) , str_replace('É''e'$b->getTranslation()->getName()) );
  771.             });
  772.         }
  773.         $siteFilterColor = [];
  774.         if (count($esAggregations['color']['buckets']) > 1) {
  775.             $siteFilterColor $em->getRepository(SiteCollection::class)->findBy([
  776.                 'productOptionValue' => array_map(function ($row) {
  777.                     return $row['key'];
  778.                 }, $esAggregations['color']['buckets']),
  779.             ]);
  780.         }
  781.         usort($siteFilterColor, function($a$b) {
  782.             return $a->getDateRelease() < $b->getDateRelease();
  783.         });
  784.         $siteFilterBadge = [];
  785.         $siteFilterBadgeVariants = [];
  786.         if (count($esAggregations['badge']['buckets']) > 1) {
  787.             foreach($esAggregations['badge']['buckets'] as $badge){
  788.                 $siteFilterBadge[] = array(
  789.                     'name' => $translator->trans("app.ui.product_callout.".$badge['key']),
  790.                     'id' => $badge['key'],
  791.                 );
  792.             }
  793.             // $siteFilterBadgeVariants = $productVariantRepository->findBy([
  794.             //     'badge' => array_map(function ($row) {
  795.             //         return $row['key'];
  796.             //     }, $esAggregations['badge']['buckets']),
  797.             //     'enabled' => true
  798.             // ], [
  799.             //     'code' => 'ASC'
  800.             // ]);
  801.             
  802.             // if(count($siteFilterBadgeVariants) > 0){
  803.             //     foreach($siteFilterBadgeVariants as $siteFilterBadgeVariant){
  804.             //         $siteFilterBadge[$siteFilterBadgeVariant->getBadge()] = array(
  805.             //             'name' => $translator->trans("app.ui.product_callout.".$siteFilterBadgeVariant->getBadge()),
  806.             //             'id' => $siteFilterBadgeVariant->getBadge(),
  807.             //         );
  808.             //     }
  809.             // }
  810.         }
  811.         $siteFilterFacetsValues = [];
  812.         foreach ($esAggregations as $keyEsAggregation => $rowEsAggregation) {
  813.             if (isset($rowEsAggregation['buckets']) && count($rowEsAggregation['buckets']) > 1) {
  814.                 $siteFilterFacetsValues[$keyEsAggregation] = array_map(function ($row) {
  815.                     return $row['key'];
  816.                 }, $rowEsAggregation['buckets']);
  817.                 // On met dans l'ordre alphabétique
  818.                 sort($siteFilterFacetsValues[$keyEsAggregation]);
  819.             }
  820.         }
  821.         // Conserve que les filtres à facettes disponible pour cette recherche
  822.         $siteFilterFacets array_filter($siteFilterFacets, function ($row) use (&$siteFilterFacetsValues) {
  823.             return in_array($row->getId(), array_keys($siteFilterFacetsValues));
  824.         });
  825.        
  826.         $noindex true;
  827.         dump($siteFilterFacetsValues);
  828.         dump($request->get('filtre'));
  829.         //on regarde si le filtre engagé est indexable ou non
  830.         foreach($siteFilterFacetsValues as $key => $facet){
  831.             if(is_int($key)){
  832.                 //carac
  833.                 $filtre $em->getRepository(SiteFilterFacet::class)->find($key);     
  834.                 // dump($filtre->getProductAttribute());        
  835.                 // dump($request->get('filtre').' ---- '.$this->replaceSpecialChar(strtolower($filtre->getProductAttribute()->getName())));     
  836.                 if($this->replaceSpecialChar(strtolower($filtre->getProductAttribute()->getName())) == $request->get('filtre')){
  837.                     $noindex = !$filtre->getIndexableSeo();
  838.                    
  839.                 }          
  840.             }elseif($key == 'shape' && $request->get('filtre') == "forme"){ //forme
  841.                 $noindex false;
  842.             }elseif($key == 'color' && $request->get('filtre') == "collection"){  //colelction
  843.                 $noindex true;
  844.             }elseif($key == 'badge' && $request->get('filtre') == "badge"){  //colelction
  845.                 $noindex false;
  846.             }
  847.                     
  848.         }
  849.         dump($noindex);
  850.         
  851.         $meta_filtre ucfirst($request->get('filtre')).' '.$request->get('filtrevalue');           
  852.         
  853.         // dump( $meta_filtre);
  854.         // Récupère tous les produits dans cette catégorie avec 
  855.         // l'applique du filtre à facette et/ou de l'ordre 
  856.         $sorting $request->query->get('sorting');
  857.         $sortBy null;
  858.         $sortOrder null;
  859.         if (is_array($sorting)) {
  860.             $sortBy key($sorting);
  861.             $sortOrder $sorting[key($sorting)];
  862.         }
  863.         $selectedFacets = (array) $request->query->get('facets', []);
  864.         $results $elasticSearch->getElementsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), 0$selectedFacets$sortBy$sortOrder);
  865.         $variants = [];
  866.         if (count($results['hits']['hits']) > 0) {
  867.             $variants $productVariantRepository->findByIdsAndOrderByFieldId(array_map(function ($row) {
  868.                 return str_ireplace('VARIANT_'''$row['_id']);
  869.             }, $results['hits']['hits']));
  870.         }
  871.         // Récupère les liens pour la partie référencement
  872.         $referencementllinks = [];
  873.         if (!empty($taxon->getSeoLinks())) {
  874.             $referencementllinks $taxonRepository->findBy([
  875.                 'id' => $taxon->getSeoLinks()
  876.             ]);
  877.         }       
  878.         
  879.         // return new JsonResponse([
  880.         //     'variants' => $twigEnvironment->render('taxons/taxon_list_products_ajax.html.twig', [
  881.         //         'variants' => $variants,
  882.         //         'taxon' => $taxon
  883.         //     ]),
  884.         //     'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS,
  885.         //     'totalResults' => $results['hits']['total']['value'],
  886.         // ]); 
  887.         
  888.         // Catégorie de "niveau 3"
  889.         return $this->render('site_taxon_lastlevel_show.html.twig', [
  890.             'taxon' => $taxon,
  891.             'referencementllinks' => $referencementllinks,
  892.             'variants' => $variants,
  893.             'selectedFacets' => $selectedFacets,
  894.             'siteFilterShape' => $siteFilterShape,
  895.             'siteFilterColor' => $siteFilterColor,
  896.             'siteFilterBadge' => $siteFilterBadge,
  897.             'siteFilterFacets' => $siteFilterFacets,
  898.             'siteFilterFacetsValues' => $siteFilterFacetsValues,
  899.             'siteFilterMinPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MIN]['value'],
  900.             'siteFilterMaxPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MAX]['value'],
  901.             'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS,
  902.             'totalResults' => $results['hits']['total']['value'],
  903.             'filtreUrl' => $filtreUrl,
  904.             'noindex' =>  $noindex,
  905.             'metaFiltre' =>  $meta_filtre,
  906.             
  907.         ]);
  908.     }
  909.     public function tissuLevel2Action(
  910.         Request $request,
  911.         LocaleContextInterface $localeContext,
  912.         TaxonRepositoryInterface $taxonRepository,
  913.         ProductRepositoryInterface $productRepository,
  914.         ProductVariantRepositoryInterface $productVariantRepository,
  915.         ProductAttributeValueRepositoryInterface $productAttributeValueRepository,
  916.         ElasticSearchService $elasticSearch,
  917.         Breadcrumbs $breadcrumbs,
  918.         $cat1,
  919.     ) {
  920.        
  921.         $slug 'tissus-et-petite-mercerie/'.$cat1;
  922.         //si filtre deja engagé
  923.         $filtreUrl '';
  924.         if(!empty($request->get('filtre')) && !empty($request->get('filtrevalue'))){
  925.             $filtreUrl $request->get('filtre').'/'.$request->get('filtrevalue');
  926.         }
  927.         // Récupère la catégorie
  928.         $taxon $taxonRepository->findOneBySlug($slug$localeContext->getLocaleCode());      
  929.        
  930.         if (empty($taxon)) {
  931.             // return;
  932.             throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
  933.         }
  934.         // Fil d'ariane
  935.         $taxonParent $taxon;
  936.         while ($taxonParent != $taxon->getRoot()) {
  937.             $breadcrumbs->prependRouteItem($taxonParent"sylius_shop_product_index", [
  938.                 'slug' => $taxonParent->getSlug()
  939.             ]);
  940.             $taxonParent $taxonParent->getParent();
  941.         }
  942.         $breadcrumbs->prependRouteItem($taxon->getRoot()->getName(), "sylius_shop_product_index", [
  943.             'slug' => $taxon->getRoot()->getSlug()
  944.         ]);
  945.         $breadcrumbs->prependRouteItem("sylius.ui.home""sylius_shop_homepage");
  946.         $em $this->get('doctrine')->getManager();
  947.         // Récupère les articles dans la catégorie d'articles associé
  948.         $articles = [];
  949.         if (empty($taxon->getSingleArticleCategory()) == false) {
  950.             $articles $em->getRepository(SiteArticle::class)
  951.             ->createQueryBuilder('a')
  952.             ->where('a.articleCategory = :category')
  953.             ->andWhere('a.dateDiffusion < :today')
  954.             ->setParameter('today'date("Y-m-d H:i:s"))
  955.             ->orderBy('a.createdAt''DESC')
  956.             ->setParameter('category'$taxon->getSingleArticleCategory())
  957.             ->getQuery()
  958.             ->getResult();
  959.         }
  960.         // Récupère tous les filtres à facettes disponible pour 
  961.         // cette "recherche"
  962.         $siteFilterFacets $em->getRepository(SiteFilterFacet::class)
  963.         ->findBy([
  964.             'enabled' => true
  965.         ], [
  966.             'position' => 'ASC'
  967.         ]);
  968.         $esAggregations $elasticSearch->getFilterFacetsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), array_map(function ($row) {
  969.             return $row->getId();
  970.         }, $siteFilterFacets));
  971.       
  972.         $siteFilterShape = [];
  973.         if (count($esAggregations['shape']['buckets']) > 1) {
  974.             $siteFilterShape $productRepository->findBy([
  975.                 'id' => array_map(function ($row) {
  976.                     return $row['key'];
  977.                 }, $esAggregations['shape']['buckets']),
  978.                 'enabled' => true
  979.             ], [
  980.                 'code' => 'ASC'
  981.             ]);
  982.             usort($siteFilterShape, function ($a$b) {
  983.                 // dump($a->getTranslation()->getName());
  984.                
  985.                 return strcmp(str_replace('É''e',$a->getTranslation()->getName()) , str_replace('É''e'$b->getTranslation()->getName()) );
  986.             });
  987.         }
  988.         $siteFilterColor = [];
  989.         if (count($esAggregations['color']['buckets']) > 1) {
  990.             $siteFilterColor $em->getRepository(SiteCollection::class)->findBy([
  991.                 'productOptionValue' => array_map(function ($row) {
  992.                     return $row['key'];
  993.                 }, $esAggregations['color']['buckets']),
  994.             ]);
  995.         }
  996.         usort($siteFilterColor, function($a$b) {
  997.             return $a->getDateRelease() < $b->getDateRelease();
  998.         });
  999.         $siteFilterFacetsValues = [];
  1000.         foreach ($esAggregations as $keyEsAggregation => $rowEsAggregation) {
  1001.             if (isset($rowEsAggregation['buckets']) && count($rowEsAggregation['buckets']) > 1) {
  1002.                 $siteFilterFacetsValues[$keyEsAggregation] = array_map(function ($row) {
  1003.                     return $row['key'];
  1004.                 }, $rowEsAggregation['buckets']);
  1005.                 // On met dans l'ordre alphabétique
  1006.                 sort($siteFilterFacetsValues[$keyEsAggregation]);
  1007.             }
  1008.         }
  1009.         // dump($siteFilterFacetsValues) ;
  1010.         // Conserve que les filtres à facettes disponible pour cette recherche
  1011.         $siteFilterFacets array_filter($siteFilterFacets, function ($row) use (&$siteFilterFacetsValues) {
  1012.             return in_array($row->getId(), array_keys($siteFilterFacetsValues));
  1013.         });
  1014.       
  1015.         // Récupère tous les produits dans cette catégorie avec 
  1016.         // l'applique du filtre à facette et/ou de l'ordre 
  1017.         $sorting $request->query->get('sorting');
  1018.         $sortBy null;
  1019.         $sortOrder null;
  1020.         if (is_array($sorting)) {
  1021.             $sortBy key($sorting);
  1022.             $sortOrder $sorting[key($sorting)];
  1023.         }
  1024.         $selectedFacets = (array) $request->query->get('facets', []);
  1025.         $results $elasticSearch->getElementsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), 0$selectedFacets$sortBy$sortOrder);
  1026.         $variants = [];
  1027.         if (count($results['hits']['hits']) > 0) {
  1028.             $variants $productVariantRepository->findByIdsAndOrderByFieldId(array_map(function ($row) {
  1029.                 return str_ireplace('VARIANT_'''$row['_id']);
  1030.             }, $results['hits']['hits']));
  1031.         }
  1032.         // Récupère les liens pour la partie référencement
  1033.         $referencementllinks = [];
  1034.         if (!empty($taxon->getSeoLinks())) {
  1035.             $referencementllinks $taxonRepository->findBy([
  1036.                 'id' => $taxon->getSeoLinks()
  1037.             ]);
  1038.         }       
  1039.         return $this->render('site_taxon_level2_show.html.twig', [
  1040.             'taxon' => $taxon,
  1041.             'referencementllinks' => $referencementllinks,
  1042.             'variants' => $variants,
  1043.             'articles' => $articles,
  1044.             'selectedFacets' => $selectedFacets,
  1045.             'siteFilterShape' => $siteFilterShape,
  1046.             'siteFilterColor' => $siteFilterColor,
  1047.             'siteFilterFacets' => $siteFilterFacets,
  1048.             'siteFilterFacetsValues' => $siteFilterFacetsValues,
  1049.             'siteFilterMinPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MIN]['value'],
  1050.             'siteFilterMaxPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MAX]['value'],
  1051.             'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS,
  1052.             'totalResults' => $results['hits']['total']['value'],
  1053.             'filtreUrl' => $filtreUrl
  1054.         ]);
  1055.     }
  1056.     public function tissuLevel3Action(
  1057.         Request $request,
  1058.         LocaleContextInterface $localeContext,
  1059.         TaxonRepositoryInterface $taxonRepository,
  1060.         ProductRepositoryInterface $productRepository,
  1061.         ProductVariantRepositoryInterface $productVariantRepository,
  1062.         ProductAttributeValueRepositoryInterface $productAttributeValueRepository,
  1063.         ElasticSearchService $elasticSearch,
  1064.         Breadcrumbs $breadcrumbs,
  1065.         TranslatorInterface $translator,
  1066.         $cat1,
  1067.         $cat2,
  1068.     ) {
  1069.       
  1070.         
  1071.         $slug 'tissus-et-petite-mercerie/'.$cat1.'/'.$cat2;
  1072.         //si filtre deja engagé
  1073.         $filtreUrl '';
  1074.         if(!empty($request->get('filtre')) && !empty($request->get('filtrevalue'))){
  1075.             $filtreUrl $request->get('filtre').'/'.$request->get('filtrevalue');
  1076.         }
  1077.         // Récupère la catégorie
  1078.         $taxon $taxonRepository->findOneBySlug($slug$localeContext->getLocaleCode());      
  1079.        
  1080.         if (empty($taxon)) {
  1081.             // return;
  1082.             throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
  1083.         }
  1084.         // Fil d'ariane
  1085.         $taxonParent $taxon;
  1086.         while ($taxonParent != $taxon->getRoot()) {
  1087.             $breadcrumbs->prependRouteItem($taxonParent"sylius_shop_product_index", [
  1088.                 'slug' => $taxonParent->getSlug()
  1089.             ]);
  1090.             $taxonParent $taxonParent->getParent();
  1091.         }
  1092.         $breadcrumbs->prependRouteItem($taxon->getRoot()->getName(), "sylius_shop_product_index", [
  1093.             'slug' => $taxon->getRoot()->getSlug()
  1094.         ]);
  1095.         $breadcrumbs->prependRouteItem("sylius.ui.home""sylius_shop_homepage");
  1096.         $em $this->get('doctrine')->getManager();
  1097.         // Récupère les articles dans la catégorie d'articles associé
  1098.         $articles = [];
  1099.         if (empty($taxon->getSingleArticleCategory()) == false) {
  1100.             $articles $em->getRepository(SiteArticle::class)
  1101.             ->createQueryBuilder('a')
  1102.             ->where('a.articleCategory = :category')
  1103.             ->andWhere('a.dateDiffusion < :today')
  1104.             ->setParameter('today'date("Y-m-d H:i:s"))
  1105.             ->orderBy('a.createdAt''DESC')
  1106.             ->setParameter('category'$taxon->getSingleArticleCategory())
  1107.             ->getQuery()
  1108.             ->getResult();
  1109.         }
  1110.         // Récupère tous les filtres à facettes disponible pour 
  1111.         // cette "recherche"
  1112.         $siteFilterFacets $em->getRepository(SiteFilterFacet::class)
  1113.         ->findBy([
  1114.             'enabled' => true
  1115.         ], [
  1116.             'position' => 'ASC'
  1117.         ]);
  1118.         $esAggregations $elasticSearch->getFilterFacetsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), array_map(function ($row) {
  1119.             return $row->getId();
  1120.         }, $siteFilterFacets));
  1121.       
  1122.         $siteFilterShape = [];
  1123.         if (count($esAggregations['shape']['buckets']) > 1) {
  1124.             $siteFilterShape $productRepository->findBy([
  1125.                 'id' => array_map(function ($row) {
  1126.                     return $row['key'];
  1127.                 }, $esAggregations['shape']['buckets']),
  1128.                 'enabled' => true
  1129.             ], [
  1130.                 'code' => 'ASC'
  1131.             ]);
  1132.             usort($siteFilterShape, function ($a$b) {
  1133.                 // dump($a->getTranslation()->getName());
  1134.                
  1135.                 return strcmp(str_replace('É''e',$a->getTranslation()->getName()) , str_replace('É''e'$b->getTranslation()->getName()) );
  1136.             });
  1137.         }
  1138.         $siteFilterColor = [];
  1139.         if (count($esAggregations['color']['buckets']) > 1) {
  1140.             $siteFilterColor $em->getRepository(SiteCollection::class)->findBy([
  1141.                 'productOptionValue' => array_map(function ($row) {
  1142.                     return $row['key'];
  1143.                 }, $esAggregations['color']['buckets']),
  1144.             ]);
  1145.         }
  1146.         usort($siteFilterColor, function($a$b) {
  1147.             return $a->getDateRelease() < $b->getDateRelease();
  1148.         });
  1149.         $siteFilterFacetsValues = [];
  1150.         foreach ($esAggregations as $keyEsAggregation => $rowEsAggregation) {
  1151.             if (isset($rowEsAggregation['buckets']) && count($rowEsAggregation['buckets']) > 1) {
  1152.                 $siteFilterFacetsValues[$keyEsAggregation] = array_map(function ($row) {
  1153.                     return $row['key'];
  1154.                 }, $rowEsAggregation['buckets']);
  1155.                 // On met dans l'ordre alphabétique
  1156.                 sort($siteFilterFacetsValues[$keyEsAggregation]);
  1157.             }
  1158.         }
  1159.         // dump($siteFilterFacetsValues) ;
  1160.         // Conserve que les filtres à facettes disponible pour cette recherche
  1161.         $siteFilterFacets array_filter($siteFilterFacets, function ($row) use (&$siteFilterFacetsValues) {
  1162.             return in_array($row->getId(), array_keys($siteFilterFacetsValues));
  1163.         });
  1164.         $siteFilterBadge = [];
  1165.         $siteFilterBadgeVariants = [];
  1166.         if (count($esAggregations['badge']['buckets']) > 1) {
  1167.             $siteFilterBadgeVariants $productVariantRepository->findBy([
  1168.                 'badge' => array_map(function ($row) {
  1169.                     return $row['key'];
  1170.                 }, $esAggregations['badge']['buckets']),
  1171.                 'enabled' => true
  1172.             ], [
  1173.                 'code' => 'ASC'
  1174.             ]);
  1175.             
  1176.             if(count($siteFilterBadgeVariants) > 0){
  1177.                 foreach($siteFilterBadgeVariants as $siteFilterBadgeVariant){
  1178.                     $siteFilterBadge[$siteFilterBadgeVariant->getBadge()] = array(
  1179.                         'name' => $translator->trans("app.ui.product_callout.".$siteFilterBadgeVariant->getBadge()),
  1180.                         'id' => $siteFilterBadgeVariant->getBadge(),
  1181.                     );
  1182.                 }
  1183.             }
  1184.         }
  1185.       
  1186.         // Récupère tous les produits dans cette catégorie avec 
  1187.         // l'applique du filtre à facette et/ou de l'ordre 
  1188.         $sorting $request->query->get('sorting');
  1189.         $sortBy null;
  1190.         $sortOrder null;
  1191.         if (is_array($sorting)) {
  1192.             $sortBy key($sorting);
  1193.             $sortOrder $sorting[key($sorting)];
  1194.         }
  1195.         $selectedFacets = (array) $request->query->get('facets', []);
  1196.         $results $elasticSearch->getElementsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), 0$selectedFacets$sortBy$sortOrder);
  1197.         $variants = [];
  1198.         if (count($results['hits']['hits']) > 0) {
  1199.             $variants $productVariantRepository->findByIdsAndOrderByFieldId(array_map(function ($row) {
  1200.                 return str_ireplace('VARIANT_'''$row['_id']);
  1201.             }, $results['hits']['hits']));
  1202.         }
  1203.         // Récupère les liens pour la partie référencement
  1204.         $referencementllinks = [];
  1205.         if (!empty($taxon->getSeoLinks())) {
  1206.             $referencementllinks $taxonRepository->findBy([
  1207.                 'id' => $taxon->getSeoLinks()
  1208.             ]);
  1209.         }       
  1210.         return $this->render('site_taxon_level2_show.html.twig', [
  1211.             'taxon' => $taxon,
  1212.             'referencementllinks' => $referencementllinks,
  1213.             'variants' => $variants,
  1214.             'articles' => $articles,
  1215.             'selectedFacets' => $selectedFacets,
  1216.             'siteFilterShape' => $siteFilterShape,
  1217.             'siteFilterColor' => $siteFilterColor,
  1218.             'siteFilterFacets' => $siteFilterFacets,
  1219.             'siteFilterFacetsValues' => $siteFilterFacetsValues,
  1220.             'siteFilterMinPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MIN]['value'],
  1221.             'siteFilterMaxPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MAX]['value'],
  1222.             'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS,
  1223.             'totalResults' => $results['hits']['total']['value'],
  1224.             'filtreUrl' => $filtreUrl
  1225.         ]);
  1226.     }
  1227.     function replaceSpecialChar($str) {
  1228.         $ch0 = array( 
  1229.                 "œ"=>"oe",
  1230.                 "Œ"=>"OE",
  1231.                 "æ"=>"ae",
  1232.                 "Æ"=>"AE",
  1233.                 "À" => "A",
  1234.                 "Á" => "A",
  1235.                 "Â" => "A",
  1236.                 "à" => "A",
  1237.                 "Ä" => "A",
  1238.                 "Å" => "A",
  1239.                 "&#256;" => "A",
  1240.                 "&#258;" => "A",
  1241.                 "&#461;" => "A",
  1242.                 "&#7840;" => "A",
  1243.                 "&#7842;" => "A",
  1244.                 "&#7844;" => "A",
  1245.                 "&#7846;" => "A",
  1246.                 "&#7848;" => "A",
  1247.                 "&#7850;" => "A",
  1248.                 "&#7852;" => "A",
  1249.                 "&#7854;" => "A",
  1250.                 "&#7856;" => "A",
  1251.                 "&#7858;" => "A",
  1252.                 "&#7860;" => "A",
  1253.                 "&#7862;" => "A",
  1254.                 "&#506;" => "A",
  1255.                 "&#260;" => "A",
  1256.                 "à" => "a",
  1257.                 "á" => "a",
  1258.                 "â" => "a",
  1259.                 "à" => "a",
  1260.                 "ä" => "a",
  1261.                 "å" => "a",
  1262.                 "&#257;" => "a",
  1263.                 "&#259;" => "a",
  1264.                 "&#462;" => "a",
  1265.                 "&#7841;" => "a",
  1266.                 "&#7843;" => "a",
  1267.                 "&#7845;" => "a",
  1268.                 "&#7847;" => "a",
  1269.                 "&#7849;" => "a",
  1270.                 "&#7851;" => "a",
  1271.                 "&#7853;" => "a",
  1272.                 "&#7855;" => "a",
  1273.                 "&#7857;" => "a",
  1274.                 "&#7859;" => "a",
  1275.                 "&#7861;" => "a",
  1276.                 "&#7863;" => "a",
  1277.                 "&#507;" => "a",
  1278.                 "&#261;" => "a",
  1279.                 "Ç" => "C",
  1280.                 "&#262;" => "C",
  1281.                 "&#264;" => "C",
  1282.                 "&#266;" => "C",
  1283.                 "&#268;" => "C",
  1284.                 "ç" => "c",
  1285.                 "&#263;" => "c",
  1286.                 "&#265;" => "c",
  1287.                 "&#267;" => "c",
  1288.                 "&#269;" => "c",
  1289.                 "Ð" => "D",
  1290.                 "&#270;" => "D",
  1291.                 "&#272;" => "D",
  1292.                 "&#271;" => "d",
  1293.                 "&#273;" => "d",
  1294.                 "È" => "E",
  1295.                 "É" => "E",
  1296.                 "Ê" => "E",
  1297.                 "Ë" => "E",
  1298.                 "&#274;" => "E",
  1299.                 "&#276;" => "E",
  1300.                 "&#278;" => "E",
  1301.                 "&#280;" => "E",
  1302.                 "&#282;" => "E",
  1303.                 "&#7864;" => "E",
  1304.                 "&#7866;" => "E",
  1305.                 "&#7868;" => "E",
  1306.                 "&#7870;" => "E",
  1307.                 "&#7872;" => "E",
  1308.                 "&#7874;" => "E",
  1309.                 "&#7876;" => "E",
  1310.                 "&#7878;" => "E",
  1311.                 "è" => "e",
  1312.                 "é" => "e",
  1313.                 "ê" => "e",
  1314.                 "ë" => "e",
  1315.                 "&#275;" => "e",
  1316.                 "&#277;" => "e",
  1317.                 "&#279;" => "e",
  1318.                 "&#281;" => "e",
  1319.                 "&#283;" => "e",
  1320.                 "&#7865;" => "e",
  1321.                 "&#7867;" => "e",
  1322.                 "&#7869;" => "e",
  1323.                 "&#7871;" => "e",
  1324.                 "&#7873;" => "e",
  1325.                 "&#7875;" => "e",
  1326.                 "&#7877;" => "e",
  1327.                 "&#7879;" => "e",
  1328.                 "&#284;" => "G",
  1329.                 "&#286;" => "G",
  1330.                 "&#288;" => "G",
  1331.                 "&#290;" => "G",
  1332.                 "&#285;" => "g",
  1333.                 "&#287;" => "g",
  1334.                 "&#289;" => "g",
  1335.                 "&#291;" => "g",
  1336.                 "&#292;" => "H",
  1337.                 "&#294;" => "H",
  1338.                 "&#293;" => "h",
  1339.                 "&#295;" => "h",
  1340.                 "Ì" => "I",
  1341.                 "Í" => "I",
  1342.                 "Î" => "I",
  1343.                 "Ï" => "I",
  1344.                 "&#296;" => "I",
  1345.                 "&#298;" => "I",
  1346.                 "&#300;" => "I",
  1347.                 "&#302;" => "I",
  1348.                 "&#304;" => "I",
  1349.                 "&#463;" => "I",
  1350.                 "&#7880;" => "I",
  1351.                 "&#7882;" => "I",
  1352.                 "&#308;" => "J",
  1353.                 "&#309;" => "j",
  1354.                 "&#310;" => "K",
  1355.                 "&#311;" => "k",
  1356.                 "&#313;" => "L",
  1357.                 "&#315;" => "L",
  1358.                 "&#317;" => "L",
  1359.                 "&#319;" => "L",
  1360.                 "&#321;" => "L",
  1361.                 "&#314;" => "l",
  1362.                 "&#316;" => "l",
  1363.                 "&#318;" => "l",
  1364.                 "&#320;" => "l",
  1365.                 "&#322;" => "l",
  1366.                 "Ñ" => "N",
  1367.                 "&#323;" => "N",
  1368.                 "&#325;" => "N",
  1369.                 "&#327;" => "N",
  1370.                 "ñ" => "n",
  1371.                 "&#324;" => "n",
  1372.                 "&#326;" => "n",
  1373.                 "&#328;" => "n",
  1374.                 "&#329;" => "n",
  1375.                 "Ò" => "O",
  1376.                 "Ó" => "O",
  1377.                 "Ô" => "O",
  1378.                 "Õ" => "O",
  1379.                 "Ö" => "O",
  1380.                 "Ø" => "O",
  1381.                 "&#332;" => "O",
  1382.                 "&#334;" => "O",
  1383.                 "&#336;" => "O",
  1384.                 "&#416;" => "O",
  1385.                 "&#465;" => "O",
  1386.                 "&#510;" => "O",
  1387.                 "&#7884;" => "O",
  1388.                 "&#7886;" => "O",
  1389.                 "&#7888;" => "O",
  1390.                 "&#7890;" => "O",
  1391.                 "&#7892;" => "O",
  1392.                 "&#7894;" => "O",
  1393.                 "&#7896;" => "O",
  1394.                 "&#7898;" => "O",
  1395.                 "&#7900;" => "O",
  1396.                 "&#7902;" => "O",
  1397.                 "&#7904;" => "O",
  1398.                 "&#7906;" => "O",
  1399.                 "ò" => "o",
  1400.                 "ó" => "o",
  1401.                 "ô" => "o",
  1402.                 "õ" => "o",
  1403.                 "ö" => "o",
  1404.                 "ø" => "o",
  1405.                 "&#333;" => "o",
  1406.                 "&#335;" => "o",
  1407.                 "&#337;" => "o",
  1408.                 "&#417;" => "o",
  1409.                 "&#466;" => "o",
  1410.                 "&#511;" => "o",
  1411.                 "&#7885;" => "o",
  1412.                 "&#7887;" => "o",
  1413.                 "&#7889;" => "o",
  1414.                 "&#7891;" => "o",
  1415.                 "&#7893;" => "o",
  1416.                 "&#7895;" => "o",
  1417.                 "&#7897;" => "o",
  1418.                 "&#7899;" => "o",
  1419.                 "&#7901;" => "o",
  1420.                 "&#7903;" => "o",
  1421.                 "&#7905;" => "o",
  1422.                 "&#7907;" => "o",
  1423.                 "ð" => "o",
  1424.                 "&#340;" => "R",
  1425.                 "&#342;" => "R",
  1426.                 "&#344;" => "R",
  1427.                 "&#341;" => "r",
  1428.                 "&#343;" => "r",
  1429.                 "&#345;" => "r",
  1430.                 "&#346;" => "S",
  1431.                 "&#348;" => "S",
  1432.                 "&#350;" => "S",
  1433.                 "&#347;" => "s",
  1434.                 "&#349;" => "s",
  1435.                 "&#351;" => "s",
  1436.                 "&#354;" => "T",
  1437.                 "&#356;" => "T",
  1438.                 "&#358;" => "T",
  1439.                 "&#355;" => "t",
  1440.                 "&#357;" => "t",
  1441.                 "&#359;" => "t",
  1442.                 "Ù" => "U",
  1443.                 "Ú" => "U",
  1444.                 "Û" => "U",
  1445.                 "Ü" => "U",
  1446.                 "&#360;" => "U",
  1447.                 "&#362;" => "U",
  1448.                 "&#364;" => "U",
  1449.                 "&#366;" => "U",
  1450.                 "&#368;" => "U",
  1451.                 "&#370;" => "U",
  1452.                 "&#431;" => "U",
  1453.                 "&#467;" => "U",
  1454.                 "&#469;" => "U",
  1455.                 "&#471;" => "U",
  1456.                 "&#473;" => "U",
  1457.                 "&#475;" => "U",
  1458.                 "&#7908;" => "U",
  1459.                 "&#7910;" => "U",
  1460.                 "&#7912;" => "U",
  1461.                 "&#7914;" => "U",
  1462.                 "&#7916;" => "U",
  1463.                 "&#7918;" => "U",
  1464.                 "&#7920;" => "U",
  1465.                 "ù" => "u",
  1466.                 "ú" => "u",
  1467.                 "û" => "u",
  1468.                 "ü" => "u",
  1469.                 "&#361;" => "u",
  1470.                 "&#363;" => "u",
  1471.                 "&#365;" => "u",
  1472.                 "&#367;" => "u",
  1473.                 "&#369;" => "u",
  1474.                 "&#371;" => "u",
  1475.                 "&#432;" => "u",
  1476.                 "&#468;" => "u",
  1477.                 "&#470;" => "u",
  1478.                 "&#472;" => "u",
  1479.                 "&#474;" => "u",
  1480.                 "&#476;" => "u",
  1481.                 "&#7909;" => "u",
  1482.                 "&#7911;" => "u",
  1483.                 "&#7913;" => "u",
  1484.                 "&#7915;" => "u",
  1485.                 "&#7917;" => "u",
  1486.                 "&#7919;" => "u",
  1487.                 "&#7921;" => "u",
  1488.                 "&#372;" => "W",
  1489.                 "&#7808;" => "W",
  1490.                 "&#7810;" => "W",
  1491.                 "&#7812;" => "W",
  1492.                 "&#373;" => "w",
  1493.                 "&#7809;" => "w",
  1494.                 "&#7811;" => "w",
  1495.                 "&#7813;" => "w",
  1496.                 "Ý" => "Y",
  1497.                 "&#374;" => "Y",
  1498.                 "?" => "Y",
  1499.                 "&#7922;" => "Y",
  1500.                 "&#7928;" => "Y",
  1501.                 "&#7926;" => "Y",
  1502.                 "&#7924;" => "Y",
  1503.                 "ý" => "y",
  1504.                 "ÿ" => "y",
  1505.                 "&#375;" => "y",
  1506.                 "&#7929;" => "y",
  1507.                 "&#7925;" => "y",
  1508.                 "&#7927;" => "y",
  1509.                 "&#7923;" => "y",
  1510.                 "&#377;" => "Z",
  1511.                 "&#379;" => "Z",
  1512.                 '+'         =>'',
  1513.                 "'"        =>'',
  1514.                 ' '        =>'-',
  1515.                 '.'        =>'-',
  1516.                 );
  1517.             $str strtr($str,$ch0);
  1518.             return $str;
  1519.         
  1520.     }
  1521. }