public static function getOnlyAvailableProductRules()
{
$user = PhocacartUser::getUser();
$userLevels = implode(',', $user->getAuthorisedViewLevels());
$userGroups = implode(',', PhocacartGroup::getGroupsById($user->id, 1, 1));
$type = PhocacartUtilsSettings::getShopType();
$wheres = array();
$wheres[] = " p.access IN (" . $userLevels . ")";
$wheres[] = " c.access IN (" . $userLevels . ")";
$wheres[] = " (ga.group_id IN (" . $userGroups . ") OR ga.group_id IS NULL)";
$wheres[] = " (gc.group_id IN (" . $userGroups . ") OR gc.group_id IS NULL)";
$wheres[] = " p.published = 1";
$wheres[] = " c.published = 1";
if (!empty($type) && is_array($type)) {
$wheres[] = ' c.type IN (' . implode(',', $type) . ')';
}
$lefts = array();
$lefts[] = ' #__phocacart_product_categories AS pc ON pc.product_id = p.id';
$lefts[] = ' #__phocacart_categories AS c ON c.id = pc.category_id';
$lefts[] = ' #__phocacart_item_groups AS ga ON p.id = ga.item_id AND ga.type = 3';
// type 3 is product
$lefts[] = ' #__phocacart_item_groups AS gc ON c.id = gc.item_id AND gc.type = 2';
// type 2 is category
$rules = array();
$rules['wheres'] = $wheres;
$rules['lefts'] = $lefts;
return $rules;
}