{% if count_attr > '1' %}
<div class="box sf-attribute sf-attribute-{{ attribute.attribute_id }} sf-{{ attribute.type }} {% if is_collapsed %} is-collapsed {% endif %}" data-id=" attribute-{{ attribute.attribute_id }}">
<div class="box-heading">{{ attribute.attribute_name }}</div>
<div class="box-content">
<ul class="sf_li {% if not journal2.settings.get('filter_show_box') %} hide-checkbox {% endif %}">
{% for value in attribute.values %}
<li><label><input data-keyword="{{ value.keyword }}" type="checkbox" name="attribute[{{ attribute.attribute_id }}]" value="{{ value.text }}">{{ value.name }}</label></li>
{% endfor %}
</ul>
</div>
</div>
{% endif %}
/* attributes */
$results = $this->model_journal2_super_filter->getAttributes($data);
foreach ($results as $key => $result) {
$display_mode = Journal2Utils::getProperty($module_data, 'attributes.' . $key, 'on');
if ($display_mode === 'off') {
continue;
}
$values = array();
foreach ($result['values'] as $value) {
$values[] = array(
'text' => rawurlencode(trim($value['text'])),
'name' => trim($value['text']) . ( $show_product_count ? ' (' . $value['total'] . ')' : ''),
'keyword' => $this->keyword($result['attribute_name'] . " " . $value['text'])
);
}
$this->data['attribute'] = array(
'attribute_id' => $result['attribute_id'],
'attribute_name' => $result['attribute_name'],
'display_mode' => $display_mode,
'type' => Journal2Utils::getProperty($module_data, 'attributes_type.' . $key, 'multi'),
'values' => $values,
);
$this->data['count_attr'] = count($this->data['attribute']['values']);
$this->template = 'journal2/module/super_filter_attributes.tpl';
$filter_groups[] = array(
'sort_order' => Journal2Utils::getProperty($module_data, 'sort_orders.a_' . $result['attribute_id']),
'html' => $this->render()
);
}
public function getAttributes($data = array()){
if(isset($data['attributes']) && !empty($data['attributes'])) {
$product_attributes = $this->getProductAttributes($data);
foreach ($data['attributes'] as $attribute_id => $value) {
foreach($product_attributes as $key => $attribute) {
if($key == $attribute_id) {
unset($product_attributes[$key]);
}
}
$temp_data = $data;
unset($temp_data['attributes'][$attribute_id]);
foreach($this->getProductAttributes($temp_data) as $key => $attribute){
if($key == $attribute_id) {
$product_attributes[$attribute_id] = $attribute;
}
}
}
$results = $product_attributes;
}else{
$results = $this->getProductAttributes($data);
}
ksort($results);
return $results;
}
private function getProductAttributes($data = array()){
$data['start'] = 0;
$data['limit'] = PHP_INT_MAX;
$products = $this->getProducts($data);
if (count($products) == 0) {
return array();
}
$sql = "SELECT pa.product_id, MAX(a.attribute_id) as attribute_id, MAX(ad.name) as attribute_name, MAX(pa.text) text, COUNT(*) total FROM `". DB_PREFIX . "product_attribute` pa LEFT JOIN `". DB_PREFIX . "attribute` a ON a.attribute_id = pa.attribute_id LEFT JOIN `". DB_PREFIX . "attribute_description` ad ON ad.attribute_id = a.attribute_id";
$sql .= " WHERE pa.product_id IN (" . implode(",", $products) . ")";
$sql .= " AND pa.language_id = '" . (int)$this->config->get('config_language_id') . "' AND ad.language_id = '" . (int)$this->config->get('config_language_id') . "'";
$sql .= " GROUP BY lower(pa.text), a.attribute_id HAVING COUNT(*) > 0";
$query = $this->db->query($sql);
$results = array();
foreach ($query->rows as $row) {
if (!isset($results[$row['attribute_id']])) {
$results[$row['attribute_id']] = array(
'attribute_id' => $row['attribute_id'],
'attribute_name' => $row['attribute_name'],
'values' => array()
);
}
$results[$row['attribute_id']]['values'][] = array(
'text' => $row['text'],
'total' => $row['total'],
);
}
foreach ($results as $attribute_id => &$value) {
usort($value['values'], array('ModelJournal2SuperFilter', 'cmpAttrs'));
}
return $results;
}