Jump to content

Ajouter des champs pour la fiche Fabricants 1.6


Recommended Posts

Bonjour,

 

Je suis nouveau dans la communauté Prestashop et je dois ajouter des champs pour la fiche des fabricants comme par exemple l'URL de son site web. Nous avons fait la mise à jour donc on est sur la version 1.6.0.14.

 

Est-ce que quelqu'un serait quels fichiers je dois modifier ?

 

Merci beaucoup

 

 

Link to comment
Share on other sites

Bonjour,
C'est une bonne idée d'ajouter de nouveaux champs à la page du fabricant.
Du coup tu m' as donné l'envie d'essayer, je ne sais pas si c'est une bonne méthode mais chez moi ca marche, je suis en 1.6.
 
J'ouvre mon phpmyadmin, dans la table ps_manufacturer_lang
1) Dans onglet structure j'ajoute 2 colonnes de type text en fin de table nommées "mon_champ_1" et "mon_champ_2"
2) J'override Manufacturer.php (situé dans le dossier classe) que je le met dans override/classes/Manufacturer.php (j'efface class_index.php du dossier cache pour que les modifs soit prisent en compte):
 

<?php

class Manufacturer extends ManufacturerCore
{

public $mon_champ_1;
public $mon_champ_2;


	/**
	 * @see ObjectModel::$definition
	 */
	public static $definition = array(
		'table' => 'manufacturer',
		'primary' => 'id_manufacturer',
		'multilang' => true,
		'fields' => array(
			'name' => 				array('type' => self::TYPE_STRING, 'validate' => 'isCatalogName', 'required' => true, 'size' => 64),
			'active' => 			array('type' => self::TYPE_BOOL),
			'date_add' => 			array('type' => self::TYPE_DATE),
			'date_upd' => 			array('type' => self::TYPE_DATE),

			// Lang fields
			'description' => 		array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
			'short_description' => 	array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
			'mon_champ_1' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
        	'mon_champ_2' => array('type' => self::TYPE_HTML, 'lang' => true, 'validate' => 'isCleanHtml'),
			'meta_title' => 		array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 128),
			'meta_description' => 	array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'size' => 255),
			'meta_keywords' => 		array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName'),
		),
	);

	protected $webserviceParameters = array(
		'fields' => array(
			'active' => array(),
			'link_rewrite' => array('getter' => 'getLink', 'setter' => false),
		),
		'associations' => array(
			'addresses' => array('resource' => 'address', 'setter' => false, 'fields' => array(
				'id' => array('xlink_resource' => 'addresses'),
			)),
		),
	);

public static function getManufacturers($get_nb_products = false, $id_lang = 0, $active = true, $p = false, $n = false, $all_group = false, $group_by = false)
	{
		if (!$id_lang)
			$id_lang = (int)Configuration::get('PS_LANG_DEFAULT');
		if (!Group::isFeatureActive())
			$all_group = true;

		$manufacturers = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
		SELECT m.*, ml.`description`, ml.`short_description`, ml.`mon_champ_1`, ml.`mon_champ_2`
		FROM `'._DB_PREFIX_.'manufacturer` m
		'.Shop::addSqlAssociation('manufacturer', 'm').'
		INNER 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' : '')
		.($group_by ? ' GROUP BY m.`id_manufacturer`' : '' ).'
		ORDER BY m.`name` ASC
		'.($p ? ' LIMIT '.(((int)$p - 1) * (int)$n).','.(int)$n : ''));
		if ($manufacturers === false)
			return false;

		if ($get_nb_products)
		{
			$sql_groups = '';
			if (!$all_group)
			{
				$groups = FrontController::getCurrentCustomerGroups();
				$sql_groups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
			}

			$results = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS('
					SELECT  p.`id_manufacturer`, COUNT(DISTINCT p.`id_product`) as nb_products
					FROM `'._DB_PREFIX_.'product` p
					'.Shop::addSqlAssociation('product', 'p').'
					LEFT JOIN `'._DB_PREFIX_.'manufacturer` as m ON (m.`id_manufacturer`= p.`id_manufacturer`)
					WHERE product_shop.`visibility` NOT IN ("none")
					'.($active ? ' AND product_shop.`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` '.$sql_groups.'
					)
					GROUP BY p.`id_manufacturer`'
				));

			$counts = array();
			foreach ($results as $result)
				$counts[(int)$result['id_manufacturer']] = (int)$result['nb_products'];

			if (count($counts))
				foreach ($manufacturers as $key => $manufacturer)
					$manufacturers[$key]['nb_products'] = $counts[(int)$manufacturer['id_manufacturer']];
		}

		$total_manufacturers = count($manufacturers);
		$rewrite_settings = (int)Configuration::get('PS_REWRITING_SETTINGS');
		for ($i = 0; $i < $total_manufacturers; $i++)
			$manufacturers[$i]['link_rewrite'] = ($rewrite_settings ? Tools::link_rewrite($manufacturers[$i]['name']) : 0);
		return $manufacturers;
	}

}

3) J'override AdminManufacturersController.php (controllers/admin) que je place dans override/controllers/admin

<?php

