Здравствуйте!
В главной категории, подкатегории выводятся таким образом https://prnt.sc/w3cof3 , вместе с ссылками на товары.... Под картинками, есть кнопка сравнения, которая должна выводить таблицу сравнения товаров подкатегории по атрибутам (https://prnt.sc/w3s890)... Не получается вывести эти атрибуты, не пойму что упустил.
Приведу код
Контроллер
$data['categories'] = array();
$results = $this->model_catalog_category->getCategories($category_id);
foreach ($results as $result) {
$filter_data = array(
'filter_category_id' => $result['category_id'],
'filter_sub_category' => true
);
if ($result['image']) {
$caimage = $this->model_tool_image->resize($result['image'], 140, 140);
}
else {
$caimage = $caimage = $this->model_tool_image->resize('no_image.png', 140, 140);
}
$data['categories'][] = array(
'category_id' => $result['category_id'],
'name' => $result['name'],
'meta_h1' => $result['meta_h1'],
'href' => $this->url->link('product/category', 'path=' . $this->request->get['path'] . '_' . $result['category_id'] . $url),
'image' => $caimage,
'count' => ($this->config->get('config_product_count') ? $this->model_catalog_product->getTotalProducts($filter_data) : '')
);
}
$data['products_all'] = array();
for( $x = 0; $x < count( $data['categories'] ); $x++ ) {
$cat = $data['categories'][ $x ][ 'category_id' ];
$data['products_all'][ $cat ] = array();
$filter_data = array(
'filter_category_id' => $cat,
'sort' => $sort,
'order' => $order,
'start' => ($page - 1) * $limit,
'limit' => $limit
);
$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
$results = $this->model_catalog_product->getProducts($filter_data);
$data['attribute_groups'] = array();
foreach ($results as $result) {
if ($this->customer->isLogged() || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$price = false;
}
if ((float)$result['special']) {
$special = $this->currency->format($this->tax->calculate($result['special'], $result['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']);
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$result['special'] ? $result['special'] : $result['price'], $this->session->data['currency']);
} else {
$tax = false;
}
$attribute_data = array();
$attribute_groups = $this->model_catalog_product->getProductAttributes($result['product_id']);
foreach ($attribute_groups as $attribute_group) {
foreach ($attribute_group['attribute'] as $attribute) {
$attribute_data[$attribute['attribute_id']] = $attribute['text'];
}
}
$data['products_all'][ $cat ][] = array(
'product_id' => $result['product_id'],
'name' => $result['name'],
'price' => $price,
'special' => $special,
'tax' => $tax,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
'model' => $result['model'],
'attribute' => $attribute_data,
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url)
);
foreach ($attribute_groups as $attribute_group) {
$data['attribute_groups'][$attribute_group['attribute_group_id']]['name'] = $attribute_group['name'];
foreach ($attribute_group['attribute'] as $attribute) {
$data['attribute_groups'][$attribute_group['attribute_group_id']]['attribute'][$attribute['attribute_id']]['name'] = $attribute['name'];
}
}
}
}
Шаблон
<?php if ($categories) { ?>
<div class="row category">
<div class="subcats">
<div>
<?php foreach ($categories as $category) { ?>
<div class="col-lg-4 col-md-6 col-sm-6 col-xs-12 bl-sk">
<div class="col-md-12 col-sm-12 col-xs-12">
<h3 class="category-item-name"><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></h3>
<hr class="category-item-line">
<span class="h2m"><?php echo $category['meta_h1']; ?></span>
</div>
<div class="row">
<div class="col-lg-6 col-md-6 col-sm-6 hidden-xs">
<a href="<?php echo $category['href']; ?>"><img class="img-sk" src="<?php echo $category['image']; ?>" alt="<?php echo $category['name']; ?>" /></a><br />
<a class="sr" type="button" data-toggle="modal" data-target="#myModal-<?php echo $category['category_id']; ?>">Сравнить</a>
<div id="myModal-<?php echo $category['category_id']; ?>" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header"><button class="close" type="button" data-dismiss="modal">×</button>
<h4 class="modal-title">Сравнение <?php echo $category['name']; ?></h4>
</div>
<div class="modal-body">
<table class="table table-bordered">
<thead>
<tr>
<th>Название</th>
<?php foreach ($attribute_groups as $attribute_group) { ?>
<?php $i = 0; ?>
<?php foreach ($attribute_group['attribute'] as $attribute) { ?>
<?php if ($i < 5) { ?>
<th><?php echo $attribute['name']; ?></th>
<?php } $i++; ?>
<?php } ?>
<?php } ?>
<th>Цена</th>
</tr>
</thead>
<tbody>
<?php foreach ($products_all[$category['category_id']] as $product ) { ?>
<tr>
<td><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></td>
<?php foreach ($attribute_groups as $attribute_group) { ?>
<?php $i = 0; ?>
<?php foreach ($attribute_group['attribute'] as $key => $attribute) { ?>
<?php if ($i < 5) { ?>
<?php if (isset($product['attribute'][$key])) { ?>
<td><?php echo $product['attribute'][$key]; ?></td>
<?php } else { ?>
<td></td>
<?php } ?>
<?php } $i++; ?>
<?php } ?>
<?php } ?>
<td><a type="button" class="btn btn-primary btn-block" onclick="cart.add('<?php echo $product['product_id']; ?>', '<?php echo $product['minimum']; ?>');"><?php echo $product['price']; ?></a></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<div class="modal-footer"><button class="btn btn-default" type="button" data-dismiss="modal">Закрыть</button></div>
</div>
</div>
</div>
</div>
<div class="col-lg-6 col-md-6 col-sm-6 col-xs-12 mp0">
<ul class="tov-cat">
<?php foreach ( $products_all[ $category['category_id'] ] as $product ) { ?>
<li class="poster">
<a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a>
</li>
<?php } ?>
</ul>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
С меня пивас за помощь!!!