Page 1 of 2
Re: Categories on the front page
Posted: Mon Feb 01, 2010 8:30 am
by soul
Solved the problem for 1.4.. need to add:
Code: Select all
$this->load->model('catalog/category');
in the loaders of home.php. Still getting some errors which I need to figure out but that at least gets the categories to load.
Re: Categories on the front page
Posted: Sat Feb 20, 2010 12:50 am
by davey c
For anyone interested, I got this working on version 1.4 now:
Here is the code for home.tpl:
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 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 if ($products) { ?>
<div class="sort">
<div class="div1">
<select name="sort" onchange="location=this.value">
<?php foreach ($sorts as $sorts) { ?>
<?php if (($sort . '-' . $order) == $sorts['value']) { ?>
<option value="<?php echo $sorts['href']; ?>" selected="selected"><?php echo $sorts['text']; ?></option>
<?php } else { ?>
<option value="<?php echo $sorts['href']; ?>"><?php echo $sorts['text']; ?></option>
<?php } ?>
<?php } ?>
</select>
</div>
<div class="div2"><?php echo $text_sort; ?></div>
</div>
<table class="list">
<?php for ($i = 0; $i < sizeof($products); $i = $i + 4) { ?>
<tr>
<?php for ($j = $i; $j < ($i + 4); $j++) { ?>
<td width="25%"><?php if (isset($products[$j])) { ?>
<a href="<?php echo $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 $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>
<div class="pagination"><?php echo $pagination; ?></div>
<?php } ?>
</div>
<div class="bottom">
<div class="left"></div>
<div class="right"></div>
<div class="center"></div>
</div>
</div>
<?php echo $footer; ?>
Here is the code for 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_store'));
$this->data['welcome'] = html_entity_decode($this->config->get('config_welcome_' . $this->config->get('config_language_id')));
$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->helper('image');
$this->load->model('catalog/category');
/* START: Added for homepage category hacks */
//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'])),
//'thumb' => HelperImage::resize($image, 120, 120)
'thumb' => 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' => 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($this->url->http('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'));
}
}
?>
Re: [MOD] Categories on the front page
Posted: Sun Feb 28, 2010 5:09 pm
by deeve
Been a while since I tried all of the above & looked on the surface like it worked but just gone back to dev site & noticed I'm getting these errors on base elements which are causing a lag on certain page loads - anyone got any ideas why?:
Undefined variable: header in mypath/store/catalog/view/theme/default/template/common/home.tpl on line 1
Undefined variable: column_left in mypath/store/catalog/view/theme/default/template/common/home.tpl on line 1
Undefined variable: column_right in mypath/store/catalog/view/theme/default/template/common/home.tpl on line 1
Undefined variable: footer in mypath/store/catalog/view/theme/default/template/common/home.tpl on line 36
OC 1.3.4
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_store'));
$this->data['welcome'] = html_entity_decode($this->config->get('config_welcome_' . $this->config->get('config_language_id')));
$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->helper('image');
$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' => 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($this->url->http('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'));
}
}
?>
Re: [MOD] Categories on the front page
Posted: Thu Mar 04, 2010 9:28 pm
by deeve
No one else getting these errors with this mod?
Re: [MOD] Categories on the front page
Posted: Tue Mar 23, 2010 7:28 pm
by deeve
Doh! Again, I overlooked to include the working [or rather NOT working] php file. If anyone could shine a light on why I'm receiving these undefined variable errors I'd be eternally grateful !
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->document->breadcrumbs = array();
$this->document->breadcrumbs[] = array(
'href' => $this->url->http('common/home'),
'text' => $this->language->get('text_home'),
'separator' => FALSE
);
$this->data['heading_title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_store'));
$this->data['welcome'] = html_entity_decode($this->config->get('config_welcome_' . $this->language->getId()));
$this->data['text_latest'] = $this->language->get('text_latest');
$this->load->model('catalog/product');
$this->load->model('catalog/category');
$this->load->model('catalog/review');
$this->load->model('tool/seo_url');
$this->load->helper('image');
/* START: Added for homepage category hacks */
//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'])),
//'thumb' => HelperImage::resize($image, 151, 151)
'thumb' => 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 */
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' => 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($this->url->http('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));
}
}
?>
Re: [MOD] Categories on the front page
Posted: Sun Apr 25, 2010 10:08 am
by nosecreek
*bump*
Has anyone gotten this to work in 1.4?
Also, I'm a little confused. Do I need Fido-X's module to make this work, or do I just need to edit the home.tpl and home.php files? If its the latter, then it is not working (1.4.7).
Re: [MOD] Categories on the front page
Posted: Wed Apr 28, 2010 5:14 pm
by espc
it does not work on 1.4.7 I agree...
Re: [MOD] Categories on the front page
Posted: Wed Oct 20, 2010 12:49 am
by hodet
I too have had a request for this, as the front page (Featured items) are too diverse for a particular store. They felt it made the front page look messy. So....
Mods are fine for this but would it not just be simpler to use the HTML functions in System-->Setting-->Store-->Welcome Message and move any modules in the center to the side. Create 120x120 png images to represent your categories and link to them.
That way you can be virtually assured that future upgrades won't break anything. Seems much simpler way then hacking code.
I do agree that "out of the box" would be a great feature to have your categories in the center that represent like a portal to your products.
Re: [MOD] Categories on the front page
Posted: Mon Oct 25, 2010 8:24 pm
by scanreg
hodet wrote:I do agree that "out of the box" would be a great feature to have your categories in the center that represent like a portal to your products.
Would be great if a frontpage category table were part of the core, customers look for that often, could even display first level subcats in text under the main cat pics too