Jump to content

Liste des fabricants


Recommended 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

Link to comment
Share on other sites

  • 1 year later...
  • 4 months later...

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.prestashop.com/forums/viewthread/10155/modules_tiers/ajouter_une_colonne_ordre_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é?

Link to comment
Share on other sites

  • 7 months later...
  • 1 month later...
  • 5 months later...

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

Link to comment
Share on other sites

  • 8 months later...

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...