Forum PrestaShop

Il Forum di PrestaShop è lo spazio in cui puoi condividere con la comunità di PrestaShop consigli pratici sull'e-commerce e trovare la risposta a tutte le domande tecniche e funzionali.

Forum PrestaShop

Jump to content

 

Liste des fabricants

8 replies to this topic
#1
ZonTavE

    PrestaShop Apprentice

  • Members
  • PipPip
  • 30 posts
Salut out le monde,

petite question, comment est-ce que je pourrais faire en sorte que l'affichage des fabricant dans le module fabricant soit affiché dans un ordre aléatoire et nom dans l'ordre alphabetique?

Merci beaucoup d'avance ;-)

Topic déplacé -yoya971

#2
Dale Cooper

    PrestaShop Newbie

  • Members
  • Pip
  • 1 posts
Hello,

voilà ce que j'ai fait pour obtenir ce résultat :

dans classes/Manufacturer.php , ligne 127 j'ai remplacé

$sql.= ' ORDER BY m.`name` ASC';


par

$sql.= ' ORDER BY RAND()';


that's all :)

#3
ZonTavE

    PrestaShop Apprentice

  • Members
  • PipPip
  • 30 posts
Super merci vraiment beaucoup.

#4
olivierl

    PrestaShop Newbie

  • Members
  • Pip
  • 21 posts
J'ajoute une question : est-il possible de choisir l'ordre d'affichage des fabricants comme on peut le faire pour les catégories (01.Catégorie name) ?

Merci !

#5
labutte

    PrestaShop Newbie

  • Members
  • Pip
  • 4 posts
Bonjour,

@olivierl : je cherche aussi à choisir l'ordre d'ffichage des fabricants. Quelqu'un a déjà posté une solution dans ce post :

http://www.prestasho...e_au_fabriquant

Malheureusement je n'ai pas réussi à faire fonctionner cette modif...
J'ai ajouté la fonction hideManufacturerPosition($name) puis modifié getNameById($id_manufacturer) mais sans succès.
Je suis sur 1.3.1
Quelqu'un a-t-il déjà essayé?

#6
matt

    PrestaShop Apprentice

  • Members
  • PipPip
  • 51 posts
Merci !!
Sinon mettre
$sql.= ' ORDER BY m.`id_manufacturer` ASC'.($p ? ' LIMIT '.((intval($p) - 1) * intval($n)).','.intval($n) : ''); 
si vous vous classer par ordre d'ID
Référencez vos sites e-commerce par l'agence référencement -
Création site internet

#7
anne4113

    PrestaShop Apprentice

  • Members
  • PipPip
  • 68 posts
Ca c'est super mais comment fait-on ensuite pour changer l'ordre des identifiants ? Et puis tant que j'y suis, comment fait-on pour laisser par ordre alphabétique dans la liste déroulante ?

#8
toto37

    PrestaShop Newbie

  • Members
  • Pip
  • 7 posts
Sur version 1.4.3
Pour la liste déroulante, je l'ai supprimé et à la place j'ai rajouté un lien "voir tous les fabriquants" (je sais que ça fait redondance avec le H4, mais le premier est plus un titre de rubrique)
Sinon, pour faire propre y'a moyen d'extend la classe dans le repertoire override, explication :

Dans module>blockmanufacturer>blockmanufacturer.php
Remplacer
$smarty->assign(array(
	   	 'manufacturers' => Manufacturer::getManufacturers(),
par
$smarty->assign(array(
			'manufacturers' => Manufacturer::getManufacturersRand(),

Puis créer dans le repertoire override>classes un fichier Manufacturer.php, et y mettre ce code :
<?php
 
class Manufacturer extends ManufacturerCore
{
	public		 $id;
 
	/** @var integer manufacturer ID */
	public		$id_manufacturer;//FIXME is it really usefull...?
 
	/** @var string Name */
	public		 $name;
 
	/** @var string A description */
	public		 $description;
 
	/** @var string A short description */
	public		 $short_description;
 
	/** @var int Address */
	public		 $id_address;
 
	/** @var string Object creation date */
	public		 $date_add;
 
	/** @var string Object last modification date */
	public		 $date_upd;
 
	/** @var string Friendly URL */
	public		 $link_rewrite;
 
	/** @var string Meta title */
	public		 $meta_title;
 
	/** @var string Meta keywords */
	public		 $meta_keywords;
 
	/** @var string Meta description */
	public		 $meta_description;
 
	/** @var boolean active */
	public		$active;
 
	 protected	 $fieldsRequired = array('name');
	 protected	 $fieldsSize = array('name' => 64);
	 protected	 $fieldsValidate = array('name' => 'isCatalogName');
 
	protected	$fieldsSizeLang = array('short_description' => 254, 'meta_title' => 128, 'meta_description' => 255, 'meta_description' => 255);
	protected	$fieldsValidateLang = array('description' => 'isString', 'short_description' => 'isString', 'meta_title' => 'isGenericName', 'meta_description' => 'isGenericName', 'meta_keywords' => 'isGenericName');
 
	protected	 $table = 'manufacturer';
	protected	 $identifier = 'id_manufacturer';
 
	protected	$webserviceParameters = array(
		'fields' => array(
			'link_rewrite' => array('getter' => 'getLink', 'setter' => false),
		),
		'associations' => array(
			'addresses' => array('resource' => 'address', 'setter' => false, 'fields' => array(
				'id' => array('xlink_resource' => 'addresses'),
			)),
		),
	);
 
static public function getManufacturersRand($getNbProducts = 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 m.`name` ASC'.($p ? ' LIMIT '.(((int)($p) - 1) * (int)($n)).','.(int)($n) : '');
		$sql.= ' ORDER BY RAND()';
		$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;
	}
}

Il vous reste plus qu'à choisir le nombre de fabricants a afficher dans backoffice ^^

Personnellement, je compte transformer ces fabricants en logo, histoire d'avoir un peu un affichage type facebook des fabricants

#9
daftfunk

    PrestaShop Apprentice

  • Members
  • PipPip
  • 52 posts
est ce possible d'avoir les logo en random et la liste en alphabétique?