Jump to content

[SOLVED] module if statement in controller


cocodeluxe

Recommended Posts

Hi and thanks for the support

 

I've been watching this code in this tutorial

http://nemops.com/page-specific-prestashop-module/#.U2uiz_l_uAW

if('category' != $this->context->controller->php_self)
    return false;

and I would need to know if there is a conditional determined for a category id or something

 

 

thanks and regards

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

Nemo show me the light

Tools::getValue('id_category') == THE_ONE_TO_CHECK

I made the statement in this way but not work 

 

public function hookDisplayBanner($params)
{ 
       if ( Tools::getValue('id_category') == 4 $this->context->controller->php_self) 




             return false;
return $this->hookDisplayTop($params);
}

What can I do with this ?

 

 

thanks

Link to comment
Share on other sites

if ( Tools::getValue('id_category') == 4 $this->context->controller->php_self) 

this statement is wrong.

 

 

use this one instead:

if ( Tools::getValue('id_category') == 4 ) 

it means "if id_category=4 then do sometihng"

 

or use this one

if ( Tools::getValue('id_category') != 4 ) 

if id category is not 4 then do something

Link to comment
Share on other sites

I tried this conditional to display the contents of a module in a single category

 

in this way, blocklinks module

 

public function hookLeftColumn($params) { 
if ( Tools::getValue('id_category') != 4 ) 


            return false; 
}


$links = $this->getLinks();


$this->smarty->assign(array(
'blocklink_links' => $links,
'title' => Configuration::get('PS_BLOCKLINK_TITLE', $this->context->language->id),
'url' => Configuration::get('PS_BLOCKLINK_URL'),
'lang' => 'text_'.$this->context->language->id
));
if (!$links)
return false;


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

it´s right?

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

hello,

it's wrong. you missed open bracket after if condition.

 

 

let me know something

you want to display something when category id = 4 

or you want to display something when category id is not equal to 4 ?

Link to comment
Share on other sites

hello,

it's wrong. you missed open bracket after if condition.

 

 

let me know something

you want to display something when category id = 4 

or you want to display something when category id is not equal to 4 ?

 

Only display in category id =4

 

 

Thanks

Link to comment
Share on other sites

so you have to use this:
 

public function hookLeftColumn($params) {
if (isset($_GET['id_category'])){
 if (Tools::getValue('id_category') == 4){
   $links = $this->getLinks();
   $this->smarty->assign(array(
   'blocklink_links' => $links,
   'title' => Configuration::get('PS_BLOCKLINK_TITLE', $this->context->language->id),
   'url' => Configuration::get('PS_BLOCKLINK_URL'),
   'lang' => 'text_'.$this->context->language->id
  ));
  if (!$links)
  return false;
  return $this->display(__FILE__, 'blocklink.tpl');
  }
}
}
Link to comment
Share on other sites

I wanted to say that the content appears in all least one , for example excluided category id =5. I said before about a !=5 and return false or something

 

 

 

 

in the above example I can use multiple ids. 4,5, 6. ?

 

if (Tools::getValue('id_category') == 4)

 

 

 

 

Very thanks

Link to comment
Share on other sites

code above will display content only on category page == 4

 

if you want to HIDE it only on category == 5 just use !=5 instead of ==5

 

and yes, you can use many conditions there

if ($something == 1 || $something2==2 || $something3 == 3){
do something
}

|| means "OR"

Link to comment
Share on other sites

Hello,

 

The best way to do this is this code because there is no need to use isset for notice errors etc.

 

public function hookLeftColumn($params) {

$categoriesArray = array(3,4,5,6,8,9);
$currentCategory = Tools::getValue('id_category', 0);

if(in_array($currentCategory, $categoriesArray)
{
   $links = $this->getLinks();
   $this->smarty->assign(array(
   'blocklink_links' => $links,
   'title' => Configuration::get('PS_BLOCKLINK_TITLE', $this->context->language->id),
   'url' => Configuration::get('PS_BLOCKLINK_URL'),
   'lang' => 'text_'.$this->context->language->id
  ));
  if (!$links)
  return false;
  return $this->display(__FILE__, 'blocklink.tpl');
}
}
Link to comment
Share on other sites

 

sorry for reopen

it´s posible this:

 if (Tools::getValue('id_category') == 3 ||('id_category') == 4){

 

this code is wrong, code below is proper one

 if (Tools::getValue('id_category') == 3 || Tools::getValue('id_category') == 4){
Link to comment
Share on other sites

Hello,

 

The best way to do this is this code because there is no need to use isset for notice errors etc.

 

public function hookLeftColumn($params) {

$categoriesArray = array(3,4,5,6,8,9);
$currentCategory = Tools::getValue('id_category', 0);

if(in_array($currentCategory, $categoriesArray)
{
   $links = $this->getLinks();
   $this->smarty->assign(array(
   'blocklink_links' => $links,
   'title' => Configuration::get('PS_BLOCKLINK_TITLE', $this->context->language->id),
   'url' => Configuration::get('PS_BLOCKLINK_URL'),
   'lang' => 'text_'.$this->context->language->id
  ));
  if (!$links)
  return false;
  return $this->display(__FILE__, 'blocklink.tpl');
}
}

With this code i have a 

 

Parse error: syntax error, unexpected '{' in /customers/0/0/7/lonelite.com/httpd.www/modules/blocklink/blocklink.php on line 121

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