Post by morktron » Mon Aug 27, 2012 1:03 pm

Hi, i'm building a site that is starting only with only 2 products, so a category menu is not appropriate and I'm attempting to create a product only menu.

I'm using a commercial theme and it automagically generates a category menu in header.tpl

I need to create a product menu but not being a php coder it gets tricky, so far I have:

Code: Select all

<ul id="topnav">
<?php foreach ($products as $product) { ?>
<li><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></li>
<?php } ?>
</ul>
Does anyone know where I'm going wrong here? (apart from obviously not learning php yet!;)

Goodbye Virtuemart! Hello Opencart! :)


New member

Posts

Joined
Tue Jun 12, 2012 1:48 pm
Location - Ballina, NSW, Australia

Post by pprmkr » Mon Aug 27, 2012 1:17 pm

It's a start.

Now get the values in the controller catalog/controller/common/header.php

You can view catalog/controller/product/category.php and search for:

Code: Select all

$product_total = $this->model_catalog_product->getTotalProducts($data);
Use the part where the $data is set to retrieve the products.
For you only filter_category_id is needed.

In the foreach you find all the data you need to create the menu.

User avatar
Active Member

Posts

Joined
Sat Jan 08, 2011 11:05 pm
Location - Netherlands

Post by UntouchableS » Tue Aug 28, 2012 6:11 am

I need exact same solution. I tried to directly add links in header file, but fonts and links positions were messed up.

Code: Select all

<div id="menu">
  <ul>
    <li><a href="http://www.storename.com.br/link1">Product 1</a></li>
    <li><a href="http://www.storename.com.br/link2">Product 2</a></li>
  </ul>
</div>

Newbie

Posts

Joined
Tue Aug 28, 2012 12:54 am

Post by UntouchableS » Tue Aug 28, 2012 11:42 pm

You should try this, it worked for me:

Code: Select all

$this->load->model('catalog/product');
 
$products_1 = $this->model_catalog_product->getProducts($data = array());  											
if ($products_1) {$output = '<ul id="topnav">';}  															
foreach ($products_1 as $product_1) {																			
	$output .= '<li>';																																			
	$unrewritten  = $this->url->link('product/product', 'product_id=' . $product_1['product_id']);								
	$output .= '<a href="'.($unrewritten).'">' . $product_1['model'] . '</a>';								
}
if ($products_1) {$output .= '</ul>';}															
echo $output; 																			
?>

Newbie

Posts

Joined
Tue Aug 28, 2012 12:54 am

Post by morktron » Mon Sep 03, 2012 11:49 am

Wow, thanks Untouchables, that has indeed work for me as well! :)

Thanks so much and sorry for my slow reply - I had forgotten to be notified of follow up posts ;)

Thanks again you've made my day and restored my faith in OpenCart :)

Goodbye Virtuemart! Hello Opencart! :)


New member

Posts

Joined
Tue Jun 12, 2012 1:48 pm
Location - Ballina, NSW, Australia

Post by powershot » Thu Feb 21, 2013 8:26 pm

UntouchableS wrote:You should try this, it worked for me:

Code: Select all

$this->load->model('catalog/product');
 
$products_1 = $this->model_catalog_product->getProducts($data = array());  											
if ($products_1) {$output = '<ul id="topnav">';}  															
foreach ($products_1 as $product_1) {																			
	$output .= '<li>';																																			
	$unrewritten  = $this->url->link('product/product', 'product_id=' . $product_1['product_id']);								
	$output .= '<a href="'.($unrewritten).'">' . $product_1['model'] . '</a>';								
}
if ($products_1) {$output .= '</ul>';}															
echo $output; 																	
?>
mark.dude

Newbie

Posts

Joined
Sat May 26, 2012 6:35 am

Post by feelergonomics » Fri Apr 12, 2013 11:53 pm

I have the same problem but I am not able to follow your instructions UntouchableS because I have no idea of PHP.
I also tried to directly add the links like you did as first try. I had no problems with fonts but I had the problem when
I deactivated the categories which were shown in the top menu, the direct links also disappeared.

So may you or someone else explain your second solution?
$this->load->model('catalog/product');

$products_1 = $this->model_catalog_product->getProducts($data = array());
if ($products_1) {$output = '<ul id="topnav">';}
foreach ($products_1 as $product_1) {
$output .= '<li>';
$unrewritten = $this->url->link('product/product', 'product_id=' . $product_1['product_id']);
$output .= '<a href="'.($unrewritten).'">' . $product_1['model'] . '</a>';
}
if ($products_1) {$output .= '</ul>';}
echo $output;
?>
Which date file is ment? Where in the data file has something to be changed? Do I only have to Just copy the stuff above into the correct line? Or is it more tricky?


Posts

Joined
Fri Apr 12, 2013 11:43 pm
Who is online

Users browsing this forum: No registered users and 5 guests