if ( empty($url_ptid) ) { // if product_type_id in a link - we do not make query
require_once (CLASSPATH."ps_product_category.php");
$ps_product_category = new ps_product_category;
$category_id=JRequest::getVar('category_id','');
$category_childs = array();
if ( $category_id && $ps_product_category->has_childs($category_id) ){
$category_childs = getCatergoryChildsList( $ps_product_category->getCategoryTreeArray(), $category_id );
}
if (!empty($category_id)){
$q = "SELECT pptx.`product_type_id`".
" FROM (`#__vm_product_product_type_xref` as pptx, `#__vm_product` as p)".
" LEFT JOIN `#__vm_product_category_xref` as pcx ".
" ON pptx.`product_id`=pcx.`product_id`";
if(count($category_childs )){
$q .= " WHERE pcx.`category_id` IN (".implode(',',$category_childs).")";
} else {
$q .= " WHERE pcx.`category_id`='$category_id'";
}
$q .= " AND p.`product_id`=pcx.`product_id`".
" AND p.`product_publish`='Y'";
if( CHECK_STOCK && PSHOP_SHOW_OUT_OF_STOCK_PRODUCTS != "1") {
$q .= ' AND p.`product_in_stock` > 0';
}
$q.= " LIMIT 0 , 1";
$db->setQuery($q);
$ptid=$db->loadResult();
}
}else{
$ptid=$url_ptid;
}