easymar Posted May 13, 2012 Share Posted May 13, 2012 Now this module select only active products but includes products from inactive categories. How can I change this code to select products only from active categories? private static function alterName($name) { $r = str_replace('%s', $name, Configuration::get('katalogusnameString')); $r = str_replace('%/s','%s', $r); return ($r); } static public function countProducts($id_lang, $start, $limit, $orderBy, $orderWay, $id_category = false, $only_active = false) { if (!Validate::isOrderBy($orderBy) OR !Validate::isOrderWay($orderWay)) die (Tools::displayError()); if ($orderBy == 'id_product' OR $orderBy == 'price' OR $orderBy == 'date_add') $orderByPrefix = 'p'; elseif ($orderBy == 'name') $orderByPrefix = 'pl'; elseif ($orderBy == 'position') $orderByPrefix = 'c'; $rq = Db::getInstance()->ExecuteS(' SELECT count(*) as aaa FROM `'._DB_PREFIX_.'product` p LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (p.`id_product` = pl.`id_product`) LEFT JOIN `'._DB_PREFIX_.'tax` t ON (t.`id_tax` = p.`id_tax`) LEFT JOIN `'._DB_PREFIX_.'manufacturer` m ON (m.`id_manufacturer` = p.`id_manufacturer`) LEFT JOIN `'._DB_PREFIX_.'supplier` s ON (s.`id_supplier` = p.`id_supplier`)'. ($id_category ? 'LEFT JOIN `'._DB_PREFIX_.'category_product` c ON (c.`id_product` = p.`id_product`)' : '').' WHERE pl.`id_lang` = '.intval($id_lang). ($id_category ? ' AND c.`id_category` = '.intval($id_category) : ''). ($only_active ? ' AND p.`active` = 1' : '').' ORDER BY '.(isset($orderByPrefix) ? pSQL($orderByPrefix).'.' : '').'`'.pSQL($orderBy).'` '.pSQL($orderWay). ($limit > 0 ? ' LIMIT '.intval($start).','.intval($limit) : '') ); if($orderBy == 'price') Tools::orderbyPrice($rq,$orderWay); return $rq[0]["aaa"]; } Could anyone help? Link to comment Share on other sites More sharing options...
easymar Posted May 19, 2012 Author Share Posted May 19, 2012 I solved this from other side - with sql query: UPDATE your_database.ps_product SET active = 0 WHERE ps_product.id_category_default = X; X is an category id where you want set all products to inactive. Link to comment Share on other sites More sharing options...
Recommended Posts