Page 1 of 1

All Categories on the front page in 1.4.6?

Posted: Fri Apr 02, 2010 11:37 pm
by Noman
Hi Guys

Does anyone know how to display all categories on the front page instead of Latest products? I tried 2 solutions found here but they don't seem to work as they were designed for 1.4.4 and older.

Thank you.

Re: All Categories on the front page in 1.4.6?

Posted: Mon Apr 05, 2010 7:02 pm
by Noman
Hello World

Is this so difficult or no one tried yet?

Re: All Categories on the front page in 1.4.6?

Posted: Tue Apr 06, 2010 5:17 pm
by ThePath
how many products do you have?

You could use the featured products hack and just add all your products to featured module!!

Re: All Categories on the front page in 1.4.6?

Posted: Tue Apr 06, 2010 6:46 pm
by Noman
Hi

I do not want to display any products on the front page. I have 12 categories and I need them to be on the home page instead of the Mod on the left "Categories". It's like to have thumbnails of categories so people can choose with ease. Thanks.

Re: All Categories on the front page in 1.4.6?

Posted: Tue Apr 06, 2010 6:56 pm
by ThePath
Well just hand code them into home.tpl

Re: All Categories on the front page in 1.4.6?

Posted: Wed Apr 07, 2010 6:43 am
by Noman
Knowing how to hard code them I wouldn't ask for help.
ThePath wrote:Well just hand code them into home.tpl

Re: All Categories on the front page in 1.4.6?

Posted: Wed Apr 07, 2010 8:18 pm
by ThePath
Well you could use fido's Homepage Module. It will allow you to create a box on your homepage and add linked image thumbnails to it.

Re: All Categories on the front page in 1.4.6?

Posted: Thu Apr 08, 2010 12:40 am
by Wade C
I deleted the latest products from the home.tpl and then just hand did all the categories in the Home page section of the admin using the editor. Its a pain when adding a new category, but better than nothing and I dont know enough to code it into the .tpl

I used a table for the images and text, so I can at least drag and drop stuff when I have to add something new and reorder it.

Wade

Re: All Categories on the front page in 1.4.6?

Posted: Wed Apr 28, 2010 5:08 pm
by nat
Try this:

edit home.php

Code: Select all


<?php  
class ControllerCommonHome extends Controller {
	public function index() {
		$this->language->load('common/home');
		
		$this->document->title = $this->config->get('config_title');
		$this->document->description = $this->config->get('config_meta_description');
		
		$this->data['heading_title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_name'));
		
		$this->load->model('setting/store');
		
		$store_info = $this->model_setting_store->getStore($this->config->get('config_store_id'));
		
		if ($store_info) {
			$this->data['welcome'] = html_entity_decode($store_info['description']);
		} else {
			$this->data['welcome'] = '';
		}
		
		$this->data['text_latest'] = $this->language->get('text_latest');
		
		$this->load->model('catalog/product');
		$this->load->model('catalog/review');
		$this->load->model('tool/seo_url');
		$this->load->model('tool/image');
		
		
		/* START: Added for homepage category hacks */
		$this->load->model('catalog/category');
		//Set Category for display
           $category_id = '0';
		//Get total categories in your category
		$category_total = $this->model_catalog_category->getTotalCategoriesByCategoryId($category_id);
		$this->data['products'] = array();
		if (isset($category_total)) {
			$this->data['categories'] = array();
			$results = $this->model_catalog_category->getCategories($category_id);
			foreach ($results as $result) {
				if ($result['image']) {
					$image = $result['image'];
				} else {
					$image = 'no_image.jpg';
				}

				$this->data['categories'][] = array(
				'name'  => $result['name'],
				//'href'  => $this->model_tool_seo_url->rewrite($this->url->http('product/category&path=' . $result['category_id'])),
				'href'    => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/category&path=' . $result['category_id']),
				//'thumb' => image_resize($image, $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'))
				'thumb'   => $this->model_tool_image->resize($image, $this->config->get('config_image_category_width'), $this->config->get('config_image_category_height'))
				);
            }

			$this->id       = 'content';
			$this->template = $this->template = 'default/template/common/home.tpl';
			$this->layout   = 'common/layout';
			$this->render();
        }
        /* END: Added for homepage category hacks */
		
		$this->data['products'] = array();

		foreach ($this->model_catalog_product->getLatestProducts(8) as $result) {			
			if ($result['image']) {
				$image = $result['image'];
			} else {
				$image = 'no_image.jpg';
			}
			
			$rating = $this->model_catalog_review->getAverageRating($result['product_id']);	
			
			$special = FALSE;
			
			$discount = $this->model_catalog_product->getProductDiscount($result['product_id']);
			
			if ($discount) {
				$price = $this->currency->format($this->tax->calculate($discount, $result['tax_class_id'], $this->config->get('config_tax')));
			} else {
				$price = $this->currency->format($this->tax->calculate($result['price'], $result['tax_class_id'], $this->config->get('config_tax')));
			 
				$special = $this->model_catalog_product->getProductSpecial($result['product_id']);
			
				if ($special) {
					$special = $this->currency->format($this->tax->calculate($special, $result['tax_class_id'], $this->config->get('config_tax')));
				}						
			}
				
          	$this->data['products'][] = array(
            	'name'    => $result['name'],
				'model'   => $result['model'],
            	'rating'  => $rating,
				'stars'   => sprintf($this->language->get('text_stars'), $rating),
				'thumb'   => $this->model_tool_image->resize($image, $this->config->get('config_image_product_width'), $this->config->get('config_image_product_height')),
            	'price'   => $price,
				'special' => $special,
				'href'    => $this->model_tool_seo_url->rewrite(HTTP_SERVER . 'index.php?route=product/product&product_id=' . $result['product_id'])
          	);
		}