class AdminManufacturersController extends AdminManufacturersControllerCore
{
	public function renderForm()
	{
		if (!($manufacturer = $this->loadObject(true)))
			return;

		$image = _PS_MANU_IMG_DIR_.$manufacturer->id.'.jpg';
		$image_url = ImageManager::thumbnail($image, $this->table.'_'.(int)$manufacturer->id.'.'.$this->imageType, 350,
			$this->imageType, true, true);
		$image_size = file_exists($image) ? filesize($image) / 1000 : false;

		$this->fields_form = array(
			'tinymce' => true,
			'legend' => array(
				'title' => $this->l('Manufacturers'),
				'icon' => 'icon-certificate'
			),
			'input' => array(
				array(
					'type' => 'text',
					'label' => $this->l('Name'),
					'name' => 'name',
					'col' => 4,
					'required' => true,
					'hint' => $this->l('Invalid characters:').' <>;=#{}'
				),
				array(
					'type' => 'textarea',
					'label' => $this->l('Short description'),
					'name' => 'short_description',
					'lang' => true,
					'cols' => 60,
					'rows' => 10,
					'autoload_rte' => 'rte', //Enable TinyMCE editor for short description
					'col' => 6,
					'hint' => $this->l('Invalid characters:').' <>;=#{}'
				),
				array(
					'type' => 'textarea',
					'label' => $this->l('Description'),
					'name' => 'description',
					'lang' => true,
					'cols' => 60,
					'rows' => 10,
					'col' => 6,
					'autoload_rte' => 'rte', //Enable TinyMCE editor for description
					'hint' => $this->l('Invalid characters:').' <>;=#{}'
				),

				array(
					'type' => 'textarea',
					'label' => $this->l('Mon champ 1'),
					'name' => 'mon_champ_1',
					'lang' => true,
					'cols' => 60,
					'rows' => 10,
					'col' => 6,
					'autoload_rte' => 'rte', //Enable TinyMCE editor for description
					'hint' => $this->l('Invalid characters:').' <>;=#{}'
				),
				array(
					'type' => 'textarea',
					'label' => $this->l('Mon champ 2'),
					'name' => 'mon_champ_2',
					'lang' => true,
					'cols' => 60,
					'rows' => 10,
					'col' => 6,
					'autoload_rte' => 'rte', //Enable TinyMCE editor for description
					'hint' => $this->l('Invalid characters:').' <>;=#{}'
				),
				array(
					'type' => 'file',
					'label' => $this->l('Logo'),
					'name' => 'logo',
					'image' => $image_url ? $image_url : false,
					'size' => $image_size,
					'display_image' => true,
					'col' => 6,
					'hint' => $this->l('Upload a manufacturer logo from your computer.')
				),
				array(
					'type' => 'text',
					'label' => $this->l('Meta title'),
					'name' => 'meta_title',
					'lang' => true,
					'col' => 4,
					'hint' => $this->l('Forbidden characters:').' <>;=#{}'
				),
				array(
					'type' => 'text',
					'label' => $this->l('Meta description'),
					'name' => 'meta_description',
					'lang' => true,
					'col' => 6,
					'hint' => $this->l('Forbidden characters:').' <>;=#{}'
				),
				array(
					'type' => 'tags',
					'label' => $this->l('Meta keywords'),
					'name' => 'meta_keywords',
					'lang' => true,
					'col' => 6,
					'hint' => array(
						$this->l('Forbidden characters:').' <>;=#{}',
						$this->l('To add "tags," click inside the field, write something, and then press "Enter."')
					)
				),
				array(
					'type' => 'switch',
					'label' => $this->l('Enable'),
					'name' => 'active',
					'required' => false,
					'class' => 't',
					'is_bool' => true,
					'values' => array(
						array(
							'id' => 'active_on',
							'value' => 1,
							'label' => $this->l('Enabled')
						),
						array(
							'id' => 'active_off',
							'value' => 0,
							'label' => $this->l('Disabled')
						)
					)
				)
			)
		);

		if (!($manufacturer = $this->loadObject(true)))
			return;

		if (Shop::isFeatureActive())
		{
			$this->fields_form['input'][] = array(
				'type' => 'shop',
				'label' => $this->l('Shop association'),
				'name' => 'checkBoxShopAsso',
			);
		}

		$this->fields_form['submit'] = array(
			'title' => $this->l('Save')
		);

		foreach ($this->_languages as $language)
		{
			$this->fields_value['short_description_'.$language['id_lang']] = htmlentities(stripslashes($this->getFieldValue(
				$manufacturer,
				'short_description',
				$language['id_lang']
			)), ENT_COMPAT, 'UTF-8');

			$this->fields_value['description_'.$language['id_lang']] = htmlentities(stripslashes($this->getFieldValue(
				$manufacturer,
				'description',
				$language['id_lang']
			)), ENT_COMPAT, 'UTF-8');

			$this->fields_value['mon_champ_1_'.$language['id_lang']] = htmlentities(stripslashes($this->getFieldValue(
				$manufacturer,
				'mon_champ_1',
				$language['id_lang']
			)), ENT_COMPAT, 'UTF-8');

			$this->fields_value['mon_champ_2_'.$language['id_lang']] = htmlentities(stripslashes($this->getFieldValue(
				$manufacturer,
				'mon_champ_2',
				$language['id_lang']
			)), ENT_COMPAT, 'UTF-8');


			
		}

		return AdminController::renderForm();
		
	}


}



4) J'appelle mes champs custom, dans le manufacturer.tpl de mon thème.
 
avec:

{$manufacturer->mon_champ_1}
{$manufacturer->mon_champ_2}

Quel est l'interet de faire des nouveaux champs pour un type de page ?
1) On peut facilement gérer ses pages produits, categories, marques, fournisseurs etc... via des fichiers excel (je prefere libre office), pour ensuite importer les csv... facilement vers prestashop.
2) On peut placer du texte à n'importe quels endroits de la page (header.tpl, footer.tpl etc...), surtout dans des balises style Hn.
 
Voila :)

Edited by Alexandre-KM (see edit history)
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...