Jump to content

Développement module problème de liens


Recommended Posts

Bonjour à tous !

Je me lance dans le développement d'un module et j'ai pour l'heure suivi l'exemple donné dans la documentation de prestashop (je suis sous la 1.7 https://developers.prestashop.com/module/05-CreatingAPrestaShop17Module/index.html)

Mais je n'arrive pas à avoir le même résultat, mon lien sur le site ne donne qu'une erreur 404 >< C'est cette partie de l'exemple que je n'arrive pas à reproduire : https://developers.prestashop.com/module/05-CreatingAPrestaShop17Module/05-DisplayingContentOnTheFrontOffice.html

Mon problème ce sont les fichiers display je pense, je ne comprends pas combien il en faut, car d'un coté je vois un display.php à mettre à la racine du projet, un autre display.php dans /controllers/front et enfin un display.tpl dans \views\templates\front.

Celui à la racine j'ai :

<?php

// This file must be placed at the root of the module's folder.
global $smarty;
include('../../config/config.inc.php');
include('../../header.php');

$smarty->display(dirname(__FILE__).'/display.tpl');

include('../../footer.php');

?>

 

l'autre display.php

 

<?php

class mymoduledisplayModuleFrontController extends ModuleFrontController
{
  public function initContent()
  {
    parent::initContent();
    $this->setTemplate('module:withdrawalform/views/templates/front/display.tpl');
  }
}

?>

 

et le template tout simple : Welcome to my shop!

Mon fichier withdrawalform.php (nom de mon module) :

<?php

if (!defined('_PS_VERSION_'))
{
  exit;
}

class WithdrawalForm extends Module
{
	public function __construct()
	{
		$this->name = 'withdrawalform';
		$this->tab = 'front_office_features';
		$this->version = '1.0.0';
		$this->author = 'Vincent Hawthorne';
		$this->need_instance = 0;
		$this->ps_versions_compliancy = array('min' => '1.7.2.4', 'max' => _PS_VERSION_);
		$this->bootstrap = true;

		parent::__construct();

		$this->displayName = $this->l('Withdrawal Form');
		$this->description = $this->l('Permet de générer un formulaire de rétractation en PDF');

		$this->confirmUninstall = $this->l('Are you sure you want to uninstall?');

		if (!Configuration::get('WITHDRAWALFORM_NAME'))
		  $this->warning = $this->l('No name provided');
	}
  
	public function getContent()
	{
		$output = null;

		if (Tools::isSubmit('submit'.$this->name))
		{
			$my_module_name = strval(Tools::getValue('WITHDRAWALFORM_NAME'));
			if (!$my_module_name
			  || empty($my_module_name)
			  || !Validate::isGenericName($my_module_name))
				$output .= $this->displayError($this->l('Invalid Configuration value'));
			else
			{
				Configuration::updateValue('WITHDRAWALFORM_NAME', $my_module_name);
				$output .= $this->displayConfirmation($this->l('Settings updated'));
			}
		}
		return $output.$this->displayForm();
	}  
  
	public function displayForm()
	{
		// Get default language
		$default_lang = (int)Configuration::get('PS_LANG_DEFAULT');

		// Init Fields form array
		$fields_form[0]['form'] = array(
			'legend' => array(
				'title' => $this->l('Settings'),
			),
			'input' => array(
				array(
					'type' => 'text',
					'label' => $this->l('Configuration value'),
					'name' => 'WITHDRAWALFORM_NAME',
					'size' => 20,
					'required' => true
				)
			),
			'submit' => array(
				'title' => $this->l('Save'),
				'class' => 'btn btn-default pull-right'
			)
		);

		$helper = new HelperForm();

		// Module, token and currentIndex
		$helper->module = $this;
		$helper->name_controller = $this->name;
		$helper->token = Tools::getAdminTokenLite('AdminModules');
		$helper->currentIndex = AdminController::$currentIndex.'&configure='.$this->name;

		// Language
		$helper->default_form_language = $default_lang;
		$helper->allow_employee_form_lang = $default_lang;

		// Title and toolbar
		$helper->title = $this->displayName;
		$helper->show_toolbar = true;        // false -> remove toolbar
		$helper->toolbar_scroll = true;      // yes - > Toolbar is always visible on the top of the screen.
		$helper->submit_action = 'submit'.$this->name;
		$helper->toolbar_btn = array(
			'save' =>
			array(
				'desc' => $this->l('Save'),
				'href' => AdminController::$currentIndex.'&configure='.$this->name.'&save'.$this->name.
				'&token='.Tools::getAdminTokenLite('AdminModules'),
			),
			'back' => array(
				'href' => AdminController::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModules'),
				'desc' => $this->l('Back to list')
			)
		);

		// Load current value
		$helper->fields_value['WITHDRAWALFORM_NAME'] = Configuration::get('WITHDRAWALFORM_NAME');

		return $helper->generateForm($fields_form);
	} 
  
  
	public function install()
	{
	  if (Shop::isFeatureActive())
		Shop::setContext(Shop::CONTEXT_ALL);

	  return parent::install() &&
		$this->registerHook('leftColumn') &&
		$this->registerHook('header') &&
		Configuration::updateValue('WITHDRAWALFORM_NAME', 'my friend');
	}

	public function uninstall()
	{
		if (!parent::uninstall())
			return false;
		return true;
	}  
	
	public function hookDisplayLeftColumn($params)
	{
	  $this->context->smarty->assign(
		  array(
			  'my_module_name' => Configuration::get('WITHDRAWALFORM_NAME'),
			  'my_module_link' => $this->context->link->getModuleLink('withdrawalform', 'display')
		  )
	  );
	  return $this->display(__FILE__, 'withdrawalform.tpl');
	}

	public function hookDisplayRightColumn($params)
	{
	  return $this->hookDisplayLeftColumn($params);
	}

	public function hookDisplayHeader()
	{
	  $this->context->controller->addCSS($this->_path.'css/withdrawalform.css', 'all');
	}	
  
}








?>

 

Le lien problématique est visible sur : https://www.laboutiquedegeorgette.com/

 

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