/*
* ID ... id of product
*/
public static function getProductDiscountsById($id = 0, $returnArray = 0)
{
if (is_null($id)) {
throw new Exception('Function Error: No id added', 500);
return false;
}
$id = (int) $id;
if (!array_key_exists($id, self::$product)) {
$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 . ")";
$wheres[] = " (ga.group_id IN (" . $userGroups . ") OR ga.group_id IS NULL)";
$where = count($wheres) ? ' WHERE ' . implode(' AND ', $wheres) : '';
$query = 'SELECT a.id, a.title, a.alias, a.discount, a.access, a.calculation_type, a.quantity_from, a.valid_from, a.valid_to' . ' FROM #__phocacart_product_discounts AS a' . ' LEFT JOIN #__phocacart_item_groups AS ga ON a.id = ga.item_id AND ga.type = 4' . $where . ' ORDER BY a.id';
$db->setQuery($query);
if ($returnArray) {
$discounts = $db->loadAssocList();
} else {
$discounts = $db->loadObjectList();
}
self::$product[$id] = $discounts;
}
return self::$product[$id];
}