Jump to content

Random Image of SubCategories


infotech

Recommended Posts

Hello, i need yours help please.

I want random image of subcategories selected with Product->reference of relative category

- The product image in my shop are with reference as name. Example: 21243.jpg

- The images of my shop are hosted in other server

 

I modified the file /classes/category.php but don't work.

Please help me, and sorry for my bad english! :D

 

public function getSubCategories($id_lang, $active = true)
{
  if (!Validate::isBool($active))
die(Tools::displayError());
 $groups = FrontController::getCurrentCustomerGroups();
 $sqlGroups = (count($groups) ? 'IN ('.implode(',', $groups).')' : '= 1');
 $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
 SELECT  c.*, cl.id_lang, cl.name, cl.description, cl.link_rewrite, cl.meta_title, cl.meta_keywords, cl.meta_description
 FROM `'._DB_PREFIX_.'category` c
 LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category` AND `id_lang` = '.(int)($id_lang).')
 LEFT JOIN `'._DB_PREFIX_.'category_group` cg ON (cg.`id_category` = c.`id_category`)
	WHERE `id_parent` = '.(int)($this->id).'
 '.($active ? 'AND `active` = 1' : '').'
 AND cg.`id_group` '.$sqlGroups.'
 GROUP BY c.`id_category`
 ORDER BY `level_depth` ASC, c.`position` ASC');

 foreach ($result AS &$row)
 {
	  $ref = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
	SELECT p.reference
 FROM `ps_category` c
 LEFT JOIN `ps_product` p ON ( c.`id_category` = p.`id_category_default` )
 WHERE `id_parent` = '.(int)($this->id).'
	'.($active ? 'AND `active` = 1' : '').'
 ORDER BY RAND( )
 LIMIT 1 ');
	 $row['id_image'] = (My_Personal_Image_Dir_.$row['ref'].'.jpg') ? (int)($row['id_category']) : Language::getIsoById($id_lang).'-default';
  $row['legend'] = 'no picture';

 }

 return $result;

}

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