		if (!$this->config->get('config_customer_price')) {
			$this->data['display_price'] = TRUE;
		} elseif ($this->customer->isLogged()) {
			$this->data['display_price'] = TRUE;
		} else {
			$this->data['display_price'] = FALSE;
		}
				
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/home.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/common/home.tpl';
		} else {
			$this->template = 'default/template/common/home.tpl';
		}
		
		$this->children = array(
			'common/header',
			'common/footer',
			'common/column_left',
			'common/column_right'
		);
		
		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
	}
}
?>

end home.tpl (only categories will be view, products view is comment)

Code: Select all


<?php echo $header; ?><?php echo $column_left; ?><?php echo $column_right; ?>
	<div id="content">
	  <div class="top">
		<div class="left"></div>
		<div class="right"></div>
		<div class="center">
		  <h1><?php echo $heading_title; ?></h1>
		</div>
	  </div>
	  <div class="middle">
		<div><?php echo $welcome; ?></div>
		
		<div class="heading"><?php echo $text_latest; ?></div>
		<?php /* START: Added for homepage category hacks */ ?>
		<?php if ($categories) { ?>
        <table class="list">
          <?php for ($i = 0; $i < sizeof($categories); $i = $i + 4) { ?>
          <tr>
            <?php for ($j = $i; $j < ($i + 4); $j++) { ?>
            <td width="25%"><?php if (isset($categories[$j])) { ?>
              <a href="<?php echo $categories[$j]['href']; ?>"><img src="<?php echo $categories[$j]['thumb']; ?>" title="<?php echo $categories[$j]['name']; ?>" alt="<?php echo $categories[$j]['name']; ?>" style="margin-bottom: 3px;" /></a><br />
              <a href="<?php echo $categories[$j]['href']; ?>"><?php echo $categories[$j]['name']; ?></a>
              <?php } ?></td>
            <?php } ?>
          </tr>
          <?php } ?>
        </table>
        <?php } ?>
		<?php /* END: Added for homepage category hacks */ /* ?>
		<table class="list">
		  <?php for ($i = 0; $i < sizeof($products); $i = $i + 4) { ?>
		  <tr>
			<?php for ($j = $i; $j < ($i + 4); $j++) { ?>
			<td style="width: 25%;"><?php if (isset($products[$j])) { ?>
			  <a href="<?php echo str_replace('&', '&', $products[$j]['href']); ?>"><img src="<?php echo $products[$j]['thumb']; ?>" title="<?php echo $products[$j]['name']; ?>" alt="<?php echo $products[$j]['name']; ?>" /></a><br />
			  <a href="<?php echo str_replace('&', '&', $products[$j]['href']); ?>"><?php echo $products[$j]['name']; ?></a><br />
			  <span style="color: #999; font-size: 11px;"><?php echo $products[$j]['model']; ?></span><br />
			  <?php if ($display_price) { ?>
			  <?php if (!$products[$j]['special']) { ?>
			  <span style="color: #900; font-weight: bold;"><?php echo $products[$j]['price']; ?></span><br />
			  <?php } else { ?>
			  <span style="color: #900; font-weight: bold; text-decoration: line-through;"><?php echo $products[$j]['price']; ?></span> <span style="color: #F00;"><?php echo $products[$j]['special']; ?></span>
			  <?php } ?>
			  <?php } ?>
			  <?php if ($products[$j]['rating']) { ?>
			  <img src="catalog/view/theme/default/image/stars_<?php echo $products[$j]['rating'] . '.png'; ?>" alt="<?php echo $products[$j]['stars']; ?>" />
			  <?php } ?>
			  <?php } ?></td>
			<?php } ?>
		  </tr>
		  <?php } ?>
		 </table>
		<?php */ ?>		
	  </div>
	  <div class="bottom">
		<div class="left"></div>
		<div class="right"></div>
		<div class="center"></div>
	  </div>
	</div>
<?php echo $footer; ?>

Nat

Re: All Categories on the front page in 1.4.6?

Posted: Fri May 07, 2010 4:14 am
by SoulV
Excellent work.. Works perfectly Cheers

Re: All Categories on the front page in Version 1.4.9.1?

Posted: Sun Oct 24, 2010 4:49 am
by SoulV
Does any one know the mod for Version 1.4.9.1?? The above worked great for previous versions... but not the new one!
It would be great to show categories on the front page center rather than latest products.

Re: All Categories on the front page in 1.4.6?

Posted: Mon Nov 08, 2010 5:34 am
by aeternitas103

Code: Select all

protected function index()
{
    $this->language->load('module/categoryhome');
    $this->data['heading_title'] = $this->language->get('heading_title');

    $this->load->model('catalog/category');
    $this->load->model('tool/seo_url');
    $this->load->model('tool/image');
 
Include the model('tool/image') and it will work.

Re: All Categories on the front page in 1.4.6?

Posted: Sat Nov 13, 2010 5:34 pm
by afendio
i use opencart v1.48b and its working. thanks a lot.

Re: All Categories on the front page in 1.4.6?

Posted: Thu Aug 04, 2011 5:16 am
by giacomoprimo
Hello everybody,
I'm interest to show all my category in home page, I'm using OC 1.5.1.1
Someone can tell me how?
Thanks