Jump to content

[SOLVED] HELP - How to sort block manufacturer ?


Recommended Posts

Then you must edit /classes/Manufacturer.php
Find lines that contains "ORDER BY m.`name` ASC" end remove it.

On ver 1.2.1 it's on line 166:

$sql.= ' ORDER BY m.`name` ASC'.($p ? ' LIMIT '.((intval($p) - 1) * intval($n)).','.intval($n) : '');



change to

$sql.= ' '.($p ? ' LIMIT '.((intval($p) - 1) * intval($n)).','.intval($n) : '');



Don't forget to backup the original file first.

I advice you do my first suggestion, since this modification will lost/not work in the next version/update.

  • Like 2
Link to comment
Share on other sites

Super :) working
i modify structures of ps_manufactures, adding a field SORT varchar(2)
after that i create a index on this field
example:
id_manufacturer name sort
1 APPLE 2
2 IBM 1
3 COMPAQ 4
4 HP 3
after that i make change described at #4 but i changhed with

$sql.= ' ORDER BY m.`sort` ASC'.($p ? ' LIMIT '.((intval($p) - 1) * intval($n)).','.intval($n) : ''); 


and my manufactures block appear like below:
IBM
APPLE
HP
COMPAQ
:)

Link to comment
Share on other sites

  • 5 months later...

Change lines 30-36 of modules/blockmanufacturer/blockmanufacturer.php from:

$smarty->assign(array(
   'manufacturers' => Manufacturer::getManufacturers(),
   'link' => $link,
   'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'),
   'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'),
   'form_list' => Configuration::get('MANUFACTURER_DISPLAY_FORM'),
));



to something like:

$manufacturers = Manufacturer::getManufacturers();

for ($i = 0; $i < sizeof($manufacturers); $i++)
   $manufacturers[$i]['name'] = Category::hideCategoryPosition($manufacturers[$i]['name']);

$smarty->assign(array(
   'manufacturers' => $manufacturers,
   'link' => $link,
   'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'),
   'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'),
   'form_list' => Configuration::get('MANUFACTURER_DISPLAY_FORM'),
));



This should hide the number prefix.

Link to comment
Share on other sites

  • 1 month later...
  • 2 years later...

Change lines 30-36 of modules/blockmanufacturer/blockmanufacturer.php from:

 

$smarty->assign(array(
'manufacturers' => Manufacturer::getManufacturers(),
'link' => $link,
'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'),
'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'),
'form_list' => Configuration::get('MANUFACTURER_DISPLAY_FORM'),
));

 

to something like:

 

$manufacturers = Manufacturer::getManufacturers();

for ($i = 0; $i < sizeof($manufacturers); $i++)
$manufacturers[$i]['name'] = Category::hideCategoryPosition($manufacturers[$i]['name']);

$smarty->assign(array(
'manufacturers' => $manufacturers,
'link' => $link,
'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'),
'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'),
'form_list' => Configuration::get('MANUFACTURER_DISPLAY_FORM'),
));

 

This should hide the number prefix.

 

Thanks for the tip!

 

But I'm having the same issue with blocklayered block. Blocklayered is still showing number prefixes. And since the code in /modules/blocklayered/blocklayered.php are totatly different than in modules/blockmanufacturer/blockmanufacturer.php I'm wondering if there is any way to implement this fix to the blocklayered?

Edited by Jero (see edit history)
Link to comment
Share on other sites

  • 6 months later...

Hi hitomile,

 

I'm using version 1.5 and for me the solution has been application for 3 things:

 

1. Add the code in the modules/blockmanufacturer/blockmanufacturer.php as described above, but swapping

Category::hideCategoryPosition

by

self::hideCategoryPosition

in the function show it (be sure to put a new function we create called getManufacturersRand, instead of getManufacturers):

 


$manufacturers = Manufacturer::getManufacturers();

		    for ($i = 0; $i < sizeof($manufacturers); $i++)
				    $manufacturers[$i]['name'] = self::hideCategoryPosition($manufacturers[$i]['name']);

       $this->smarty->assign(array(
           'manufacturers' => Manufacturer::getManufacturersRand(),
           'text_list' => Configuration::get('MANUFACTURER_DISPLAY_TEXT'),
           'text_list_nb' => Configuration::get('MANUFACTURER_DISPLAY_TEXT_NB'),
           'form_list' => Configuration::get('MANUFACTURER_DISPLAY_FORM'),
           'display_link_manufacturer' => Configuration::get('PS_DISPLAY_SUPPLIERS'),
       ));

 

