Pedro D. Posted June 25, 2019 Share Posted June 25, 2019 Hola Comunidad, ¿hay alguna forma de poder ordenar en el filtro de navegación por facetas las marcas de forma alfabética? Tenemos un desplegable con más de 200 marcas en el filtro y no hay manera de que sea intuitivo. Versión de Prestashop: 1.7.5.0 Versión del módulo de Navegación por facetas: 3.0.5 Llevamos unos días buscando en el propio módulo la solución, y creemos que debemos de hacerlo en esta función, ¿estamos en lo correcto? private function getManufacturersBlock($filter, $selectedFilters, $idLang) { $manufacturersArray = $manufacturers = []; $filteredSearchAdapter = $this->searchAdapter->getFilteredSearchAdapter('id_manufacturer'); $tempManufacturers = Manufacturer::getManufacturers(false, $idLang); if (empty($tempManufacturers)) { return $manufacturersArray; } foreach ($tempManufacturers as $key => $manufacturer) { $manufacturers[$manufacturer['id_manufacturer']] = $manufacturer; } $results = $filteredSearchAdapter->valueCount('id_manufacturer'); foreach ($results as $key => $values) { if (!isset($values['id_manufacturer'])) { continue; } $id_manufacturer = $values['id_manufacturer']; if (empty($manufacturers[$id_manufacturer]['name'])) { continue; } $count = $values['c']; $manufacturersArray[$id_manufacturer] = [ 'name' => $manufacturers[$id_manufacturer]['name'], 'nbr' => $count, ]; if (isset($selectedFilters['manufacturer']) && in_array($id_manufacturer, $selectedFilters['manufacturer']) ) { $manufacturersArray[$id_manufacturer]['checked'] = true; } } $this->sortByKey($manufacturers, $manufacturersArray); $manufacturerBlock = [ 'type_lite' => 'manufacturer', 'type' => 'manufacturer', 'id_key' => 0, 'name' => $this->context->getTranslator()->trans('Brand', [], 'Modules.Facetedsearch.Shop'), 'values' => $manufacturersArray, 'filter_show_limit' => $filter['filter_show_limit'], 'filter_type' => $filter['filter_type'], ]; return $manufacturerBlock; } Muchas gracias de antemano. Link to comment Share on other sites More sharing options...
gusman126 Posted June 25, 2019 Share Posted June 25, 2019 Asi deberia ordenar por nombre usort($tempManufacturers, "name"); foreach ($tempManufacturers as $key => $manufacturer) { $manufacturers[$manufacturer['id_manufacturer']] = $manufacturer; } Comprueba que el campo "name" sea el correcto Link to comment Share on other sites More sharing options...
Pedro D. Posted June 25, 2019 Author Share Posted June 25, 2019 Gracias gusman126, vamos a probar. Link to comment Share on other sites More sharing options...
Pedro D. Posted June 25, 2019 Author Share Posted June 25, 2019 Hola gusmain126, no coge el orden, y el campo name es correcto. ¿Alguna otra idea? Gracias. Link to comment Share on other sites More sharing options...
Pedro D. Posted June 26, 2019 Author Share Posted June 26, 2019 Resuelto: Lo resolví insertando el orden del array al final de la función con un sort: sort($manufacturersArray); Dejo la función completa. private function getManufacturersBlock($filter, $selectedFilters, $idLang) { $manufacturersArray = $manufacturers = []; $filteredSearchAdapter = $this->searchAdapter->getFilteredSearchAdapter('id_manufacturer'); $tempManufacturers = Manufacturer::getManufacturers(false, $idLang); if (empty($tempManufacturers)) { return $manufacturersArray; } foreach ($tempManufacturers as $key => $manufacturer) { $manufacturers[$manufacturer['id_manufacturer']] = $manufacturer; } $results = $filteredSearchAdapter->valueCount('id_manufacturer'); foreach ($results as $key => $values) { if (!isset($values['id_manufacturer'])) { continue; } $id_manufacturer = $values['id_manufacturer']; if (empty($manufacturers[$id_manufacturer]['name'])) { continue; } $count = $values['c']; //var_dump($manufacturersArray); $manufacturersArray[$id_manufacturer] = [ 'name' => $manufacturers[$id_manufacturer]['name'], 'nbr' => $count, ]; if (isset($selectedFilters['manufacturer']) && in_array($id_manufacturer, $selectedFilters['manufacturer']) ) { $manufacturersArray[$id_manufacturer]['checked'] = true; } } sort($manufacturersArray); $this->sortByKey($manufacturers, $manufacturersArray); Link to comment Share on other sites More sharing options...
gusman126 Posted June 26, 2019 Share Posted June 26, 2019 Ok, gracias por ponerlo. Cambia el titulo a solucionado Link to comment Share on other sites More sharing options...
Adrián Posted November 19, 2019 Share Posted November 19, 2019 Buenas tardes, me podéis decir exactamente cual es el archivo en concreto a modificar (ruta)? Mi versión de prestashop es 1.7.6.1 y del modulo de Facetas 3.4.0 Muchas gracias! Link to comment Share on other sites More sharing options...
Adrián Posted November 30, 2019 Share Posted November 30, 2019 On 6/26/2019 at 4:19 PM, Pedro D. said: Resuelto: Lo resolví insertando el orden del array al final de la función con un sort: sort($manufacturersArray); Dejo la función completa. private function getManufacturersBlock($filter, $selectedFilters, $idLang) { $manufacturersArray = $manufacturers = []; $filteredSearchAdapter = $this->searchAdapter->getFilteredSearchAdapter('id_manufacturer'); $tempManufacturers = Manufacturer::getManufacturers(false, $idLang); if (empty($tempManufacturers)) { return $manufacturersArray; } foreach ($tempManufacturers as $key => $manufacturer) { $manufacturers[$manufacturer['id_manufacturer']] = $manufacturer; } $results = $filteredSearchAdapter->valueCount('id_manufacturer'); foreach ($results as $key => $values) { if (!isset($values['id_manufacturer'])) { continue; } $id_manufacturer = $values['id_manufacturer']; if (empty($manufacturers[$id_manufacturer]['name'])) { continue; } $count = $values['c']; //var_dump($manufacturersArray); $manufacturersArray[$id_manufacturer] = [ 'name' => $manufacturers[$id_manufacturer]['name'], 'nbr' => $count, ]; if (isset($selectedFilters['manufacturer']) && in_array($id_manufacturer, $selectedFilters['manufacturer']) ) { $manufacturersArray[$id_manufacturer]['checked'] = true; } } sort($manufacturersArray); $this->sortByKey($manufacturers, $manufacturersArray); Buenas cual es la ubicación exacta del archivo, gracias! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now