Post by mikeytrw » Fri Oct 24, 2008 10:51 pm

This isn't so much a contribution, but a modification (read 'hack') allowing the home page to display categories instead of latest products.

I've built two opencart sites where this feature has been requested so I'm assuming other people will need it.

In

/catalog/controller/home.php

change :

Code: Select all

		$product_data = array();
		
		//See: http://forum.opencart.com/index.php?topic=100.0
		$results = $database->getRows("select * from product p left join product_description pd on (p.product_id = pd.product_id) left join image i on (p.image_id = i.image_id) where p.status = '1' and pd.language_id = '" . (int)$language->getId() . "' and p.date_available < now() and p.status = '1' order by p.date_added desc limit 6");

		foreach ($results as $result) {
			$product_data[] = array(
				'name'  => $result['name'],
				'href'  => $url->href('product', FALSE, array('product_id' => $result['product_id'])),
				'thumb' => $image->resize($result['filename'], $config->get('config_image_width'), $config->get('config_image_height')),
				'price' => $currency->format($tax->calculate($result['price'], $result['tax_class_id'], $config->get('config_tax')))
			);
		}

		$view->set('products', $product_data);
to :

Code: Select all

       $category_data = array();
        		
		$results = $database->getRows("select * from category c left join category_description cd on (c.category_id = cd.category_id) left join image i on (c.image_id = i.image_id) where c.parent_id = '0' and cd.language_id = '" . (int)$language->getId() . "' order by sort_order");
				
        foreach ($results as $result) {
          	$category_data[] = array(
            	'name'  => $result['name'],
            	'href'  => $url->href('category', FALSE, array('path' => $result['category_id'])),
            	'thumb' => $image->resize($result['filename'], $config->get('config_image_width'), $config->get('config_image_height'))
          		);
        }

		$view->set('categories', $category_data);

and in /catalog/template/[template name]/content/home.tpl

change:

Code: Select all

<div class="heading"><?php echo $text_latest; ?></div> 
<?php foreach ($products as $product) { ?>
  <div class="products"><a href="<?php echo $product['href']; ?>"><img src="<?php echo $product['thumb']; ?>" title="<?php echo $product['name']; ?>" alt="<?php echo $product['name']; ?>"></a><br><b><a href="<?php echo $product['href']; ?>"><?php echo $product['name']; ?></a></b><br><?php echo $product['price']; ?></div>
<?php } ?>

to:

Code: Select all

<?php if ($categories) { ?>
<?php foreach ($categories as $category) { ?>
<div class="categories"><a href="<?php echo $category['href']; ?>"><img src="<?php echo $category['thumb']; ?>" title="<?php echo $category['name']; ?>" alt="<?php echo $category['name']; ?>" /></a><br />
  <a href="<?php echo $category['href']; ?>"><?php echo $category['name']; ?></a></div>
<?php } ?>
<?php } ?>

any problems give me a PM.

Thanks

New member

Posts

Joined
Tue May 27, 2008 9:28 pm

Post by Qphoria » Fri Oct 24, 2008 11:25 pm

A very nice idea.
Thanks!

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by skunky » Fri Oct 31, 2008 9:14 pm

would this work with your mod' here http://forum.opencart.com/index.php/top ... l#msg10530

??

Newbie

Posts

Joined
Fri Oct 31, 2008 7:06 pm

Post by Qphoria » Fri Oct 31, 2008 9:36 pm

It should. The category links on the homepage should link to their category list page, which would call my code.

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by skunky » Fri Oct 31, 2008 9:37 pm

I apologise if you frown on unnecessary posting... but, thanks!

Newbie

Posts

Joined
Fri Oct 31, 2008 7:06 pm

Post by Qphoria » Fri Oct 31, 2008 9:39 pm

frown?! I thrive on it! But then bruce yells at me!  ;D

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by skunky » Fri Oct 31, 2008 10:12 pm

well this works perfectly on my site... just thought i'd let you know. and thanks for taking the time to share :)

Newbie

Posts

Joined
Fri Oct 31, 2008 7:06 pm

Post by bruce » Fri Oct 31, 2008 10:43 pm

Qphoria wrote: frown?! I thrive on it! But then bruce yells at me!  ;D
:D you remembered... LOL

Congratulations mate on the birth of your three daughters.
Last edited by bruce on Fri Oct 31, 2008 10:46 pm, edited 1 time in total.

Active Member

Posts

Joined
Wed Dec 12, 2007 2:26 pm

Post by rod » Mon Nov 03, 2008 7:45 am

This works very well on my site too, thanks! Is the welcome guest message supposed to dissapear after making this mod? If not, I made a wrong turn somewhere. Can you help?

Jesus Saves!


User avatar
rod
Newbie

Posts

Joined
Wed Oct 15, 2008 10:39 pm
Location - Longview, Texas

Post by Qphoria » Mon Nov 03, 2008 7:50 am

bruce wrote:
Qphoria wrote: frown?! I thrive on it! But then bruce yells at me!  ;D
:D you remembered... LOL

Congratulations mate on the birth of your three daughters.
LOL random place to put this! I just happened to notice the edit while looking at rod's reply. But thanks!

Image
Donate!|OpenCart Basics|GeoZones
Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by jty » Mon Nov 03, 2008 9:56 am

rod wrote: This works very well on my site too, thanks! Is the welcome guest message supposed to dissapear after making this mod? If not, I made a wrong turn somewhere. Can you help?
Hello Rod,
The welcome guest message can be removed by editing
catalog/template/default/home.tpl

Comment out or delete this line(s) at the top

Code: Select all

<!-- <div class="heading"><?php echo $heading_title; ?></div>
<?php echo $text_greeting; ?> -->
If you want to keep the message but change the wording, wordings are found in the corresponding language files.
Edit catalog/laguage/english/controller/home.php
I suppose you swap english for your language if you're not english

jty
Active Member

Posts

Joined
Sat Aug 30, 2008 8:19 am
Who is online

Users browsing this forum: No registered users and 2 guests