N
N
Nikolai2021-03-29 15:56:50
PHP
Nikolai, 2021-03-29 15:56:50

How to display products with categories on the main page on Opencart?

Good afternoon, how to display products and categories on the main page, who can tell. In the home controller, I made the output of categories to the main one and now all products from all categories fall into each category. I don’t know how to make the product only from this category be in the section. In short, how to make pizza like on the dodo website. Categories and goods.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
Nikolai, 2021-03-30
@Skofield2016

good evening I made cycles in the controller but only displays the last category with the product, why is
the code itself here
<?php
class ControllerCommonHome extends Controller {
public function index() {
$this->load->language('product/category');
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$this->load->model('tool/image');
$arr_category = $this->model_catalog_category->getCategories(0);
foreach($arr_category as $id){
$category_id = $id['category_id'];
$category_info = $this->model_catalog_category->getCategory($category_id);
print_r($category_info);
$this->document->setTitle($category_info['meta_title']);
$this->document->setDescription($category_info['meta_description']);
$this->document->setKeywords($category_info['meta_keyword']);
$data['categories'] = array();
$data['heading_title'] = $category_info['name'];
$data['products'] = array();
$filter_data = array(
'filter_category_id' => $category_id,
);
$product_total = $this->model_catalog_product->getTotalProducts($filter_data);
$results = $this->model_catalog_product->getProducts($filter_data);
foreach ($results as $result) {
if ($result['image']) {
$image = $this->model_tool_image->resize($result['image'], $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width' ), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
} else {
$image = $this->model_tool_image->resize('placeholder.png', $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_width '), $this->config->get('theme_' . $this->config->get('config_theme') . '_image_product_height'));
}
if ($this->customer->isLogged() || !$this->config->get('config_customer_price'
} else {
$price = false;
}
$data['products'][] = array(
'product_id' => $result['product_id'],
'thumb' => $image,
'name' => $result['name'],
'description' => utf8_substr(trim(strip_tags(html_entity_decode($result['description'], ENT_QUOTES, 'UTF-8'))), 0, $this->config->get('theme_' . $this->config- >get('config_theme') . '_product_description_length')) . '..',
'price' => $price,
'minimum' => $result['minimum'] > 0 ? $result['minimum'] : 1,
// 'href' => $this->url->
link('product/product', 'path=' . $this->request->get['path'] . '&product_id=' . $result['product_id'] . $url) );
};
$data['continue'] = $this->url->link('common/home');
$data['column_left'] = $this->load->controller('common/column_left');
$data['column_right'] = $this->load->controller('common/column_right');
$data['content_top'] = $this->load->controller('common/content_top');
$data['content_bottom'] = $this->load->controller('common/content_bottom');
$data['footer'] = $this->load->controller('common/footer');
$data['header'] = $this->load->controller('common/header');
$this->response->setOutput($this->load->view('product/category', $data));

S
Serge Tkach, 2021-03-29
@SergeTkach

2 loops
1 - iterate through categories {
2 - iterate through products of this category {
you can see how $filter_data is formed on the page of a specific category and be inspired by this
}
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question