public static
getAllSpecificationsAndValues
(mixed $ordering = 1, mixed $onlyAvailableProducts = 0, mixed $lang = '', mixed $filterProducts = array())
public static function getAllSpecificationsAndValues($ordering = 1, $onlyAvailableProducts = 0, $lang = '', $filterProducts = array())
{
$db = Factory::getDBO();
$orderingText = PhocacartOrdering::getOrderingText($ordering, 6);
$columns = 's.id, s.title, s.alias, s.value, s.alias_value, s.image, s.image_medium, s.image_small, s.color';
$groupsFull = $columns;
$groupsFast = 's.id';
$groups = PhocacartUtilsSettings::isFullGroupBy() ? $groupsFull : $groupsFast;
$wheres = array();
$lefts = array();
$wheres[] = ' sg.published = 1';
$lefts[] = ' #__phocacart_specification_groups AS sg ON s.group_id = sg.id';
if ($onlyAvailableProducts == 1) {
if ($lang != '' && $lang != '*') {
$wheres[] = PhocacartUtilsSettings::getLangQuery('p.language', $lang);
}
$lefts[] = ' #__phocacart_products AS p ON s.product_id = p.id';
$rules = PhocacartProduct::getOnlyAvailableProductRules();
$wheres = array_merge($wheres, $rules['wheres']);
$lefts = array_merge($lefts, $rules['lefts']);
} else {
if ($lang != '' && $lang != '*') {
$wheres[] = PhocacartUtilsSettings::getLangQuery('p.language', $lang);
}
$lefts[] = ' #__phocacart_products AS p ON s.product_id = p.id';
}
if (!empty($filterProducts)) {
$productIds = implode(',', $filterProducts);
$wheres[] = 'p.id IN (' . $productIds . ')';
}
$query = 'SELECT ' . $columns . ' FROM #__phocacart_specifications AS s' . (!empty($lefts) ? ' LEFT JOIN ' . implode(' LEFT JOIN ', $lefts) : '') . (!empty($wheres) ? ' WHERE ' . implode(' AND ', $wheres) : '') . ' GROUP BY ' . $groups . ' ORDER BY ' . $orderingText;
$db->setQuery($query);
$specifications = $db->loadObjectList();
$a = array();
if (!empty($specifications)) {
foreach ($specifications as $k => $v) {
if (isset($v->title) && $v->title != '' && isset($v->id) && $v->id != '' && isset($v->alias) && $v->alias != '') {
$a[$v->alias]['title'] = $v->title;
$a[$v->alias]['id'] = $v->id;
$a[$v->alias]['alias'] = $v->alias;
if (isset($v->value) && $v->value != '' && isset($v->alias_value) && $v->alias_value != '') {
$a[$v->alias]['value'][$v->alias_value] = new stdClass();
$a[$v->alias]['value'][$v->alias_value]->title = $v->value;
$a[$v->alias]['value'][$v->alias_value]->id = $v->id;
$a[$v->alias]['value'][$v->alias_value]->alias = $v->alias_value;
$a[$v->alias]['value'][$v->alias_value]->image = $v->image;
$a[$v->alias]['value'][$v->alias_value]->image_medium = $v->image_medium;
$a[$v->alias]['value'][$v->alias_value]->image_small = $v->image_small;
$a[$v->alias]['value'][$v->alias_value]->color = $v->color;
} else {
$a[$v->alias]['value'] = array();
}
}
}
}
return $a;
}