I've tried a few methods, but all seem to kick out an error, as they seem to be for previous versions of OC. I understand i need to edit the header controller, but how/what/where i have no idea!
Help please?
Ernie
My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.
Ernie
---
TOP menu - images 2.X
https://www.opencart.com/index.php?rout ... n_id=23715
---
Super Mega Menu V2.4 - opencart module
https://www.opencart.com/index.php?rout ... on_id=8002
---
https://www.opencart.com/index.php?rout ... n_id=11375
---
https://www.opencart.com/index.php?rout ... n_id=22754
---
---
My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.
It all exists, so, where is the problem ?
Ernie
---
Images menu category v. 2.0.0.0, 2.0.1.0, 2.0.1.1, 2.0.2.0, 2.0.3.1
https://www.opencart.com/index.php?rout ... n_id=24065
---
Category Menu Image Display v.1.5.x, 2.0.0.0
https://www.opencart.com/index.php?rout ... n_id=28275
---
Flexible Menu v.2.0.3.1, 2.1.0.1, 2.1.0.2
https://www.opencart.com/index.php?rout ... n_id=22754
---
Menu Category Image v.1.5.6.x
https://www.opencart.com/index.php?rout ... on_id=7112
My Github OC Site: https://github.com/IP-CAM
5'200 + FREE OC Extensions, on the World's largest private Github OC Repository Archive Site.
Im getting the error now on my menu :
Code: Select all
Notice: Undefined variable: products in C:\wamp64\www\iyouprint\catalog\view\theme\iyouprint\template\common\header.tpl on line 124
Warning: Invalid argument supplied for foreach() in C:\wamp64\www\iyouprint\catalog\view\theme\iyouprint\template\common\header.tpl on line 124
Code: Select all
$this->load->model('catalog/category'); //
$this->load->model('catalog/product'); //Load our models so the controller can get data
$categories = $this->model_catalog_category->getCategories(0); //get all top level categories
$all_products = array();
foreach ($categories as $category) //go through each category and get all the products for each category
{
$category_products = $this->model_catalog_product->getProductsforCategoryId($category['category_id']); //returns product IDs for category
foreach ($category_products as $category_product)
{
$product_data = $this->model_catalog_product->getProduct($category_product); //fetch product data for this product then add it to our array of all products
$all_products[] = array(
'href' => $this->url->link('product/product', 'product_id=' . $product_data['product_id']),
'name' => $product_data['name']
);
}
}
$this->data['products'] = $all_products; //Now pass our product array data to the view, in the view this will be the $products array
I've managed to get the products into the menu, the problem i have is showing products from each category, as it stands, each category is showing the 1 test product i have on the site, almost as if that product is assigned to every category, its not, its only assigned to one...
Any ideas?
header controller :
Code: Select all
// START PRODUCTS //
$data['products'] = array();
$results = $this->model_catalog_product->getProducts();
if ($results) {
foreach ($results as $result) {
$data['products'][] = array(
'product_id' => $result['product_id'],
'name' => $result['name'],
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'])
);
}
}
// END PRODUCTS //
Code: Select all
<ul class="dropdown-menu mega-dropdown-menu row">
<?php foreach ($categories as $category) { ?>
<li class="col-sm-4">
<ul>
<li class="dropdown-header"><?php echo $category['name']; ?></li>
<?php foreach ($products as $product) { ?>
<li><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></li>
<?php } ?>
</ul>
</li>
<?php } ?>
</ul>
Code: Select all
$data['categories'][] = array(
...snip
'products'=>$cat_products,//the array of products for each category
);
Code: Select all
<ul class="dropdown-menu mega-dropdown-menu row">
<?php foreach ($categories as $category) { ?>
<li class="col-sm-4">
<ul>
<li class="dropdown-header"><?php echo $category['name']; ?>
<ul class="dropdown-menu"><!--start product dropdown-->
<?php foreach ($category['products'] as $product) { ?>
<li><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></li>
</ul>
</li>
<?php } ?>
</ul>
</li>
<?php } ?>
</ul>
Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+
Thanks!
I added the code you mentioned and now getting a different error :
Code: Select all
Notice: Undefined variable: cat_products in C:\wamp64\www\iyouprint\catalog\controller\common\header.php on line 139
Code: Select all
Warning: Invalid argument supplied for foreach() in C:\wamp64\www\iyouprint\catalog\view\theme\iyouprint\template\common\header.tpl on line 124
Code: Select all
// Menu
$this->load->model('catalog/category');
$this->load->model('catalog/product');
// START PRODUCTS //
$data['products'] = array();
$results = $this->model_catalog_product->getProducts();
if ($results) {
foreach ($results as $result) {
$data['products'][] = array(
'product_id' => $result['product_id'],
'name' => $result['name'],
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'])
);
}
}
// END PRODUCTS //
$data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
if ($category['top']) {
// Level 2
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true
);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id'])
);
}
// Level 1
$data['categories'][] = array(
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id']),
'products'=>$cat_products,//the array of products for each category
);
}
}
$data['language'] = $this->load->controller('common/language');
$data['currency'] = $this->load->controller('common/currency');
$data['search'] = $this->load->controller('common/search');
$data['cart'] = $this->load->controller('common/cart');
// For page specific css
if (isset($this->request->get['route'])) {
if (isset($this->request->get['product_id'])) {
$class = '-' . $this->request->get['product_id'];
} elseif (isset($this->request->get['path'])) {
$class = '-' . $this->request->get['path'];
} elseif (isset($this->request->get['manufacturer_id'])) {
$class = '-' . $this->request->get['manufacturer_id'];
} elseif (isset($this->request->get['information_id'])) {
$class = '-' . $this->request->get['information_id'];
} else {
$class = '';
}
$data['class'] = str_replace('/', '-', $this->request->get['route']) . $class;
} else {
$data['class'] = 'common-home';
}
return $this->load->view('common/header', $data);
}
$cat_products was just my name, you need to use the one you created.
I added the products inside the category loop otherwise you will get all the same products for each category.
This filters the products by cat id
array('filter_category_id'=>$category['category_id'])
This also limits results to 5
array('filter_category_id'=>$category['category_id'], 'limit'=>5)
Code: Select all
// Menu
$this->load->model('catalog/category');
$this->load->model('catalog/product');
$data['categories'] = array();
$categories = $this->model_catalog_category->getCategories(0);
foreach ($categories as $category) {
// START PRODUCTS //
$results = $this->model_catalog_product->getProducts(array('filter_category_id'=>$category['category_id']));
//init products array for each cat
$cat_products = array();
if ($results) {
foreach ($results as $result) {
$cat_products[] = array(
'product_id' => $result['product_id'],
'name' => $result['name'],
'href' => $this->url->link('product/product', 'product_id=' . $result['product_id'], true),
);
}
}
// END PRODUCTS //
if ($category['top']) {
// Level 2
$children_data = array();
$children = $this->model_catalog_category->getCategories($category['category_id']);
foreach ($children as $child) {
$filter_data = array(
'filter_category_id' => $child['category_id'],
'filter_sub_category' => true,
);
$children_data[] = array(
'name' => $child['name'] . ($this->config->get('config_product_count') ? ' (' . $this->model_catalog_product->getTotalProducts($filter_data) . ')' : ''),
'href' => $this->url->link('product/category', 'path=' . $category['category_id'] . '_' . $child['category_id']),
);
}
// Level 1
$data['categories'][] = array(
'name' => $category['name'],
'children' => $children_data,
'column' => $category['column'] ? $category['column'] : 1,
'href' => $this->url->link('product/category', 'path=' . $category['category_id']),
'products' => $cat_products,//the array of products for each category
);
}
}
Attn: I no longer provide OpenCart extensions, nor future support - this includes forum posts.
Reason: OpenCart version 3+
Thanks!
So, although all of my errors are now gone, im back to a previous issue, where each category, has the same 1, test product listed under it.
My test product is "Sample Product"
My categories are 1/2/3/4
Sample product is only on category 1, but its showing as being part of 1/2/3/4
See screenshot for illustration, any ideas?
Is the the TPL file or the controller?
Attachments
mainmenu.jpg (137.3 KiB) Viewed 9717 times
Users browsing this forum: No registered users and 45 guests