The easiest is to change:
$filters = array('a.product_published=1','a.product_type=\'main\'');
to:
$filters = array('a.product_published=1');
and remove the block:
if(hikashop_level(2)){
$catFilters = array('category_published=1','category_type=\'product\'');
hikashop_addACLFilters($catFilters,'category_access');
$db->setQuery('SELECT category_id FROM '.hikashop_table('category').' WHERE '.implode(' AND ',$catFilters));
$cats = $db->loadResultArray();
if(!empty($cats)){
$filters[]='b.category_id IN ('.implode(',',$cats).')';
}
}
$leftjoin=' INNER JOIN '.hikashop_table('product_category').' AS b ON a.product_id=b.product_id';
But it won't handle the unpublished categories and we display the variants even if they are associated to a product within unpublished categories.