How to show each subcategory products on category page in grid style ?
This solve may be intresting many people.

Thanks.
Code: Select all
$product_total = $this->model_catalog_product->getTotalProducts($data);
Code: Select all
$subproducts = array();
$productdata = array(
'filter_category_id' => $result['category_id'],
'sort' => $sort,
'order' => $order,
'start' => 0,
'limit' => 15
);
$productresults = $this->model_catalog_product->getProducts($productdata);
foreach ($productresults as $productresult) {
if ($productresult['image']) {
$image = $this->model_tool_image->resize($productresult['image'], $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height'));
} else {
$image = false;
}
if (($this->config->get('config_customer_price') && $this->customer->isLogged()) || !$this->config->get('config_customer_price')) {
$price = $this->currency->format($this->tax->calculate($productresult['price'], $productresult['tax_class_id'], $this->config->get('config_tax')));
} else {
$price = false;
}
if ((float)$productresult['special']) {
$special = $this->currency->format($this->tax->calculate($productresult['special'], $productresult['tax_class_id'], $this->config->get('config_tax')));
} else {
$special = false;
}
if ($this->config->get('config_tax')) {
$tax = $this->currency->format((float)$productresult['special'] ? $productresult['special'] : $productresult['price']);
} else {
$tax = false;
}
if ($this->config->get('config_review_status')) {
$rating = (int)$productresult['rating'];
} else {
$rating = false;
}
$subproducts[] = array(
'product_id' => $productresult['product_id'],
'thumb' => $image,
'name' => $productresult['name'],
'description' => utf8_substr(strip_tags(html_entity_decode($productresult['description'], ENT_QUOTES, 'UTF-8')), 0, 100) . '..',
'price' => $price,
'special' => $special,
'tax' => $tax,
'rating' => $productresult['rating'],
'reviews' => sprintf($this->language->get('text_reviews'), (int)$productresult['reviews']),
'href' => $this->url->link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $productresult['product_id'] . $url)
);
}
, 15 reffers to the number of products it shows for each category, you can change that if you wish.'limit' => 15
Code: Select all
'name' => $result['name'] . ($this->config->get('config_product_count') ? ' (' . $product_total . ')' : ''),
Code: Select all
'subproducts' => $subproducts,
Code: Select all
<?php if ($categories) { ?>
<h2><?php echo $text_refine; ?></h2>
<div class="category-list">
<?php if (count($categories) <= 5) { ?>
<ul>
<?php foreach ($categories as $category) { ?>
<li><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></li>
<?php } ?>
</ul>
<?php } else { ?>
<?php for ($i = 0; $i < count($categories);) { ?>
<ul>
<?php $j = $i + ceil(count($categories) / 4); ?>
<?php for (; $i < $j; $i++) { ?>
<?php if (isset($categories[$i])) { ?>
<li><a href="<?php echo $categories[$i]['href']; ?>"><?php echo $categories[$i]['name']; ?></a></li>
<?php } ?>
<?php } ?>
</ul>
<?php } ?>
<?php } ?>
</div>
<?php } ?>
Code: Select all
<?php if ($categories) { ?>
<?php foreach ($categories as $category) { ?>
<h2><a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></h2>
<?php if ($category['subproducts']) { ?>
<div class="product-list">
<?php foreach ($category['subproducts'] as $product) { ?>
<div>
<?php if ($product['thumb']) { ?>
<div class="image"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" title="<?php echo $product['name']; ?>" alt="<?php echo $product['name']; ?>" /></a></div>
<?php } ?>
<div class="name"><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></div>
<div class="description"><?php echo $product['description']; ?></div>
<?php if ($product['price']) { ?>
<div class="price">
<?php if (!$product['special']) { ?>
<?php echo $product['price']; ?>
<?php } else { ?>
<span class="price-old"><?php echo $product['price']; ?></span> <span class="price-new"><?php echo $product['special']; ?></span>
<?php } ?>
<?php if ($product['tax']) { ?>
<br />
<span class="price-tax"><?php echo $text_tax; ?> <?php echo $product['tax']; ?></span>
<?php } ?>
</div>
<?php } ?>
<?php if ($product['rating']) { ?>
<div class="rating"><img src="catalog/view/theme/default/image/stars-<?php echo $product['rating']; ?>.png" alt="<?php echo $product['reviews']; ?>" /></div>
<?php } ?>
<div class="cart">
<input type="button" value="<?php echo $button_cart; ?>" onclick="addToCart('<?php echo $product['product_id']; ?>');" class="button" />
</div>
<div class="wishlist"><a onclick="addToWishList('<?php echo $product['product_id']; ?>');"><?php echo $button_wishlist; ?></a></div>
<div class="compare"><a onclick="addToCompare('<?php echo $product['product_id']; ?>');"><?php echo $button_compare; ?></a></div>
</div>
<?php } ?>
</div>
<?php } ?>
<?php } ?>
Users browsing this forum: No registered users and 4 guests