Jump to content

créer une page d'édition


Recommended Posts

Bonjour à tous, 

 

Je suis un développeur junior et je n'ai encore jamais essayé de m'attaquer à prestashop jusqu'à aujourd'hui.

 

Ce que je dois faire, c'est coder un morceau de programme en php qui va interagir avec les images produits, tout ce qui est côté php : je sais faire, mais il faut que ce programme soit paramétrable depuis l'interface de modification des produits, je dois donc créer un nouvel onglet(il comportera un formulaire pour les différents paramètres qui appellera mon code php) au même endroit que "prix" "information" "SEO" etc, dans la colonne qui apparait à gauche. Et c'est là tout le problème : j'ai cherché sur internet et dans les dossiers du prestashop, et je n'ai absolument rien trouver pour m'aider a intégrer ceci. 

J'ai donc besoin de savoir comment je peux créer cet onglet. 

 

Merci d'avance pour votre aide :)

 

Link to comment
Share on other sites

Bonsoir, j ai commencé a faire un module pour afficher une video dans une fiche produit via Projekktor (lecteur video html5), l'affichage de ce que tu demande est via la fonction hookDisplayAdminProductsExtra ca pourra peut être t'aider:

<?php

if (!defined('_PS_VERSION_'))

  exit;
 
class tgprojekktor extends Module
{
	  /**
    * Declaration du module
    */
    
	public function __construct()
	{
		$this->name = 'tgprojekktor';
    	$this->tab = 'front_office_features';
    	$this->version = '1.0';
    	$this->author = 'Alexandre KM';
    	$this->need_instance = 1;
    	$this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.6');
    	parent::__construct();
    	$this->displayName = $this->l('Vidéo Projekktor');
    	$this->description = $this->l('Permet de mettre une vidéo dans une fiche produit');
    	$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
   	 	if (!Configuration::get('tgprojekktor'))      
      	$this->warning = $this->l('No name provided');
	}
  
  	  /**
    * Installation et desinstallation
    */
    
    function install()
    {
        if (!parent::install() OR
            !$this->alterTable('add') OR         
				!$this->registerHook('header') OR 
            !$this->registerHook('displayTgprojekktor') OR
            !$this->registerHook('actionAdminControllerSetMedia') OR
        		!$this->registerHook('actionProductUpdate') OR
        		!$this->registerHook('displayAdminProductsExtra') OR
        		!$this->registerHook('displayBackOfficeHeader')

            )
            return false;
        return true;
    }
    
	public function uninstall()
	{
    if (!parent::uninstall() OR !$this->alterTable('remove'))
        return false;
    return true;
	}
	

	
/**
* Ajouter la table video_url dans la base product lang
*/
	
	public function alterTable($method)
	{
    switch ($method) {
        case 'add':
            $sql = 'ALTER TABLE ' . _DB_PREFIX_ . 'product_lang ADD `video_url` VARCHAR(500) NOT NULL';
            break;
         
        case 'remove':
          $sql = 'ALTER TABLE ' . _DB_PREFIX_ . 'product_lang DROP COLUMN `video_url`';
            break;
    	}
     
    if(!Db::getInstance()->Execute($sql))
        return false;
    return true;
	}
	
 


/**
 * Assign à smarty la variable video_url à tgprojekktortab.tpl dans l'admin fiche produit
 */
    
public function prepareNewTab()
{
 
    $this->context->smarty->assign(array(
        'video_url' => $this->getVideoUrl((int)Tools::getValue('id_product')),
        'languages' => $this->context->controller->_languages,
        'default_language' => (int)Configuration::get('PS_LANG_DEFAULT')
    ));
 
}


 /**
* Affichage de tgprojekktortab.tpl dans l'admin fiche produit
*/
    
public function hookDisplayAdminProductsExtra($params)
{
	 //include_once(dirname(__FILE__).'controllers/admin/AdmintgprojekktorController.php');		 
    
    if (Validate::isLoadedObject($product = new Product((int)Tools::getValue('id_product'))))
    {

      $this->prepareNewTab();
      return $this->display(__FILE__, 'views/templates/admin/tggprojekktortab.tpl');
		

    }
    

}

/**
* Affichage de js dans le backoffice
*/
public function hookActionAdminControllerSetMedia($params)
{
 
    // add necessary javascript to products back office
    if($this->context->controller->controller_name == 'AdminProducts' && Tools::getValue('id_product'))
    {
        $this->context->controller->addJS($this->_path.'/js/tgprojekktor.js');
    }
 
}
   
/**
* A la mise a jour du produit update des tables dans la base de donnée
*/
    
