/*
* Done in PhocacartProduct::getProductKey();
*
public static function correctArrtibutesFormat(&$attributes) {
if (!empty($attributes)) {
foreach ($attributes as $k => $v) {
if (!is_array($v)) {
$attributes[$k] = array($v => $v);
}
}
}
}*/
/* public static function storeOptionsByAttributeId($attributeId, $optArray) {
if ((int)$attributeId > 0) {
$db =Factory::getDBO();
$query = ' DELETE '
.' FROM #__phocacart_attribute_values'
. ' WHERE attribute_id = '. (int)$attributeId;
$db->setQuery($query);
if (!empty($optArray)) {
$values = array();
$valuesString = '';
foreach($optArray as $k => $v) {
if (isset($v['title']) && $v['title'] != '' && isset($v['amount']) && isset($v['operator'])) {
$values[] = ' ('.(int)$attributeId.', \''.$v['title'].'\', \''.$v['operator'].'\', \''.(float)$v['amount'].'\')';
}
}
if (!empty($values)) {
$valuesString = implode(',', $values);
$query = ' INSERT INTO #__phocacart_attribute_values (attribute_id, title, operator, amount)'
.' VALUES '.(string)$valuesString;
$db->setQuery($query);
}
}
}
}
public static function getAllAttributesSelectBox($name, $id, $activeArray, $javascript = NULL, $order = 'id' ) {
$db = Factory::getDBO();
$query = 'SELECT a.id AS value, CONCAT(a.title_attribute,\' (\', a.title, \')\') AS text'
.' FROM #__phocacart_attributes AS a'
. ' ORDER BY '. $order;
$db->setQuery($query);
$attributes = $db->loadObjectList();
$attributesO = HTMLHelper::_('select.genericlist', $attributes, $name, 'class="form-control" size="4" multiple="multiple"'. $javascript, 'value', 'text', $activeArray, $id);
return $attributesO;
}
*/
public static function getActiveAttributeValues($items, $ordering)
{
$db = Factory::getDbo();
$o = array();
$wheres = array();
$ordering = PhocacartOrdering::getOrderingText($ordering, 5);
//at v
if (!empty($items)) {
foreach ($items as $k => $v) {
$wheres[] = '( v.alias = ' . $db->quote($k) . ' AND at.alias IN (' . $v . ') )';
}
if (!empty($wheres)) {
// FULL GROUP BY GROUP_CONCAT(DISTINCT o.title) AS title
$q = 'SELECT DISTINCT at.title, at.alias, CONCAT(\'a[\', v.alias, \']\') AS parameteralias, v.title AS parametertitle FROM #__phocacart_attribute_values AS at' . ' LEFT JOIN #__phocacart_attributes AS v ON v.id = at.attribute_id' . (!empty($wheres) ? ' WHERE ' . implode(' OR ', $wheres) : '') . ' GROUP BY v.alias, at.alias, at.title' . ' ORDER BY ' . $ordering;
$db->setQuery($q);
$o = $db->loadAssocList();
}
}
return $o;
}