/*
* ID ... id of cart
*/
public static function getCartDiscountsById($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::$cart ) ) {
$db = Factory::getDBO();
$user = PhocacartUser::getUser();
$userLevels = implode(',', $user->getAuthorisedViewLevels());
$userGroups = implode(',', PhocacartGroup::getGroupsById($user->id, 1, 1));
$wheres = array();
$wheres[] = "a.access IN (" . $userLevels . ")";
$wheres[] = " (ga.group_id IN (" . $userGroups . ") OR ga.group_id IS NULL)";
$wheres[] = 'a.published = 1';
$where = count($wheres) ? ' WHERE ' . implode(' AND ', $wheres) : '';
$columns = 'a.id, a.title, a.alias, a.discount, a.access, a.discount, a.total_amount, a.free_shipping, a.free_payment, a.calculation_type, a.quantity_from, a.quantity_to, a.valid_from, a.valid_to, a.category_filter, a.product_filter,' . ' GROUP_CONCAT(DISTINCT dp.product_id) AS product,' . ' GROUP_CONCAT(DISTINCT dc.category_id) AS category';
// line of selected categories
$groupsFull = 'a.id, a.title, a.alias, a.discount, a.access, a.discount, a.total_amount, a.free_shipping, a.free_payment, a.calculation_type, a.quantity_from, a.quantity_to, a.valid_from, a.valid_to, a.category_filter, a.product_filter';
$groupsFast = 'a.id';
$groups = PhocacartUtilsSettings::isFullGroupBy() ? $groupsFull : $groupsFast;
$query = 'SELECT ' . $columns . ' FROM #__phocacart_discounts AS a' . ' LEFT JOIN #__phocacart_discount_products AS dp ON dp.discount_id = a.id' . ' LEFT JOIN #__phocacart_discount_categories AS dc ON dc.discount_id = a.id' . ' LEFT JOIN #__phocacart_item_groups AS ga ON a.id = ga.item_id AND ga.type = 5' . $where . ' GROUP BY ' . $groups;
$query .= ' ORDER BY a.id';
PhocacartUtils::setConcatCharCount();
$db->setQuery($query);
if ($returnArray) {
$discounts = $db->loadAssocList();
} else {
$discounts = $db->loadObjectList();
}
self::$cart[$id] = $discounts;
//- }
return self::$cart[$id];
}