<?php
declare(strict_types=1);
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Sylius\Component\Locale\Context\LocaleContextInterface;
use Sylius\Component\Taxonomy\Repository\TaxonRepositoryInterface;
use Sylius\Component\Core\Repository\ProductRepositoryInterface;
use Sylius\Component\Core\Repository\ProductVariantRepositoryInterface;
use Sylius\Component\Product\Repository\ProductAttributeValueRepositoryInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use WhiteOctober\BreadcrumbsBundle\Model\Breadcrumbs;
use App\Services\ElasticSearchService;
use App\Entity\SiteArticle;
use App\Entity\SiteCollection;
use App\Entity\SiteFilterFacet;
use Symfony\Component\HttpFoundation\JsonResponse;
use Twig\Environment;
use Symfony\Contracts\Translation\TranslatorInterface;
class TaxonController extends AbstractController
{
/**
* Page catégorie
*/
public function indexAction(
Request $request,
LocaleContextInterface $localeContext,
TaxonRepositoryInterface $taxonRepository,
ProductRepositoryInterface $productRepository,
ProductVariantRepositoryInterface $productVariantRepository,
ProductAttributeValueRepositoryInterface $productAttributeValueRepository,
ElasticSearchService $elasticSearch,
Breadcrumbs $breadcrumbs,
TranslatorInterface $translator,
$slug
) {
$em = $this->get('doctrine')->getManager();
// Récupère la catégorie
$taxon = $taxonRepository->findOneBySlug($slug, $localeContext->getLocaleCode());
if (empty($taxon)) {
// return;
// dump($localeContext->getLocaleCode());
if (str_contains( $slug, 'nos-produits') && $localeContext->getLocaleCode() == 'en_US') {
$taxon = $taxonRepository->findOneBySlug($slug, 'fr_FR');
if (!empty($taxon)) {
$conn = $em->getConnection();
$sql = '
SELECT * FROM sylius_taxon_translation
WHERE translatable_id = :translatable_id
AND locale = "en_US"
';
$stmt = $conn->prepare($sql);
$resultSet = $stmt->executeQuery(['translatable_id' => $taxon->getId()]);
// returns an array of arrays (i.e. a raw data set)
$result = $resultSet->fetchAllAssociative();
if(count($result) > 0){
return $this->redirectToRoute('sylius_shop_product_index', ['slug' => $result[0]['slug']]);
}else{
throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
}
// return $this->redirect('http://symfony.com/doc');
}else{
throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
}
}elseif(str_contains( $slug, 'our-products') && $localeContext->getLocaleCode() == 'fr_FR'){
$taxon = $taxonRepository->findOneBySlug($slug, 'en_US');
if (!empty($taxon)) {
$conn = $em->getConnection();
$sql = '
SELECT * FROM sylius_taxon_translation
WHERE translatable_id = :translatable_id
AND locale = "fr_FR"
';
$stmt = $conn->prepare($sql);
$resultSet = $stmt->executeQuery(['translatable_id' => $taxon->getId()]);
// returns an array of arrays (i.e. a raw data set)
$result = $resultSet->fetchAllAssociative();
if(count($result) > 0){
return $this->redirectToRoute('sylius_shop_product_index', ['slug' => $result[0]['slug']]);
}else{
throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
}
// return $this->redirect('http://symfony.com/doc');
}else{
throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
}
}elseif(str_contains( $slug, 'fabrics-and-small-haberdashery') && $localeContext->getLocaleCode() == 'fr_FR'){
$taxon = $taxonRepository->findOneBySlug($slug, 'en_US');
if (!empty($taxon)) {
$conn = $em->getConnection();
$sql = '
SELECT * FROM sylius_taxon_translation
WHERE translatable_id = :translatable_id
AND locale = "fr_FR"
';
$stmt = $conn->prepare($sql);
$resultSet = $stmt->executeQuery(['translatable_id' => $taxon->getId()]);
// returns an array of arrays (i.e. a raw data set)
$result = $resultSet->fetchAllAssociative();
if(count($result) > 0){
return $this->redirectToRoute('sylius_shop_product_index', ['slug' => $result[0]['slug']]);
}else{
throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
}
// return $this->redirect('http://symfony.com/doc');
}else{
throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
}
}elseif(str_contains( $slug, 'tissus-et-petite-mercerie') && $localeContext->getLocaleCode() == 'en_US'){
$taxon = $taxonRepository->findOneBySlug($slug, 'fr_FR');
if (!empty($taxon)) {
$conn = $em->getConnection();
$sql = '
SELECT * FROM sylius_taxon_translation
WHERE translatable_id = :translatable_id
AND locale = "en_US"
';
$stmt = $conn->prepare($sql);
$resultSet = $stmt->executeQuery(['translatable_id' => $taxon->getId()]);
// returns an array of arrays (i.e. a raw data set)
$result = $resultSet->fetchAllAssociative();
if(count($result) > 0){
return $this->redirectToRoute('sylius_shop_product_index', ['slug' => $result[0]['slug']]);
}else{
throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
}
// return $this->redirect('http://symfony.com/doc');
}else{
throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
}
}else{
throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
}
}
// Fil d'ariane
$taxonParent = $taxon;
// dump( $taxonParent);
// dump( $taxon->getRoot());
while ($taxonParent->getId() != $taxon->getRoot()->getId()) {
// dump( $taxonParent);
$breadcrumbs->prependRouteItem($taxonParent, "sylius_shop_product_index", [
'slug' => $taxonParent->getSlug()
]);
// dump( $taxonParent);
$taxonParent = $taxonParent->getParent();
}
$breadcrumbs->prependRouteItem($taxon->getRoot()->getName(), "sylius_shop_product_index", [
'slug' => $taxon->getRoot()->getSlug()
]);
$breadcrumbs->prependRouteItem("sylius.ui.home", "sylius_shop_homepage");
// Catégorie de "niveau 1" - On affiche uniquement les sous catégories
if ($taxon->getLevel() == 0) {
// foreach($taxon->getChildren() as $child){
// dump($child->getSlug());
// }
return $this->render('site_taxon_level1_show.html.twig', [
'taxon' => $taxon
]);
}
$em = $this->get('doctrine')->getManager();
// Récupère les articles dans la catégorie d'articles associé
$articles = [];
if (empty($taxon->getSingleArticleCategory()) == false) {
$articles = $em->getRepository(SiteArticle::class)
->createQueryBuilder('a')
->where('a.articleCategory = :category')
->andWhere('a.dateDiffusion < :today')
->setParameter('today', date("Y-m-d H:i:s"))
->orderBy('a.createdAt', 'DESC')
->setParameter('category', $taxon->getSingleArticleCategory())
->getQuery()
->getResult();
}
// Récupère tous les filtres à facettes disponible pour
// cette "recherche"
$siteFilterFacets = $em->getRepository(SiteFilterFacet::class)
->findBy([
'enabled' => true
], [
'position' => 'ASC'
]);
// dump($siteFilterFacets);
$esAggregations = $elasticSearch->getFilterFacetsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), array_map(function ($row) {
return $row->getId();
}, $siteFilterFacets));
dump( $esAggregations);
$siteFilterShape = [];
if (count($esAggregations['shape']['buckets']) > 1) {
$siteFilterShape = $productRepository->findBy([
'id' => array_map(function ($row) {
return $row['key'];
}, $esAggregations['shape']['buckets']),
'enabled' => true
], [
'code' => 'ASC'
]);
usort($siteFilterShape, function ($a, $b) {
// dump($a->getTranslation()->getName());
return strcmp(str_replace('É', 'e',$a->getTranslation()->getName()) , str_replace('É', 'e', $b->getTranslation()->getName()) );
});
}
dump($siteFilterShape);
// dump($esAggregations) ;
$siteFilterColor = [];
if (count($esAggregations['color']['buckets']) > 1) {
$siteFilterColor = $em->getRepository(SiteCollection::class)->findBy([
'productOptionValue' => array_map(function ($row) {
return $row['key'];
}, $esAggregations['color']['buckets']),
]);
}
usort($siteFilterColor, function($a, $b) {
return $a->getDateRelease() < $b->getDateRelease();
});
$siteFilterFacetsValues = [];
foreach ($esAggregations as $keyEsAggregation => $rowEsAggregation) {
// dump( $keyEsAggregation);
// dump( $rowEsAggregation);
if (isset($rowEsAggregation['buckets']) && count($rowEsAggregation['buckets']) > 1) {
$siteFilterFacetsValues[$keyEsAggregation] = array_map(function ($row) {
return $row['key'];
}, $rowEsAggregation['buckets']);
// On met dans l'ordre alphabétique
sort($siteFilterFacetsValues[$keyEsAggregation]);
}
}
dump( $siteFilterFacetsValues);
// Conserve que les filtres à facettes disponible pour cette recherche
$siteFilterFacets = array_filter($siteFilterFacets, function ($row) use (&$siteFilterFacetsValues) {
return in_array($row->getId(), array_keys($siteFilterFacetsValues));
});
$siteFilterBadge = [];
$siteFilterBadgeVariants = [];
if (count($esAggregations['badge']['buckets']) > 1) {
foreach($esAggregations['badge']['buckets'] as $badge){
$siteFilterBadge[] = array(
'name' => $translator->trans("app.ui.product_callout.".$badge['key']),
'id' => $badge['key'],
);
}
// $siteFilterBadgeVariants = $productVariantRepository->findBy([
// 'badge' => array_map(function ($row) {
// return $row['key'];
// }, $esAggregations['badge']['buckets']),
// 'enabled' => true
// ], [
// 'code' => 'ASC'
// ]);
// if(count($siteFilterBadgeVariants) > 0){
// foreach($siteFilterBadgeVariants as $siteFilterBadgeVariant){
// $siteFilterBadge[$siteFilterBadgeVariant->getBadge()] = array(
// 'name' => $translator->trans("app.ui.product_callout.".$siteFilterBadgeVariant->getBadge()),
// 'id' => $siteFilterBadgeVariant->getBadge(),
// );
// }
// }
}
// dump( $esAggregations);
// Récupère tous les produits dans cette catégorie avec
// l'applique du filtre à facette et/ou de l'ordre
$sorting = $request->query->get('sorting');
$sortBy = null;
$sortOrder = null;
if (is_array($sorting)) {
$sortBy = key($sorting);
$sortOrder = $sorting[key($sorting)];
}
$selectedFacets = (array) $request->query->get('facets', []);
$results = $elasticSearch->getElementsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), 0, $selectedFacets, $sortBy, $sortOrder);
$variants = [];
if (count($results['hits']['hits']) > 0) {
$variants = $productVariantRepository->findByIdsAndOrderByFieldId(array_map(function ($row) {
return str_ireplace('VARIANT_', '', $row['_id']);
}, $results['hits']['hits']));
}
dump($taxon->getLevel());
// Récupère les liens pour la partie référencement
$referencementllinks = [];
if (!empty($taxon->getSeoLinks())) {
$referencementllinks = $taxonRepository->findBy([
'id' => $taxon->getSeoLinks()
]);
}
// Catégorie de "niveau 2"
if ($taxon->getLevel() == 1) {
// Récupère les produits avec le badge "nouveau" de la catégorie
$newestProducts = $productVariantRepository->findNewestEnabledByTaxonsAndLocale(
array_merge(
[$taxon],
$taxonRepository->findAllChildren($taxon->getCode(), $localeContext->getLocaleCode())
),
$localeContext->getLocaleCode(),
10 // nombre de produits minimum avec le badge "newest"/"nouveauté"
);
// $newestProducts = [];
// dump($newestProducts );
// dump($localeContext->getLocaleCode());
if($localeContext->getLocaleCode() == 'fr_FR'){
$ctas = empty($taxon->getCtas()) ? $taxon->getRoot()->getCtas() : $taxon->getCtas();
}else{
$ctas = empty($taxon->getCtasEn()) ? $taxon->getRoot()->getCtasEn() : $taxon->getCtasEn();
}
return $this->render('site_taxon_level2_show.html.twig', [
'taxon' => $taxon,
'referencementllinks' => $referencementllinks,
'variants' => $variants,
'articles' => $articles,
'newestProducts' => $newestProducts,
'ctas' => $ctas,
'selectedFacets' => $selectedFacets,
'siteFilterShape' => $siteFilterShape,
'siteFilterColor' => $siteFilterColor,
'siteFilterBadge' => $siteFilterBadge,
'siteFilterFacets' => $siteFilterFacets,
'siteFilterFacetsValues' => $siteFilterFacetsValues,
'siteFilterMinPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MIN]['value'],
'siteFilterMaxPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MAX]['value'],
'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS,
'totalResults' => $results['hits']['total']['value'],
'filtreUrl' => ''
]);
}
// dump($siteFilterFacets);
// dump($siteFilterFacetsValues);
// Catégorie de "niveau 3"
return $this->render('site_taxon_lastlevel_show.html.twig', [
'taxon' => $taxon,
'referencementllinks' => $referencementllinks,
'variants' => $variants,
'selectedFacets' => $selectedFacets,
'siteFilterShape' => $siteFilterShape,
'siteFilterColor' => $siteFilterColor,
'siteFilterBadge' => $siteFilterBadge,
'siteFilterFacets' => $siteFilterFacets,
'siteFilterFacetsValues' => $siteFilterFacetsValues,
'siteFilterMinPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MIN]['value'],
'siteFilterMaxPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MAX]['value'],
'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS,
'totalResults' => $results['hits']['total']['value'],
'filtreUrl' => ''
]);
}
public function ajaxTaxonProductList(
Request $request,
ElasticSearchService $elasticSearch,
LocaleContextInterface $localeContext,
ProductVariantRepositoryInterface $productVariantRepository,
TaxonRepositoryInterface $taxonRepository,
Environment $twigEnvironment,
ProductRepositoryInterface $productRepository,
TranslatorInterface $translator,
$taxonId
) {
$tstart = microtime(true);
// Récupère la catégorie
$taxon = $taxonRepository->findOneById($taxonId);
if (empty($taxon)) {
return new Response('');
}
$t1 = microtime(true);
// OFFSET
$offset = intval($request->request->get('offset', 0));
$offset = min(max($offset, 0), ElasticSearchService::MAX_WINDOW_RESULTS - ElasticSearchService::MAX_SEARCH_RESULTS);
// SORT BY
$sorting = $request->request->get('sorting');
$sortBy = null;
$sortOrder = null;
if (is_array($sorting)) {
$sortBy = key($sorting);
$sortOrder = $sorting[key($sorting)];
}
$selectedFacets = (array) $request->request->get('facets', []);
$fromPage = $request->query->get('filtre');
// $selectedFacetsFromPage = array();
// if(!empty($fromPage)){
// // si badge
// if (str_contains( $fromPage, 'badge')) {
// $filtreArr = explode("=", $fromPage);
// $badge = $filtreArr[1];
// $selectedFacetsFromPage = ['badge' => $badge];
// }else{
// $selectedFacetsFromPage = $fromPage;
// }
// }
// if(count($selectedFacetsFromPage) > 0){
// $selectedFacets = array_merge($selectedFacets,$selectedFacetsFromPage);
// }
//
// dump($selectedFacets);
// dump($selectedFacetsFromPage);
// dump($selectedFacets);
$fromCat = $taxon->getId();
if(isset($selectedFacets['taxons'])){
foreach($selectedFacets['taxons'] as $taxonId){
//si recherche tissu, la cat de base est 222
$is_tissu = array(222, 223, 225, 226, 228, 229, 230, 231, 224, 234, 232, 233, 290, 285, 235);
if (in_array($taxonId, $is_tissu)) {
$fromCat = 222;
}
}
}
// die($fromCat.'aaa');
if(count($selectedFacets) == 0 && !empty($fromPage)){
$results = array();
}elseif($offset != 0){
$results = $elasticSearch->getElementsByTaxon($localeContext->getLocaleCode(), $fromCat, $offset, $selectedFacets, $sortBy, $sortOrder, false);
}else{
$results = $elasticSearch->getElementsByTaxon($localeContext->getLocaleCode(), $fromCat, $offset, $selectedFacets, $sortBy, $sortOrder, true);
}
$t2 = microtime(true);
// dump($fromCat);
$variants = [];
if (isset($results['hits']) && count($results['hits']['hits']) > 0) {
$variants = $productVariantRepository->findByIdsAndOrderByFieldId(array_map(function ($row) {
return str_ireplace('VARIANT_', '', $row['_id']);
}, $results['hits']['hits']));
}
$t3 = microtime(true);
$em = $this->get('doctrine')->getManager();
$siteFilterFacets = $em->getRepository(SiteFilterFacet::class)
->findBy([
'enabled' => true
], [
'position' => 'ASC'
]);
$t4 = microtime(true);
// dump($siteFilterFacets);
$esAggregations = $elasticSearch->getFilterFacetsByTaxon($localeContext->getLocaleCode(), $fromCat, array_map(function ($row) {
return $row->getId();
}, $siteFilterFacets));
// dump($taxon);
// dump($esAggregations) ;
$siteFilterFacetsValues = [];
foreach ($esAggregations as $keyEsAggregation => $rowEsAggregation) {
// dump( $keyEsAggregation);
// dump( $rowEsAggregation);
if (isset($rowEsAggregation['buckets']) && count($rowEsAggregation['buckets']) > 1) {
$siteFilterFacetsValues[$keyEsAggregation] = array_map(function ($row) {
return $row['key'];
}, $rowEsAggregation['buckets']);
// On met dans l'ordre alphabétique
sort($siteFilterFacetsValues[$keyEsAggregation]);
}
}
$t5 = microtime(true);
// dump($siteFilterFacetsValues);
// Conserve que les filtres à facettes disponible pour cette recherche
$siteFilterFacets = array_filter($siteFilterFacets, function ($row) use (&$siteFilterFacetsValues) {
return in_array($row->getId(), array_keys($siteFilterFacetsValues));
});
// dump($siteFilterFacets);
// dump($variants);
$t6 = microtime(true);
$siteFilterShape = [];
if (count($esAggregations['shape']['buckets']) > 1) {
$siteFilterShape = $productRepository->findBy([
'id' => array_map(function ($row) {
return $row['key'];
}, $esAggregations['shape']['buckets']),
'enabled' => true
], [
'code' => 'ASC'
]);
usort($siteFilterShape, function ($a, $b) {
// dump($a->getTranslation()->getName());
return strcmp(str_replace('É', 'e',$a->getTranslation()->getName()) , str_replace('É', 'e', $b->getTranslation()->getName()) );
});
}
$t7 = microtime(true);
dump($siteFilterShape);
$siteFilterColor = [];
if (count($esAggregations['color']['buckets']) > 1) {
$siteFilterColor = $em->getRepository(SiteCollection::class)->findBy([
'productOptionValue' => array_map(function ($row) {
return $row['key'];
}, $esAggregations['color']['buckets']),
]);
}
usort($siteFilterColor, function($a, $b) {
return $a->getDateRelease() < $b->getDateRelease();
});
$t8 = microtime(true);
$siteFilterBadge = [];
$siteFilterBadgeVariants = [];
if (count($esAggregations['badge']['buckets']) > 1) {
foreach($esAggregations['badge']['buckets'] as $badge){
$siteFilterBadge[] = array(
'name' => $translator->trans("app.ui.product_callout.".$badge['key']),
'id' => $badge['key'],
);
}
// $siteFilterBadgeVariants = $productVariantRepository->findBy([
// 'badge' => array_map(function ($row) {
// return $row['key'];
// }, $esAggregations['badge']['buckets']),
// 'enabled' => true
// ], [
// 'code' => 'ASC'
// ]);
// if(count($siteFilterBadgeVariants) > 0){
// foreach($siteFilterBadgeVariants as $siteFilterBadgeVariant){
// $siteFilterBadge[$siteFilterBadgeVariant->getBadge()] = array(
// 'name' => $translator->trans("app.ui.product_callout.".$siteFilterBadgeVariant->getBadge()),
// 'id' => $siteFilterBadgeVariant->getBadge(),
// );
// }
// }
}
dump( $esAggregations);
dump( $siteFilterBadge);
$t9 = microtime(true);
$log = [];
$log[] = 'Time to retrieve taxon: ' . ($t1 - $tstart) . ' seconds';
$log[] = 'Time to retrieve elements by taxon: ' . ($t2 - $t1) . ' seconds';
$log[] = 'Time to retrieve variants: ' . ($t3 - $t2) . ' seconds';
$log[] = 'Time to retrieve site filter facets: ' . ($t4 - $t3) . ' seconds';
$log[] = 'Time to retrieve filter facets by taxon: ' . ($t5 - $t4) . ' seconds';
$log[] = 'Time to filter site filter facets: ' . ($t6 - $t5) . ' seconds';
$log[] = 'Time to retrieve site filter shape: ' . ($t7 - $t6) . ' seconds';
$log[] = 'Time to retrieve site filter color: ' . ($t8 - $t7) . ' seconds';
$log[] = 'Time to retrieve site filter badge: ' . ($t9 - $t8) . ' seconds';
dump($log);
// $filtreUrl = '';
// if(!empty($request->get('filtre')) && !empty($request->get('filtrevalue'))){
// $filtreUrl = $request->get('filtre').'/'.$request->get('filtrevalue');
// }
if (count($variants) <= 0) {
return new JsonResponse([
'variants' => $twigEnvironment->render('taxons/taxon_list_products_ajax.html.twig', [
'variants' => '',
'taxon' => $taxon
]),
'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS_AJAX,
'totalResults' => 0,
// 'siteFilterFacets' => $siteFilterFacets
'siteFilterFacets' => $twigEnvironment->render('partials/block-facet-filters.html.twig', [
'siteFilterFacets' => $siteFilterFacets,
'siteFilterShape' => $siteFilterShape,
'siteFilterBadgeVariants' => $siteFilterBadgeVariants,
'siteFilterColor' => $siteFilterColor,
'siteFilterBadge' => $siteFilterBadge,
'siteFilterFacetsValues' => $siteFilterFacetsValues,
'ajaxUrl'=> $this->get('router')->generate('app_taxon_ajax_list', array('taxonId' => $taxon->getId()))
]),
// 'filtreUrl' => $filtreUrl,
]);
}else{
if(isset( $selectedFacets['color'])){
$shapeMatch = array();
foreach($variants as $variant){
$shapeMatch[$variant->getProduct()->getId()] = $variant->getProduct()->getId();
}
$siteFilterShapeVariants = array();
foreach($siteFilterShape as $shape){
if (in_array($shape->getId(), $shapeMatch)) {
$siteFilterShapeVariants[] = $shape;
}
}
}else{
$siteFilterShapeVariants = $siteFilterShape;
}
if(isset( $selectedFacets['shape'])){
$collectionMatch = array();
foreach($variants as $variant){
if($variant->getOptionValues()->first()){
$collectionMatch[$variant->getOptionValues()->first()->getId()] = $variant->getOptionValues()->first()->getId();
}
}
$siteFilterColorVariants = array();
foreach($siteFilterColor as $color){
if (in_array($color->getProductOptionValue()->getId(), $collectionMatch)) {
$siteFilterColorVariants[] = $color;
}
}
}else{
$siteFilterColorVariants = $siteFilterColor;
}
$badgeMatch = array();
foreach($variants as $variant){
$badgeMatch[$variant->getBadge()] = $variant->getBadge();
}
$siteFilterBadgeVariants = array();
foreach($siteFilterBadge as $badge){
if (in_array($badge['id'], $badgeMatch)) {
$siteFilterBadgeVariants[] = $badge;
}
}
$filtersMatch = array();
foreach($variants as $variant){
// $variant->getProduct()->getAttributeValue()
foreach($variant->getProduct()->getAttributes() as $attr){
$value = $attr->getValue();
// $filtersMatch[$attr->getAttribute()->getId()][$variant->getProduct()->getId()][$attr->getId()] = $value[0];
if(isset($value[0])){
$filtersMatch[$attr->getAttribute()->getId()][$value[0]] = $attr->getId();
}
}
}
$siteFilterOtherVariants = array();
foreach($siteFilterFacets as $key => $facet){
// dump($facet);
// dump($facet->getProductAttribute());
if (isset($filtersMatch[$facet->getProductAttribute()->getId()])/* && in_array($facet->getProductAttribute()->getOptionValues(), $filtersMatch[$facet->getProductAttribute()->getId()])*/) {
$siteFilterOtherVariants[] = $facet;
// foreach($facet->getProductAttribute()->getConfiguration()['choices'] as $key => $choice){
// }
}
}
// dump($variants);
// dump($filtersMatch);
// dump($siteFilterFacets);
// dump($siteFilterFacetsValues);
// // dump($esAggregations);
// dump($siteFilterOtherVariants);
// // dump($siteFilterColor);
// // dump($collectionMatch);
// // dump($siteFilterColorVariants);
}
$tend = microtime(true);
// dump($t1 - $tstart);
$log[] = 'Total execution time: ' . ($tend - $tstart) . ' seconds';
dump($log);
// $logger = $this->get('logger');
// $logger->info('Time to retrieve taxon: ' . ($t1 - $tstart) . ' seconds');
// $logger->info('Time to retrieve elements by taxon: ' . ($t2 - $t1) . ' seconds');
// $logger->info('Time to retrieve variants: ' . ($t3 - $t2) . ' seconds');
// $logger->info('Time to retrieve site filter facets: ' . ($t4 - $t3) . ' seconds');
// $logger->info('Time to retrieve filter facets by taxon: ' . ($t5 - $t4) . ' seconds');
// $logger->info('Time to filter site filter facets: ' . ($t6 - $t5) . ' seconds');
// $logger->info('Time to retrieve site filter shape: ' . ($t7 - $t6) . ' seconds');
// $logger->info('Time to retrieve site filter color: ' . ($t8 - $t7) . ' seconds');
// $logger->info('Time to retrieve site filter badge: ' . ($t9 - $t8) . ' seconds');
// $logger->info('Total execution time: ' . ($tend - $tstart) . ' seconds');
// Renvoyer les résultats
// return $this->render('taxons/taxon_list_products_ajax.html.twig', [
// 'variants' => $variants,
// 'taxon' => $taxon
// ]);
return new JsonResponse([
'variants' => $twigEnvironment->render('taxons/taxon_list_products_ajax.html.twig', [
'variants' => $variants,
'taxon' => $taxon
]),
'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS_AJAX,
'totalResults' => $results['hits']['total']['value'],
// 'siteFilterFacets' => $siteFilterFacets
'siteFilterFacets' => $twigEnvironment->render('partials/block-facet-filters.html.twig', [
'siteFilterFacets' => $siteFilterOtherVariants,
'siteFilterShape' => $siteFilterShapeVariants,
'siteFilterColor' => $siteFilterColorVariants,
'siteFilterBadge' => $siteFilterBadgeVariants,
'siteFilterFacetsValues' => $siteFilterFacetsValues,
'ajaxUrl'=> $this->get('router')->generate('app_taxon_ajax_list', array('taxonId' => $taxon->getId())),
]),
// 'filtreUrl' => $filtreUrl,
]);
}
public function indexWithFiltreAction(
Request $request,
LocaleContextInterface $localeContext,
TaxonRepositoryInterface $taxonRepository,
ProductRepositoryInterface $productRepository,
ProductVariantRepositoryInterface $productVariantRepository,
ProductAttributeValueRepositoryInterface $productAttributeValueRepository,
ElasticSearchService $elasticSearch,
Breadcrumbs $breadcrumbs,
TranslatorInterface $translator,
$cat1,
$cat2
) {
$slug = 'nos-produits/'.$cat1.'/'.$cat2;
//si filtre deja engagé
$filtreUrl = '';
if(!empty($request->get('filtre')) && !empty($request->get('filtrevalue'))){
$filtreUrl = $request->get('filtre').'/'.$request->get('filtrevalue');
}
// Récupère la catégorie
$taxon = $taxonRepository->findOneBySlug($slug, $localeContext->getLocaleCode());
if (empty($taxon)) {
// return;
throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
}
// Fil d'ariane
$taxonParent = $taxon;
while ($taxonParent != $taxon->getRoot()) {
$breadcrumbs->prependRouteItem($taxonParent, "sylius_shop_product_index", [
'slug' => $taxonParent->getSlug()
]);
$taxonParent = $taxonParent->getParent();
}
$breadcrumbs->prependRouteItem($taxon->getRoot()->getName(), "sylius_shop_product_index", [
'slug' => $taxon->getRoot()->getSlug()
]);
$breadcrumbs->prependRouteItem("sylius.ui.home", "sylius_shop_homepage");
// Catégorie de "niveau 1" - On affiche uniquement les sous catégories
if ($taxon->getLevel() == 0) {
return $this->render('site_taxon_level1_show.html.twig', [
'taxon' => $taxon
]);
}
$em = $this->get('doctrine')->getManager();
// Récupère les articles dans la catégorie d'articles associé
$articles = [];
if (empty($taxon->getSingleArticleCategory()) == false) {
$articles = $em->getRepository(SiteArticle::class)
->createQueryBuilder('a')
->where('a.articleCategory = :category')
->andWhere('a.dateDiffusion < :today')
->setParameter('today', date("Y-m-d H:i:s"))
->orderBy('a.createdAt', 'DESC')
->setParameter('category', $taxon->getSingleArticleCategory())
->getQuery()
->getResult();
}
// Récupère tous les filtres à facettes disponible pour
// cette "recherche"
$siteFilterFacets = $em->getRepository(SiteFilterFacet::class)
->findBy([
'enabled' => true
], [
'position' => 'ASC'
]);
$esAggregations = $elasticSearch->getFilterFacetsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), array_map(function ($row) {
return $row->getId();
}, $siteFilterFacets));
dump($esAggregations) ;
$siteFilterShape = [];
if (count($esAggregations['shape']['buckets']) > 1) {
$siteFilterShape = $productRepository->findBy([
'id' => array_map(function ($row) {
return $row['key'];
}, $esAggregations['shape']['buckets']),
'enabled' => true
], [
'code' => 'ASC'
]);
usort($siteFilterShape, function ($a, $b) {
// dump($a->getTranslation()->getName());
return strcmp(str_replace('É', 'e',$a->getTranslation()->getName()) , str_replace('É', 'e', $b->getTranslation()->getName()) );
});
}
$siteFilterColor = [];
if (count($esAggregations['color']['buckets']) > 1) {
$siteFilterColor = $em->getRepository(SiteCollection::class)->findBy([
'productOptionValue' => array_map(function ($row) {
return $row['key'];
}, $esAggregations['color']['buckets']),
]);
}
usort($siteFilterColor, function($a, $b) {
return $a->getDateRelease() < $b->getDateRelease();
});
$siteFilterBadge = [];
$siteFilterBadgeVariants = [];
if (count($esAggregations['badge']['buckets']) > 1) {
foreach($esAggregations['badge']['buckets'] as $badge){
$siteFilterBadge[] = array(
'name' => $translator->trans("app.ui.product_callout.".$badge['key']),
'id' => $badge['key'],
);
}
// $siteFilterBadgeVariants = $productVariantRepository->findBy([
// 'badge' => array_map(function ($row) {
// return $row['key'];
// }, $esAggregations['badge']['buckets']),
// 'enabled' => true
// ], [
// 'code' => 'ASC'
// ]);
// if(count($siteFilterBadgeVariants) > 0){
// foreach($siteFilterBadgeVariants as $siteFilterBadgeVariant){
// $siteFilterBadge[$siteFilterBadgeVariant->getBadge()] = array(
// 'name' => $translator->trans("app.ui.product_callout.".$siteFilterBadgeVariant->getBadge()),
// 'id' => $siteFilterBadgeVariant->getBadge(),
// );
// }
// }
}
$siteFilterFacetsValues = [];
foreach ($esAggregations as $keyEsAggregation => $rowEsAggregation) {
if (isset($rowEsAggregation['buckets']) && count($rowEsAggregation['buckets']) > 1) {
$siteFilterFacetsValues[$keyEsAggregation] = array_map(function ($row) {
return $row['key'];
}, $rowEsAggregation['buckets']);
// On met dans l'ordre alphabétique
sort($siteFilterFacetsValues[$keyEsAggregation]);
}
}
// Conserve que les filtres à facettes disponible pour cette recherche
$siteFilterFacets = array_filter($siteFilterFacets, function ($row) use (&$siteFilterFacetsValues) {
return in_array($row->getId(), array_keys($siteFilterFacetsValues));
});
$noindex = true;
dump($siteFilterFacetsValues);
dump($request->get('filtre'));
//on regarde si le filtre engagé est indexable ou non
foreach($siteFilterFacetsValues as $key => $facet){
if(is_int($key)){
//carac
$filtre = $em->getRepository(SiteFilterFacet::class)->find($key);
// dump($filtre->getProductAttribute());
// dump($request->get('filtre').' ---- '.$this->replaceSpecialChar(strtolower($filtre->getProductAttribute()->getName())));
if($this->replaceSpecialChar(strtolower($filtre->getProductAttribute()->getName())) == $request->get('filtre')){
$noindex = !$filtre->getIndexableSeo();
}
}elseif($key == 'shape' && $request->get('filtre') == "forme"){ //forme
$noindex = false;
}elseif($key == 'color' && $request->get('filtre') == "collection"){ //colelction
$noindex = true;
}elseif($key == 'badge' && $request->get('filtre') == "badge"){ //colelction
$noindex = false;
}
}
dump($noindex);
$meta_filtre = ucfirst($request->get('filtre')).' '.$request->get('filtrevalue');
// dump( $meta_filtre);
// Récupère tous les produits dans cette catégorie avec
// l'applique du filtre à facette et/ou de l'ordre
$sorting = $request->query->get('sorting');
$sortBy = null;
$sortOrder = null;
if (is_array($sorting)) {
$sortBy = key($sorting);
$sortOrder = $sorting[key($sorting)];
}
$selectedFacets = (array) $request->query->get('facets', []);
$results = $elasticSearch->getElementsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), 0, $selectedFacets, $sortBy, $sortOrder);
$variants = [];
if (count($results['hits']['hits']) > 0) {
$variants = $productVariantRepository->findByIdsAndOrderByFieldId(array_map(function ($row) {
return str_ireplace('VARIANT_', '', $row['_id']);
}, $results['hits']['hits']));
}
// Récupère les liens pour la partie référencement
$referencementllinks = [];
if (!empty($taxon->getSeoLinks())) {
$referencementllinks = $taxonRepository->findBy([
'id' => $taxon->getSeoLinks()
]);
}
// return new JsonResponse([
// 'variants' => $twigEnvironment->render('taxons/taxon_list_products_ajax.html.twig', [
// 'variants' => $variants,
// 'taxon' => $taxon
// ]),
// 'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS,
// 'totalResults' => $results['hits']['total']['value'],
// ]);
// Catégorie de "niveau 3"
return $this->render('site_taxon_lastlevel_show.html.twig', [
'taxon' => $taxon,
'referencementllinks' => $referencementllinks,
'variants' => $variants,
'selectedFacets' => $selectedFacets,
'siteFilterShape' => $siteFilterShape,
'siteFilterColor' => $siteFilterColor,
'siteFilterBadge' => $siteFilterBadge,
'siteFilterFacets' => $siteFilterFacets,
'siteFilterFacetsValues' => $siteFilterFacetsValues,
'siteFilterMinPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MIN]['value'],
'siteFilterMaxPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MAX]['value'],
'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS,
'totalResults' => $results['hits']['total']['value'],
'filtreUrl' => $filtreUrl,
'noindex' => $noindex,
'metaFiltre' => $meta_filtre,
]);
}
public function tissuLevel2Action(
Request $request,
LocaleContextInterface $localeContext,
TaxonRepositoryInterface $taxonRepository,
ProductRepositoryInterface $productRepository,
ProductVariantRepositoryInterface $productVariantRepository,
ProductAttributeValueRepositoryInterface $productAttributeValueRepository,
ElasticSearchService $elasticSearch,
Breadcrumbs $breadcrumbs,
$cat1,
) {
$slug = 'tissus-et-petite-mercerie/'.$cat1;
//si filtre deja engagé
$filtreUrl = '';
if(!empty($request->get('filtre')) && !empty($request->get('filtrevalue'))){
$filtreUrl = $request->get('filtre').'/'.$request->get('filtrevalue');
}
// Récupère la catégorie
$taxon = $taxonRepository->findOneBySlug($slug, $localeContext->getLocaleCode());
if (empty($taxon)) {
// return;
throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
}
// Fil d'ariane
$taxonParent = $taxon;
while ($taxonParent != $taxon->getRoot()) {
$breadcrumbs->prependRouteItem($taxonParent, "sylius_shop_product_index", [
'slug' => $taxonParent->getSlug()
]);
$taxonParent = $taxonParent->getParent();
}
$breadcrumbs->prependRouteItem($taxon->getRoot()->getName(), "sylius_shop_product_index", [
'slug' => $taxon->getRoot()->getSlug()
]);
$breadcrumbs->prependRouteItem("sylius.ui.home", "sylius_shop_homepage");
$em = $this->get('doctrine')->getManager();
// Récupère les articles dans la catégorie d'articles associé
$articles = [];
if (empty($taxon->getSingleArticleCategory()) == false) {
$articles = $em->getRepository(SiteArticle::class)
->createQueryBuilder('a')
->where('a.articleCategory = :category')
->andWhere('a.dateDiffusion < :today')
->setParameter('today', date("Y-m-d H:i:s"))
->orderBy('a.createdAt', 'DESC')
->setParameter('category', $taxon->getSingleArticleCategory())
->getQuery()
->getResult();
}
// Récupère tous les filtres à facettes disponible pour
// cette "recherche"
$siteFilterFacets = $em->getRepository(SiteFilterFacet::class)
->findBy([
'enabled' => true
], [
'position' => 'ASC'
]);
$esAggregations = $elasticSearch->getFilterFacetsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), array_map(function ($row) {
return $row->getId();
}, $siteFilterFacets));
$siteFilterShape = [];
if (count($esAggregations['shape']['buckets']) > 1) {
$siteFilterShape = $productRepository->findBy([
'id' => array_map(function ($row) {
return $row['key'];
}, $esAggregations['shape']['buckets']),
'enabled' => true
], [
'code' => 'ASC'
]);
usort($siteFilterShape, function ($a, $b) {
// dump($a->getTranslation()->getName());
return strcmp(str_replace('É', 'e',$a->getTranslation()->getName()) , str_replace('É', 'e', $b->getTranslation()->getName()) );
});
}
$siteFilterColor = [];
if (count($esAggregations['color']['buckets']) > 1) {
$siteFilterColor = $em->getRepository(SiteCollection::class)->findBy([
'productOptionValue' => array_map(function ($row) {
return $row['key'];
}, $esAggregations['color']['buckets']),
]);
}
usort($siteFilterColor, function($a, $b) {
return $a->getDateRelease() < $b->getDateRelease();
});
$siteFilterFacetsValues = [];
foreach ($esAggregations as $keyEsAggregation => $rowEsAggregation) {
if (isset($rowEsAggregation['buckets']) && count($rowEsAggregation['buckets']) > 1) {
$siteFilterFacetsValues[$keyEsAggregation] = array_map(function ($row) {
return $row['key'];
}, $rowEsAggregation['buckets']);
// On met dans l'ordre alphabétique
sort($siteFilterFacetsValues[$keyEsAggregation]);
}
}
// dump($siteFilterFacetsValues) ;
// Conserve que les filtres à facettes disponible pour cette recherche
$siteFilterFacets = array_filter($siteFilterFacets, function ($row) use (&$siteFilterFacetsValues) {
return in_array($row->getId(), array_keys($siteFilterFacetsValues));
});
// Récupère tous les produits dans cette catégorie avec
// l'applique du filtre à facette et/ou de l'ordre
$sorting = $request->query->get('sorting');
$sortBy = null;
$sortOrder = null;
if (is_array($sorting)) {
$sortBy = key($sorting);
$sortOrder = $sorting[key($sorting)];
}
$selectedFacets = (array) $request->query->get('facets', []);
$results = $elasticSearch->getElementsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), 0, $selectedFacets, $sortBy, $sortOrder);
$variants = [];
if (count($results['hits']['hits']) > 0) {
$variants = $productVariantRepository->findByIdsAndOrderByFieldId(array_map(function ($row) {
return str_ireplace('VARIANT_', '', $row['_id']);
}, $results['hits']['hits']));
}
// Récupère les liens pour la partie référencement
$referencementllinks = [];
if (!empty($taxon->getSeoLinks())) {
$referencementllinks = $taxonRepository->findBy([
'id' => $taxon->getSeoLinks()
]);
}
return $this->render('site_taxon_level2_show.html.twig', [
'taxon' => $taxon,
'referencementllinks' => $referencementllinks,
'variants' => $variants,
'articles' => $articles,
'selectedFacets' => $selectedFacets,
'siteFilterShape' => $siteFilterShape,
'siteFilterColor' => $siteFilterColor,
'siteFilterFacets' => $siteFilterFacets,
'siteFilterFacetsValues' => $siteFilterFacetsValues,
'siteFilterMinPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MIN]['value'],
'siteFilterMaxPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MAX]['value'],
'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS,
'totalResults' => $results['hits']['total']['value'],
'filtreUrl' => $filtreUrl
]);
}
public function tissuLevel3Action(
Request $request,
LocaleContextInterface $localeContext,
TaxonRepositoryInterface $taxonRepository,
ProductRepositoryInterface $productRepository,
ProductVariantRepositoryInterface $productVariantRepository,
ProductAttributeValueRepositoryInterface $productAttributeValueRepository,
ElasticSearchService $elasticSearch,
Breadcrumbs $breadcrumbs,
TranslatorInterface $translator,
$cat1,
$cat2,
) {
$slug = 'tissus-et-petite-mercerie/'.$cat1.'/'.$cat2;
//si filtre deja engagé
$filtreUrl = '';
if(!empty($request->get('filtre')) && !empty($request->get('filtrevalue'))){
$filtreUrl = $request->get('filtre').'/'.$request->get('filtrevalue');
}
// Récupère la catégorie
$taxon = $taxonRepository->findOneBySlug($slug, $localeContext->getLocaleCode());
if (empty($taxon)) {
// return;
throw new NotFoundHttpException("Cette catégorie produit n'existe pas.");
}
// Fil d'ariane
$taxonParent = $taxon;
while ($taxonParent != $taxon->getRoot()) {
$breadcrumbs->prependRouteItem($taxonParent, "sylius_shop_product_index", [
'slug' => $taxonParent->getSlug()
]);
$taxonParent = $taxonParent->getParent();
}
$breadcrumbs->prependRouteItem($taxon->getRoot()->getName(), "sylius_shop_product_index", [
'slug' => $taxon->getRoot()->getSlug()
]);
$breadcrumbs->prependRouteItem("sylius.ui.home", "sylius_shop_homepage");
$em = $this->get('doctrine')->getManager();
// Récupère les articles dans la catégorie d'articles associé
$articles = [];
if (empty($taxon->getSingleArticleCategory()) == false) {
$articles = $em->getRepository(SiteArticle::class)
->createQueryBuilder('a')
->where('a.articleCategory = :category')
->andWhere('a.dateDiffusion < :today')
->setParameter('today', date("Y-m-d H:i:s"))
->orderBy('a.createdAt', 'DESC')
->setParameter('category', $taxon->getSingleArticleCategory())
->getQuery()
->getResult();
}
// Récupère tous les filtres à facettes disponible pour
// cette "recherche"
$siteFilterFacets = $em->getRepository(SiteFilterFacet::class)
->findBy([
'enabled' => true
], [
'position' => 'ASC'
]);
$esAggregations = $elasticSearch->getFilterFacetsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), array_map(function ($row) {
return $row->getId();
}, $siteFilterFacets));
$siteFilterShape = [];
if (count($esAggregations['shape']['buckets']) > 1) {
$siteFilterShape = $productRepository->findBy([
'id' => array_map(function ($row) {
return $row['key'];
}, $esAggregations['shape']['buckets']),
'enabled' => true
], [
'code' => 'ASC'
]);
usort($siteFilterShape, function ($a, $b) {
// dump($a->getTranslation()->getName());
return strcmp(str_replace('É', 'e',$a->getTranslation()->getName()) , str_replace('É', 'e', $b->getTranslation()->getName()) );
});
}
$siteFilterColor = [];
if (count($esAggregations['color']['buckets']) > 1) {
$siteFilterColor = $em->getRepository(SiteCollection::class)->findBy([
'productOptionValue' => array_map(function ($row) {
return $row['key'];
}, $esAggregations['color']['buckets']),
]);
}
usort($siteFilterColor, function($a, $b) {
return $a->getDateRelease() < $b->getDateRelease();
});
$siteFilterFacetsValues = [];
foreach ($esAggregations as $keyEsAggregation => $rowEsAggregation) {
if (isset($rowEsAggregation['buckets']) && count($rowEsAggregation['buckets']) > 1) {
$siteFilterFacetsValues[$keyEsAggregation] = array_map(function ($row) {
return $row['key'];
}, $rowEsAggregation['buckets']);
// On met dans l'ordre alphabétique
sort($siteFilterFacetsValues[$keyEsAggregation]);
}
}
// dump($siteFilterFacetsValues) ;
// Conserve que les filtres à facettes disponible pour cette recherche
$siteFilterFacets = array_filter($siteFilterFacets, function ($row) use (&$siteFilterFacetsValues) {
return in_array($row->getId(), array_keys($siteFilterFacetsValues));
});
$siteFilterBadge = [];
$siteFilterBadgeVariants = [];
if (count($esAggregations['badge']['buckets']) > 1) {
$siteFilterBadgeVariants = $productVariantRepository->findBy([
'badge' => array_map(function ($row) {
return $row['key'];
}, $esAggregations['badge']['buckets']),
'enabled' => true
], [
'code' => 'ASC'
]);
if(count($siteFilterBadgeVariants) > 0){
foreach($siteFilterBadgeVariants as $siteFilterBadgeVariant){
$siteFilterBadge[$siteFilterBadgeVariant->getBadge()] = array(
'name' => $translator->trans("app.ui.product_callout.".$siteFilterBadgeVariant->getBadge()),
'id' => $siteFilterBadgeVariant->getBadge(),
);
}
}
}
// Récupère tous les produits dans cette catégorie avec
// l'applique du filtre à facette et/ou de l'ordre
$sorting = $request->query->get('sorting');
$sortBy = null;
$sortOrder = null;
if (is_array($sorting)) {
$sortBy = key($sorting);
$sortOrder = $sorting[key($sorting)];
}
$selectedFacets = (array) $request->query->get('facets', []);
$results = $elasticSearch->getElementsByTaxon($localeContext->getLocaleCode(), $taxon->getId(), 0, $selectedFacets, $sortBy, $sortOrder);
$variants = [];
if (count($results['hits']['hits']) > 0) {
$variants = $productVariantRepository->findByIdsAndOrderByFieldId(array_map(function ($row) {
return str_ireplace('VARIANT_', '', $row['_id']);
}, $results['hits']['hits']));
}
// Récupère les liens pour la partie référencement
$referencementllinks = [];
if (!empty($taxon->getSeoLinks())) {
$referencementllinks = $taxonRepository->findBy([
'id' => $taxon->getSeoLinks()
]);
}
return $this->render('site_taxon_level2_show.html.twig', [
'taxon' => $taxon,
'referencementllinks' => $referencementllinks,
'variants' => $variants,
'articles' => $articles,
'selectedFacets' => $selectedFacets,
'siteFilterShape' => $siteFilterShape,
'siteFilterColor' => $siteFilterColor,
'siteFilterFacets' => $siteFilterFacets,
'siteFilterFacetsValues' => $siteFilterFacetsValues,
'siteFilterMinPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MIN]['value'],
'siteFilterMaxPrice' => $esAggregations[ElasticSearchService::FACET_PRICE_MAX]['value'],
'maxViewResults' => ElasticSearchService::MAX_SEARCH_RESULTS,
'totalResults' => $results['hits']['total']['value'],
'filtreUrl' => $filtreUrl
]);
}
function replaceSpecialChar($str) {
$ch0 = array(
"œ"=>"oe",
"Œ"=>"OE",
"æ"=>"ae",
"Æ"=>"AE",
"À" => "A",
"Á" => "A",
"Â" => "A",
"à" => "A",
"Ä" => "A",
"Å" => "A",
"Ā" => "A",
"Ă" => "A",
"Ǎ" => "A",
"Ạ" => "A",
"Ả" => "A",
"Ấ" => "A",
"Ầ" => "A",
"Ẩ" => "A",
"Ẫ" => "A",
"Ậ" => "A",
"Ắ" => "A",
"Ằ" => "A",
"Ẳ" => "A",
"Ẵ" => "A",
"Ặ" => "A",
"Ǻ" => "A",
"Ą" => "A",
"à" => "a",
"á" => "a",
"â" => "a",
"à" => "a",
"ä" => "a",
"å" => "a",
"ā" => "a",
"ă" => "a",
"ǎ" => "a",
"ạ" => "a",
"ả" => "a",
"ấ" => "a",
"ầ" => "a",
"ẩ" => "a",
"ẫ" => "a",
"ậ" => "a",
"ắ" => "a",
"ằ" => "a",
"ẳ" => "a",
"ẵ" => "a",
"ặ" => "a",
"ǻ" => "a",
"ą" => "a",
"Ç" => "C",
"Ć" => "C",
"Ĉ" => "C",
"Ċ" => "C",
"Č" => "C",
"ç" => "c",
"ć" => "c",
"ĉ" => "c",
"ċ" => "c",
"č" => "c",
"Ð" => "D",
"Ď" => "D",
"Đ" => "D",
"ď" => "d",
"đ" => "d",
"È" => "E",
"É" => "E",
"Ê" => "E",
"Ë" => "E",
"Ē" => "E",
"Ĕ" => "E",
"Ė" => "E",
"Ę" => "E",
"Ě" => "E",
"Ẹ" => "E",
"Ẻ" => "E",
"Ẽ" => "E",
"Ế" => "E",
"Ề" => "E",
"Ể" => "E",
"Ễ" => "E",
"Ệ" => "E",
"è" => "e",
"é" => "e",
"ê" => "e",
"ë" => "e",
"ē" => "e",
"ĕ" => "e",
"ė" => "e",
"ę" => "e",
"ě" => "e",
"ẹ" => "e",
"ẻ" => "e",
"ẽ" => "e",
"ế" => "e",
"ề" => "e",
"ể" => "e",
"ễ" => "e",
"ệ" => "e",
"Ĝ" => "G",
"Ğ" => "G",
"Ġ" => "G",
"Ģ" => "G",
"ĝ" => "g",
"ğ" => "g",
"ġ" => "g",
"ģ" => "g",
"Ĥ" => "H",
"Ħ" => "H",
"ĥ" => "h",
"ħ" => "h",
"Ì" => "I",
"Í" => "I",
"Î" => "I",
"Ï" => "I",
"Ĩ" => "I",
"Ī" => "I",
"Ĭ" => "I",
"Į" => "I",
"İ" => "I",
"Ǐ" => "I",
"Ỉ" => "I",
"Ị" => "I",
"Ĵ" => "J",
"ĵ" => "j",
"Ķ" => "K",
"ķ" => "k",
"Ĺ" => "L",
"Ļ" => "L",
"Ľ" => "L",
"Ŀ" => "L",
"Ł" => "L",
"ĺ" => "l",
"ļ" => "l",
"ľ" => "l",
"ŀ" => "l",
"ł" => "l",
"Ñ" => "N",
"Ń" => "N",
"Ņ" => "N",
"Ň" => "N",
"ñ" => "n",
"ń" => "n",
"ņ" => "n",
"ň" => "n",
"ʼn" => "n",
"Ò" => "O",
"Ó" => "O",
"Ô" => "O",
"Õ" => "O",
"Ö" => "O",
"Ø" => "O",
"Ō" => "O",
"Ŏ" => "O",
"Ő" => "O",
"Ơ" => "O",
"Ǒ" => "O",
"Ǿ" => "O",
"Ọ" => "O",
"Ỏ" => "O",
"Ố" => "O",
"Ồ" => "O",
"Ổ" => "O",
"Ỗ" => "O",
"Ộ" => "O",
"Ớ" => "O",
"Ờ" => "O",
"Ở" => "O",
"Ỡ" => "O",
"Ợ" => "O",
"ò" => "o",
"ó" => "o",
"ô" => "o",
"õ" => "o",
"ö" => "o",
"ø" => "o",
"ō" => "o",
"ŏ" => "o",
"ő" => "o",
"ơ" => "o",
"ǒ" => "o",
"ǿ" => "o",
"ọ" => "o",
"ỏ" => "o",
"ố" => "o",
"ồ" => "o",
"ổ" => "o",
"ỗ" => "o",
"ộ" => "o",
"ớ" => "o",
"ờ" => "o",
"ở" => "o",
"ỡ" => "o",
"ợ" => "o",
"ð" => "o",
"Ŕ" => "R",
"Ŗ" => "R",
"Ř" => "R",
"ŕ" => "r",
"ŗ" => "r",
"ř" => "r",
"Ś" => "S",
"Ŝ" => "S",
"Ş" => "S",
"ś" => "s",
"ŝ" => "s",
"ş" => "s",
"Ţ" => "T",
"Ť" => "T",
"Ŧ" => "T",
"ţ" => "t",
"ť" => "t",
"ŧ" => "t",
"Ù" => "U",
"Ú" => "U",
"Û" => "U",
"Ü" => "U",
"Ũ" => "U",
"Ū" => "U",
"Ŭ" => "U",
"Ů" => "U",
"Ű" => "U",
"Ų" => "U",
"Ư" => "U",
"Ǔ" => "U",
"Ǖ" => "U",
"Ǘ" => "U",
"Ǚ" => "U",
"Ǜ" => "U",
"Ụ" => "U",
"Ủ" => "U",
"Ứ" => "U",
"Ừ" => "U",
"Ử" => "U",
"Ữ" => "U",
"Ự" => "U",
"ù" => "u",
"ú" => "u",
"û" => "u",
"ü" => "u",
"ũ" => "u",
"ū" => "u",
"ŭ" => "u",
"ů" => "u",
"ű" => "u",
"ų" => "u",
"ư" => "u",
"ǔ" => "u",
"ǖ" => "u",
"ǘ" => "u",
"ǚ" => "u",
"ǜ" => "u",
"ụ" => "u",
"ủ" => "u",
"ứ" => "u",
"ừ" => "u",
"ử" => "u",
"ữ" => "u",
"ự" => "u",
"Ŵ" => "W",
"Ẁ" => "W",
"Ẃ" => "W",
"Ẅ" => "W",
"ŵ" => "w",
"ẁ" => "w",
"ẃ" => "w",
"ẅ" => "w",
"Ý" => "Y",
"Ŷ" => "Y",
"?" => "Y",
"Ỳ" => "Y",
"Ỹ" => "Y",
"Ỷ" => "Y",
"Ỵ" => "Y",
"ý" => "y",
"ÿ" => "y",
"ŷ" => "y",
"ỹ" => "y",
"ỵ" => "y",
"ỷ" => "y",
"ỳ" => "y",
"Ź" => "Z",
"Ż" => "Z",
'+' =>'',
"'" =>'',
' ' =>'-',
'.' =>'-',
);
$str = strtr($str,$ch0);
return $str;
}
}