Jump to content

[Contribution]Menu vertical relatives au pages CMS


Recommended Posts

Bonjour,

Je partage avec vous une astuce que j'ai adopté pour modifier le module blockcms à qu'il soit un menu vertical.

Le menu marche bien que ce soit avec l'activiation d'url ou sans.

J'ai fait ceci :

Dans modules/blockcms/blockcms.php, j'ai ajouter ceci à la méthode hookLeftColumn

 

 

 


$urlVars =explode("/",$_SERVER['REQUEST_URI']);																						  
  if ((int)(Configuration::get('PS_REWRITING_SETTINGS') == 1)){																						  
  $urlVars =explode("/",$_SERVER['REQUEST_URI']);																						  
  $link_url = $urlVars[sizeof($urlVars)-1];																						  
  $tab_id_cms = array();																						  
  $tab_id_cms = explode("-",$link_url);																						  
  $id_cms = $tab_id_cms[0];																						  
  }																						  
 else{																						  
   $id_cms= Tools::getValue('id_cms');																						  
 }																						  
$cms = new CMS((int)$id_cms);																					
[size=1]$cat= $cms->id_cms_category;		  
$smarty->assign('id_category', $cat);		

avant l'appel de

 

	return $this->display(__FILE__, 'blockcms.tpl');	

il faut ne pas oublié de faire l'inclusion du classe CMS

avec

 

 

include_once(dirname(__FILE__) .'/../../classes/CMS.php');		 

avant la définition de la classe.

Dans la méthode

 

 

 public static function getCMStitles($location)			

j'ai ajouté

 

 

 

$content[$key]['id_cms_category'] =$cmsCategory['id_cms_category'];

après

 

 

  $content[$key]['category_name'] =$cmsCategory['category_name'];

à la fin de la méthode et au sein de la boucle

 

 

foreach ($cmsCategories AS $cmsCategory) 

 

Ensuite dans le tpl: dans VOTRE_THEME/modules/blckcms/blockcms.tpl (s'il ya de l'override) ou bien dans modules/blockcms/blockcms.tpl

Il faut ajouter une condition if pour afficher que le bloc cms relative à la page cms en cours

après

 

 

  {foreach from=$cms_titles key=cms_key item=cms_title}	

il faut ajouter

 

 

 

 {if $id_category == $cms_title.id_cms_category}  

à la fin il faut fermer le if par

{/if]

avant le

 

 

		{/foreach}

qui précéde le commentaire

 

 

 <!-- /Block CMS module --> 

Vous pouvez ensuite modifier le css du module à votre guise :)

J'espère que ce post vous a aidé pour adapter le module blockcms pour qu'il soit semblable à un menu vertical.

J'espère que cette solution vous as aidé et vous a permis de faire des économies de quelques €

blockcms.zip

Edited by tarek.fellah (see edit history)
  • Like 1
Link to comment
Share on other sites

Pour le principe, je récupère l'id catégorie de la page cms en cours, depuis le php, et dans le tpl n'afficher que le bloc cms relative à cette catégorie.

Si vous avez connaissance du module block cms ,il affiche un bloc (menu) pour chaque catégorie cms spécifié dans le backoffice

Dans le tpl, la boucle

 

{foreach from=$cms_titles key=cms_key item=cms_title}

 

parcours l'ensemble des blocs cms (pour la langue courante) des différends catégorie (ajouté au BO du module blockcms)

donc

pour avoir le bloc cms de la catégorie de la page cms en cours

je fais

{if $id_category == $cms_title.id_cms_category}

 

ces deux variables assignés dans le blockcms.php comme ceci

 

 

$smarty->assign('id_category', $cat);$smarty->assign(array('block' => 1,'cms_titles' => $cms_titles,'theme_dir' => _PS_THEME_DIR_));

 

 

$cms_titles est un tableau de tableaux

 

dans GetCmsTitles($location)

$cms_titles = self::getCMStitles(self::LEFT_COLUMN);

return un tableau qui contient l'ensemble des bloc cms créés dans le BO du module.

Dans

GetCmsTitles($location)

j'ai ajouté

$content[$key]['id_cms_category'] =(int)$cmsCategory['id_cms_category']; 

pour avoir l'id catégorie de chaque bloc

J'espère être le plus clair possible.

Edited by tarek.fellah (see edit history)
Link to comment
Share on other sites

  • 1 month later...

1 million thanks Tarek, it worked perfect for me!

 

Do you now how could I highlight the current page <li><a> in that block? I mean to add a "class='selected'" to the current list item.

 

EDIT: don't know why, but when installing this, I get an error 500 in every page except of the CMS pages, which works fine.

 

I'm using Prestashop 1.4.8.2

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

  • 2 months later...

Hi again, Tarek!

 

Finally I managed to upgrade my site to 1.5.1 and your module was working well, but didn't noticed that when I activate your module, I lose some search functions.

 

In detail, when your module is active, the pagination of every search-result page, doesn't link well. Every button at the pagination part has a link like this:

 

index.php?controller=cms?tag=XXXXXX&p=2

index.php?controller=cms?tag=XXXXXX&p=3

 

when it should be:

 

search?tag=XXXXXX&p=2

search?tag=XXXXXX&p=2

 

...and I get a 404 page, my visitors only can see the first page when they search.

 

Have tested and isolated the problem, the only module that is pulling this error is this one (yours) :(

 

Your help would be MUCH appreciated.

Link to comment
Share on other sites

  • 2 years later...

1 million thanks Tarek, it worked perfect for me!

 

Do you now how could I highlight the current page <li><a> in that block? I mean to add a "class='selected'" to the current list item.

 

EDIT: don't know why, but when installing this, I get an error 500 in every page except of the CMS pages, which works fine.

 

I'm using Prestashop 1.4.8.2

Hi,

It might be too late,

You should activate the DEV_MODE to see the errors

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