Jump to content

Copy of prestashop plugin installs but doesn't function as expected


Recommended Posts

I have a prestashop plugin that adds an extra tab to the product page:

 

<?php

   // Disable direct addressing to the script:
   if (!defined('_PS_VERSION_'))
       exit;

   //Create module class:
   class producttab extends Module {

   //Class constructor that contains its configuration:
   public function __construct()
   {
       $this->name = "producttab"; //Module name
       $this->tab = "front_office_features"; //Tab with the module in Prestashop back-office modules list
       $this->version = "1.0"; // Module version
       $this->author = "BelVG";  // Module author 
       parent::__construct();
       $this->displayName = $this->l("Product Tab"); // Module title
       $this->description = $this->l("Module creates a new tab on the frontend product page "); // Module description 
   }

   //Module installation-method:
   public function install()
   {
       return (parent::install()
               AND $this->registerHook('productTab') //Register productTab hook that will display the tab button
               AND $this->registerHook('productTabContent') //Register productTabContent hook that will display the tab content
               );
   }

   //Module deinstallation-method:
   public function uninstall()
   {
       return (parent::uninstall()
               AND $this->unregisterHook('productTab')
               AND $this->unregisterHook('productTabContent')); // Delete all hooks, registered by the  module 
   }

   //Method will be called while performing the "ProductTab" hook (tab buttons generation):
   public function hookProductTab($params)
   {
       global $smarty;
       //Call the template containing the HTML-code ?? our button
       return $this->display(__FILE__ , 'tpl/productTab.tpl');
   }

   public function hookProductTabContent($params)
   {
       global $smarty;
       //Transfer the new tab content into template via smatry
       //( it is optional as far as the content can be assigned directly in the template)
        $result = Db::getInstance()->executeS('SELECT * FROM ps_cms_lang WHERE id_cms =14');

   $smarty->assign('content', $result);
       // Call the template containing the HTML-code of our new tab content:
       return $this->display(__FILE__ , 'tpl/productTabContent.tpl');
   }

   }
   ?>

The module works as expected. I'm trying to adapt the same code to add another tab. For some reason the new module installs but the tab does not appear. Is there something I'm missing?

 

<?php

   // Disable direct addressing to the script:
   if (!defined('_PS_VERSION_'))
   exit;

   //Create module class:
   class jewellerytab extends Module {

   //Class constructor that contains its configuration:
   public function __construct()
   {
       $this->name = "jewellerytab"; //Module name
       $this->tab = "front_office_features"; //Tab with the module in Prestashop back-office modules list
       $this->version = "1.0"; // Module version
       $this->author = "James Filtness";  // Module author 
       parent::__construct();
       $this->displayName = $this->l("jewellery Tab"); // Module title
       $this->description = $this->l("Module creates a new tab on the frontend jewellery page "); // Module description 
   }

   //Module installation-method:
   public function install()
   {
       return (parent::install()
               AND $this->registerHook('jewelleryTab') //Register jewelleryTab hook that will display the tab button
               AND $this->registerHook('jewelleryTabContent') //Register jewelleryTabContent hook that will display the tab content
               );
   }

   //Module deinstallation-method:
   public function uninstall()
   {
       return (parent::uninstall()
               AND $this->unregisterHook('jewelleryTab')
               AND $this->unregisterHook('jewelleryTabContent')); // Delete all hooks, registered by the  module 
   }

   //Method will be called while performing the "jewelleryTab" hook (tab buttons generation):
   public function hookjewelleryTab($params)
   {
       global $smarty;
       //Call the template containing the HTML-code ?? our button
       return $this->display(__FILE__ , 'tpl/jewelleryTab.tpl');
   }

   public function hookjewelleryTabContent($params)
   {
       global $smarty;
       //Transfer the new tab content into template via smatry
       //( it is optional as far as the content can be assigned directly in the template)
        $result = Db::getInstance()->executeS('SELECT * FROM ps_cms_lang WHERE id_cms =14');

   $smarty->assign('content', $result);
       // Call the template containing the HTML-code of our new tab content:
       return $this->display(__FILE__ , 'tpl/jewelleryTabContent.tpl');
   }

   }
   ?>

Link to comment
Share on other sites

HI there,

 

Thanks for the reply. The module does actually work with 1.5. I've been trying to adapt it to add another tab....like so:

 

<?php

// Disable direct addressing to the script:
if (!defined('_PS_VERSION_'))
exit;

//Create module class:
class jewellerytab extends Module {

//Class constructor that contains its configuration:
public function __construct()
{
	$this->name = "jewellerytab"; //Module name
	$this->tab = "front_office_features"; //Tab with the module in Prestashop back-office modules list
	$this->version = "1.0"; // Module version
	$this->author = "[color=#008800][size=2]BelVG[/size][/color]";  // Module author
	parent::__construct();
	$this->displayName = $this->l("Jewellery Tab"); // Module title
	$this->description = $this->l("Module creates a jewellery tab on the frontend product page "); // Module description
}

  /* Installation function. You can add your own functions here, save your initial config options in the database or hook your display TPL file to a section of the system, or anything else you want  */
function install() {
	if (!parent::install())
		return false;
	// this little function updates (or creates if it doesn't exist) a value in the settings table.
return true;
}

/* Uninstall function. You can use it to get rid of your settings stored in the config database table */
public function uninstall() {
	if (!parent::uninstall())
  return false;
	  return true;
}

//Method will be called while performing the "ProductTab" hook (tab buttons generation):
public function hookProductTab($params)
{
	global $smarty;
	//Call the template containing the HTML-code ?? our button
	return $this->display(__FILE__ , 'tpl/jewelleryTab.tpl');
}

public function hookProductTabContent($params)
{
	global $smarty;
	//Transfer the new tab content into template via smatry
	//( it is optional as far as the content can be assigned directly in the template)
	// $result = Db::getInstance()->executeS('SELECT * FROM ps_cms_lang WHERE id_cms =14');
//$smarty->assign('content', $result);
	// Call the template containing the HTML-code of our new tab content:
	return $this->display(__FILE__ , 'tpl/jewelleryTabContent.tpl');
}

}
?>

 

BUt for some reason it doesn't work....I've renamed all of the associated files....any ideas? I can't see anything wrong with this code. I've added some sql in there but that's all functioning fine...no errors reported

 

I am teaching myself module development this week so hopefully I can find the solution myself.

Edited by elduderino (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...