2. In the same file, insert the function: (because the function hideCategoryPosition() is obsolete for the 1.5)

 

public static function hideCategoryPosition($name)
    {
	    return preg_replace('/^[0-9]+\./', '', $name);
    }

 

3. Now, insert a new function in the classes/Manufacturer.php, to sort the manufacture randomly:

 

public static function getManufacturersRand($get_nb_products = false, $id_lang = 0, $active = true, $p = false,
 $n = false, $all_group = false)
{
				    if (!$id_lang)
			    $id_lang = (int) Configuration::get('PS_LANG_DEFAULT');
		    $sql = 'SELECT m.*, ml.`description`';
		    $sql.= ' FROM `' . _DB_PREFIX_ . 'manufacturer` m
	  LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer_lang` ml ON (m.`id_manufacturer` = ml.`id_manufacturer` AND ml.`id_lang` = ' . (int) ($id_lang) . ')
	  ' . ($active ? ' WHERE m.`active` = 1' : '');
		    $sql.= ' ORDER BY RAND()' . ($p ? ' LIMIT ' . (((int) ($p) - 1) * (int) ($n)) . ',' . (int) ($n) : '');
		    $manufacturers = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS($sql);
		    if ($manufacturers === false)
			    return false;
		    if ($getNbProducts) {
			    $sqlGroups = '';
			    if (!$all_group) {
				    $groups = FrontController::getCurrentCustomerGroups();
				    $sqlGroups = (count($groups) ? 'IN (' . implode(',', $groups) . ')' : '= 1');
			    }
			    foreach ($manufacturers as $key => $manufacturer) {
				    $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('SELECT p.`id_product`
	    FROM `' . _DB_PREFIX_ . 'product` p
	    LEFT JOIN `' . _DB_PREFIX_ . 'manufacturer` as m ON (m.`id_manufacturer`= p.`id_manufacturer`)
	    WHERE m.`id_manufacturer` = ' . (int) ($manufacturer['id_manufacturer']) .
						    ($active ? ' AND p.`active` = 1 ' : '') .
						    ($all_group ? '' : ' AND p.`id_product` IN (
			 SELECT cp.`id_product`
			 FROM `' . _DB_PREFIX_ . 'category_group` cg
			 LEFT JOIN `' . _DB_PREFIX_ . 'category_product` cp ON (cp.`id_category` = cg.`id_category`)
			 WHERE cg.`id_group` ' . $sqlGroups . ')'));
				    $manufacturers[$key]['nb_products'] = sizeof($result);
			    }
		    }
		    for ($i = 0; $i < sizeof($manufacturers); $i++)
			    if ((int) (Configuration::get('PS_REWRITING_SETTINGS')))
				    $manufacturers[$i]['link_rewrite'] = Tools::link_rewrite($manufacturers[$i]['name'], false);
			    else
				    $manufacturers[$i]['link_rewrite'] = 0;
		    return $manufacturers;
}

 

it is. work for me.

excuse the bad english.

Link to comment
Share on other sites

  • 3 weeks later...
  • 1 month later...

Would it be possible to change something in /classes/Manufacturer.php for Prestashop 1.5.3 that would sort the Manufacturers by the position they have in the back office? There is some "position" talk in the code of the Manufacturer.php

if (empty($order_by) || $order_by == 'position')

$order_by = 'name';

if (empty($order_way)) $order_way = 'ASC';

 

Anyone?

Link to comment
Share on other sites

  • 1 month later...

Try to rename the actual manufacturer name like:

01. Ibm

02. Compaq

and so on

The "01. " you add in front of the name will be automatically hid by Prestashop in the front store.

 

I just tried this it doesn't work , prestashop does not hide the number....am I missing anything? (prestashop 1.5)

Link to comment
Share on other sites

  • 1 year later...
  • 4 months later...
×
×
  • Create New...