	public function hookActionProductUpdate($params)
{
    // get all languages
    // for each of them, store the new field
    $id_product = (int)Tools::getValue('id_product');
    $languages = Language::getLanguages(true);
    foreach ($languages as $lang) {
        if(!Db::getInstance()->update('product_lang', array('video_url'=> pSQL(Tools::getValue('video_url_'.$lang['id_lang']))) ,'id_lang = ' . $lang['id_lang'] .' AND id_product = ' .$id_product ))
            $this->context->controller->_errors[] = Tools::displayError('Error: ').mysql_error();
    }
}
/**
* Va chercher le champs dans la base de donnée
*/
public function getVideoUrl($id_product)
{
    $result = Db::getInstance()->getValue('SELECT video_url FROM '._DB_PREFIX_.'product_lang WHERE id_product = ' . (int)$id_product . ' AND id_lang = ' . $this->context->language->id);
    if(!$result)
        return false;

    return $result;
}
	
/**
* Assign à smarty la variable video_url
*/
    
public function getVariable()
{
    $this->context->smarty->assign('video_url', $this->getVideoUrl((int)Tools::getValue('id_product')));
 
}


		/**
    * Affiche moi tgprojekktor.tpl dans le hook pour le front
    */
    	
	public function hookDisplayTgProjekktor($params)
	{

		$this->getVariable();
		return $this->display(__FILE__, 'views/templates/front/tgprojekktor.tpl');
	}
	
	/**
    * Affiche moi les css et js dans le header quand on se trouve dans l'admin
    */
    public function hookDisplayBackOfficeHeader(){

    return $this->display(__FILE__, 'views/templates/admin/adminheader.tpl');

	}
    
    

	
		
}


Edited by Alexandre-KM (see edit history)
Link to comment
Share on other sites

Bonjour , moi aussi j'essaye d'utiliser ce code pour rajouter une variable à produit via un onglet hookDisplayAdminProductsExtra

 

Mais je rencontre un soucis à la récuperation de la variable dans mon views/templates/admin/tggprojekktortab.tpl

 

la variable s'enregistre bien en BD mais quand je reviens dans le BO pour l’éditer il ne m'affiche que la 2e lettre de ma variable dans le champs input !?

 

exemple : si j'ai enregistré comme valeur : http://www.monlienvideo.com

quand je reviens dans le BO la valeur dans le champs affiche : t

 

du coup j'ai ajouté une div dans mon .tpl comme suit pour connaitre la valeur de ma variable

<div>{$video_url}</div>

et celle ci affiche bien http://www.monlienvideo.com

 

voici mon tggprojekktortab.tpl

<div id="product-video" class="panel product-tab">
	<input type="hidden" name="submitted_tabs[]" value="video" />
	<h3 class="tab"> <i class="icon-info"></i> {l s='video' mod='newfieldstut'}</h3> 

<h4>{l s='New Fields Tutorial' mod='newfieldstut'}</h4>
<div class="separation"></div>


<table>
	
	<tr>
		<td class="col-left">
			<label>{l s='Our New Field:'}</label>
		</td>
		<td>
			{include file="controllers/products/input_text_lang.tpl"
				languages=$languages
				input_value=$video_url
				input_name="video_url"
				}
				<div>{$video_url}</div>
			<p class="preference_description">{l s='Simply a new custom field'}. <strong>{l s='ie: something here as a hint'}</strong></p>
		</td>
	</tr>
</table>

<div class="panel-footer">
        <a href="{$link->getAdminLink('AdminProducts')|escape:'html':'UTF-8'}" class="btn btn-default"><i class="process-icon-cancel"></i> {l s='Cancel'}</a>
        <button type="submit" name="submitAddproduct" class="btn btn-default pull-right"><i class="process-icon-save"></i> {l s='Save'}</button>
        <button type="submit" name="submitAddproductAndStay" class="btn btn-default pull-right"><i class="process-icon-save"></i> {l s='Save and stay'}</button>
    </div>

je ne comprends pas pourquoi quand je reviens editer mon lien il ne m'affiche que la 2e lettre de ma variable.

 

Des idées? Merci d'avance.

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