Jump to content

[SOLVED] Losing module php and css when clicking more on product


Robnola

Recommended Posts

Whenever I click "more" on a product from the main page or login I lose my #right_column custom modules php and css link. The tpl is still there because the HTML is generated.

 

Here is my PHP code. How can I keep my right side bar module when switching from the main page to a sub page?

<?php

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

class MySidebar extends Module
{

  public function __construct()
  {
	$this->name = 'mysidebar';
    $this->tab = 'front_office_features';
    $this->version = '1.0';
    $this->author = 'Firstname Lastname';
    $this->need_instance = 0;
	$this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_);
	$this->bootstrap = true;
	
    parent::__construct();

    $this->displayName = $this->l('My Sidebar');
    $this->description = $this->l('Description of my module.');
    $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');

    if (!Configuration::get('MYMODULE_NAME'))       
      $this->warning = $this->l('No name provided');
  }
	
	public function install()
	{
		if (Shop::isFeatureActive())
			Shop::setContext(Shop::CONTEXT_ALL);
	
		return parent::install() && $this->registerHook('leftColumn') && $this->registerHook('header') && Configuration::updateValue('MYMODULE_NAME', 'my friend');
	}
	
	public function uninstall()
	{
	  if (!parent::uninstall() || !Configuration::deleteByName('MYMODULE_NAME'))
			return false;
	  return true;
	}
	
	public function hookDisplayLeftColumn($params)
	{
		if (!$this->isCached('mysidebar.tpl', $this->getCacheId()))
		{
			$facebookurl = Configuration::get('blockfacebook_url');
			if (!strstr($facebookurl, 'facebook.com'))
				$facebookurl = 'https://www.facebook.com/'.$facebookurl;
			$this->context->smarty->assign('facebookurl', $facebookurl);
		}
		
		if (Tools::getValue('search_query') || !$this->isCached('mysidebar.tpl', $this->getCacheId()))
				{
					$this->calculHookCommon($params);
					$this->smarty->assign(array(
						'blocksearch_type' => 'block',
						'search_query' => (string)Tools::getValue('search_query')
						)
					);
				}
		Media::addJsDef(array('blocksearch_type' => 'block'));
		return $this->display(__FILE__, 'mysidebar.tpl', Tools::getValue('search_query') ? null : $this->getCacheId());
	}
   
	public function hookDisplayRightColumn($params)
	{
	  return $this->hookDisplayLeftColumn($params);
	}
	   
	public function hookDisplayHeader()
	{
	$this->page_name = Dispatcher::getInstance()->getController();
		if ($this->page_name == 'index')
		{
			$this->context->controller->addJS(($this->_path).'blockfacebook.js');
			$this->context->controller->addCSS($this->_path.'css/mysidebar.css', 'all');
		}
	}   
	
		private function calculHookCommon($params)
	{
		$this->smarty->assign(array(
			'ENT_QUOTES' =>		ENT_QUOTES,
			'search_ssl' =>		Tools::usingSecureMode(),
			'ajaxsearch' =>		Configuration::get('PS_SEARCH_AJAX'),
			'instantsearch' =>	Configuration::get('PS_INSTANT_SEARCH'),
			'self' =>			dirname(__FILE__),
		));

		return true;
	}
	
	public function getContent()
	{
		$html = '';
		// If we try to update the settings
		if (Tools::isSubmit('submitModule'))
		{
			Configuration::updateValue('blockfacebook_url', Tools::getValue('blockfacebook_url'));
			$html .= $this->displayConfirmation($this->l('Configuration updated'));
			$this->_clearCache('mysidebar.tpl');
			Tools::redirectAdmin('index.php?tab=AdminModules&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'));
		}

		$html .= $this->renderForm();
		$facebookurl = Configuration::get('blockfacebook_url');
		if(!strstr($facebookurl, "facebook.com")) $facebookurl="https://www.facebook.com/".$facebookurl;
		$this->context->smarty->assign('facebookurl', $facebookurl);
		$this->context->smarty->assign('facebook_js_url', $this->_path.'blockfacebook.js');
		$this->context->smarty->assign('facebook_css_url', $this->_path.'css/mysidebar.css');
		$html .= $this->context->smarty->fetch($this->local_path.'views/admin/_configure/preview.tpl');
		return $html;
	}
	
	public function renderForm()
	{
		$fields_form = array(
			'form' => array(
				'legend' => array(
					'title' => $this->l('Settings'),
					'icon' => 'icon-cogs'
				),
				'input' => array(
					array(
						'type' => 'text',
						'label' => $this->l('Facebook link (full URL is required)'),
						'name' => 'blockfacebook_url',
					),
				),
				'submit' => array(
					'title' => $this->l('Save')
				)
			),
		);

		$helper = new HelperForm();
		$helper->show_toolbar = false;
		$helper->table =  $this->table;
		$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
		$helper->default_form_language = $lang->id;
		$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
		$this->fields_form = array();

		$helper->identifier = $this->identifier;
		$helper->submit_action = 'submitModule';
		$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
		$helper->token = Tools::getAdminTokenLite('AdminModules');
		$helper->tpl_vars = array(
			'fields_value' => $this->getConfigFieldsValues(),
			'languages' => $this->context->controller->getLanguages(),
			'id_language' => $this->context->language->id
		);

		return $helper->generateForm(array($fields_form));
	}

	public function getConfigFieldsValues()
	{
		return array(
			'blockfacebook_url' => Tools::getValue('blockfacebook_url', Configuration::get('blockfacebook_url')),
		);
	}
}
?>



	


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

Oh silly me, it was this line of code, had to remove that condition so the js and css got loaded on other pages than index.

if ($this->page_name == 'index')
		{
			$this->context->controller->addJS(($this->_path).'blockfacebook.js');
			$this->context->controller->addCSS($this->_path.'css/mysidebar.css', 'all');
		}

Edited by Robnola (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...