Jump to content

[Solucionado] Filtro de Navegación por facetas: Orden alfabético de las marcas o fabricantes.


Pedro D.

Recommended Posts

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

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

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

  • Pedro D. changed the title to [Solucionado] Filtro de Navegación por facetas: Orden alfabético de las marcas o fabricantes.
  • 4 months later...
  • 2 weeks later...
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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...