/* Module - get all products with featured */
public static function getProductsFeatured($params = array())
{
$db = Factory::getDBO();
$user = PhocacartUser::getUser();
$userLevels = implode(',', $user->getAuthorisedViewLevels());
$userGroups = implode(',', PhocacartGroup::getGroupsById($user->id, 1, 1));
$wheres = array();
//$wheres[] = "a.product_id = " . (int)$id;
// $wheres[] = " a.access IN (" . $userLevels . ")";// ACCESS Discount
$wheres[] = " p.access IN (" . $userLevels . ")";
// ACCESS Product
$wheres[] = " c.access IN (" . $userLevels . ")";
// ACCESS Category
$wheres[] = "p.published = 1";
// PUBLISHED Product
$wheres[] = "c.published = 1";
// PUBLISHED Category
$wheres[] = " (gp.group_id IN (" . $userGroups . ") OR gp.group_id IS NULL)";
$wheres[] = " (gc.group_id IN (" . $userGroups . ") OR gc.group_id IS NULL)";
// $wheres[] = " (ga.group_id IN (" . $userGroups . ") OR ga.group_id IS NULL)";// GROUP
// STOCK
if (isset($params['stock_check']) && $params['stock_check'] == 1) {
$wheres[] = " p.stock > 0";
}
// LIMIT
$limit = 1;
if (isset($params['limit'])) {
if ((int) $params['limit'] == 0) {
return false;
} else {
if ((int) $params['limit'] > 0) {
$limit = (int) $params['limit'];
}
}
}
$wheres[] = " p.featured = 1";
$where = count($wheres) ? ' WHERE ' . implode(' AND ', $wheres) : '';
$query = 'SELECT p.id, p.description, p.title, p.alias, p.image, p.price, p.unit_amount,' . ' p.unit_unit, p.stock, p.stockstatus_a_id, p.stockstatus_n_id, p.featured_background_image AS background_image,' . ' c.id AS category_id, c.title AS category_title, c.alias AS category_alias,' . ' t.id as tax_id, t.tax_rate AS tax_rate, t.calculation_type AS tax_calculationtype, t.title AS tax_title,' . ' MIN(ppg.price) as group_price' . ' FROM #__phocacart_products AS p' . ' LEFT JOIN #__phocacart_product_categories AS pc ON pc.product_id = p.id' . ' LEFT JOIN #__phocacart_categories AS c ON c.id = pc.category_id' . ' LEFT JOIN #__phocacart_taxes AS t ON t.id = p.tax_id' . ' LEFT JOIN #__phocacart_item_groups AS gp ON p.id = gp.item_id AND gp.type = 3' . ' LEFT JOIN #__phocacart_item_groups AS gc ON c.id = gc.item_id AND gc.type = 2' . ' LEFT JOIN #__phocacart_product_price_groups AS ppg ON p.id = ppg.product_id AND ppg.group_id IN (SELECT group_id FROM #__phocacart_item_groups WHERE item_id = p.id AND group_id IN (' . $userGroups . ') AND type = 3)' . $where . ' GROUP BY p.id' . ' ORDER BY p.id' . ' LIMIT ' . (int) $limit;
$db->setQuery($query);
$items = $db->loadObjectList();
if (!empty($items) && isset($items[0]->id) && (int) $items[0]->id > 0) {
return $items;
}
return false;
}