Jump to content

[SOLVED]Current category id if exists


R.Kinkeris

Recommended Posts

Hello,
Does anyone know how can I get the current category only if it exists. I need to pass the parameter to mysql query only if it exists.

 

'weeksBestseller' => ProductSale::weeksBestseller((int)$this->context->cookie->id_lang, $quantity, $days, Tools::getValue('id_category'))

Tools::getValue('id_category') gets the category if category isset, but on home page the category isn't set. And the query fails. Any idea how can I pass the parameter to the function only if ii isset?

 

The query uses default parameter if it's not overridden. 

public static function weeksBestseller($id_lang, $quantity, $days, $category = 'p.`id_category_default`', Context $context = null)
Edited by R.Kinkeris (see edit history)
Link to comment
Share on other sites

Problem solved. Works when using this syntax. In controller->

 

$categ = Tools::getValue('id_category');
if(!isset($catr)) {
	$categ = NULL;
};
$this->smarty->assign(array(
	'best_sellers' => $best_sellers,
	'weeksBestseller' => ProductSale::weeksBestseller((int)$this->context->cookie->id_lang, $quantity, $days, $categ),
));

and in class ->

 

public static function weeksBestseller($id_lang, $quantity, $days, $category = NULL, Context $context = null)
{
	if ($category == NULL) {
		$category = 2;
	}
}

where category 2 is home.

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