PrestaShop Forum

The best place in the world to ask questions about PrestaShop and get advice from our passionate community!

PrestaShop Forum

Jump to content

Frontpage Categories Module for v1.3 and below

209 replies to this topic
#1
ejectcore

    PrestaShop Addict

  • Members
  • PipPipPip
  • 827 posts
I have to say this is the first Module for prestashop I have ever created, some of you here may already know how to do this. but for those who don't carry on reading below

Sorry this module is in english only I am no good with module translation  :-
As I progress with learning PrestaShop I will try to share these new Mods  ;)

Frontpage Categories v0.1
Displays categories in the middle of your homepage

Please download then unzip homecategories.zip to the modules directory then upload.

All you have to do then is add the value homecategories to name field & value 1 in to active field within mysql table ps_module then your see the new module in the PrestaShop Admin. (Select hompage possition)

I have not used any styling from global.css so if you wan to use box styling you will need to modify homecategories.tpl

example

change:
<div>
<h4>{l s='categories' mod='homecategories'}</h4>
	{if isset($categories) AND $categories}
<div>

to:
<div id="featured-products_block_center" class="block products_block">
<h4>{l s='categories' mod='homecategories'}</h4>
	{if isset($categories) AND $categories}
<div class="block_content">

Enjoy  :) 



Attached Files


Filter Search 2.1 Enterprise Edition Now Available

Available Soon
Filter Search 2.1 Lite Edition

Follow us on twitter

#2
ejectcore

    PrestaShop Addict

  • Members
  • PipPipPip
  • 827 posts
Quick note: Make sure categories are enabled on the left column for the frontpage categories to work.
Question for the Prestashop Team how do I get this module to work in any position, it seems to only work when categories are displayed on the left column  ???

<?php

class Homecategories extends Module
{
	private $_html = '';
	private $_postErrors = array();

	function __construct()
	{
		$this->name = 'homecategories';
		$this->tab = 'Home';
		$this->version = 0.1;

		parent::__construct(); // The parent construct is required for translations

		$this->page = basename(__FILE__, '.php');
		$this->displayName = $this->l('Frontpage Categories');
		$this->description = $this->l('Displays categories in the middle of your homepage');
	}

	function install()
	{
		if (!Configuration::updateValue('HOME_categories_NBR', 10) OR !parent::install() OR !$this->registerHook('home'))
			return false;
		return true;
	}

	public function getContent()
	{
		$output = '<h2>'.$this->displayName.'</h2>';
		if (Tools::isSubmit('submitHomecategories'))
		{
			$nbr = intval(Tools::getValue('nbr'));
			if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr))
				$errors[] = $this->l('Invalid number of categories');
			else
				Configuration::updateValue('HOME_categories_NBR', $nbr);
			if (isset($errors) AND sizeof($errors))
				$output .= $this->displayError(implode('<br />', $errors));
			else
				$output .= $this->displayConfirmation($this->l('Settings updated'));
		}
		return $output.$this->displayForm();
	}

	public function displayForm()
	{
		$output = '
		<form action="'.$_SERVER['REQUEST_URI'].'" method="post">
			<fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
				<label>'.$this->l('Number of categories displayed').'</label>
				<div class="margin-form">
					<input type="text" size="5" name="nbr" value="'.Tools::getValue('nbr', Configuration::get('HOME_categories_NBR')).'" />
					<p class="clear">'.$this->l('The number of catgeories displayed on homepage (default: 10)').'</p>
					
				</div>
				<center><input type="submit" name="submitHomecategories" value="'.$this->l('Save').'" class="button" /></center>
			</fieldset>
		</form>';
		return $output;
	}

	function hookHome($params)
	{
		global $smarty;
		$category = new Category(1);
		$nb = intval(Configuration::get('HOME_categories_NBR'));
		
		$smarty->assign(array(
			'category' => $category,
			'lang' => Language::getIsoById(intval($params['cookie']->id_lang)),
		));
		return $this->display(__FILE__, 'homecategories.tpl');
	}

}


Filter Search 2.1 Enterprise Edition Now Available

Available Soon
Filter Search 2.1 Lite Edition

Follow us on twitter

#3
Rain3r

    PrestaShop Apprentice

  • Members
  • PipPip
  • 143 posts
I ve done it as you said but nothing new appears on the home page :(

#4
ejectcore

    PrestaShop Addict

  • Members
  • PipPipPip
  • 827 posts
Make sure you have categories in the left column & inserted the value into the database  8)
& don't forget to upload the homecategories folder into the modules directory

Then if all the above is correct activate it in the admin (Transplant a module)
then Frontpage Categories will appear in the dropdown hook into Homepage Content

Attached Files


Filter Search 2.1 Enterprise Edition Now Available

Available Soon
Filter Search 2.1 Lite Edition

Follow us on twitter

#5
Rain3r

    PrestaShop Apprentice

  • Members
  • PipPip
  • 143 posts
Maybe that is the problem, when I click on Transplant module, I get only Hack atempt message :(

#6
ejectcore

    PrestaShop Addict

  • Members
  • PipPipPip
  • 827 posts
Just a thought to activate frontpage categories manually via mysql:

First backup your DB then enter the id you used to setup this module in table ps_module ie. (36 homecategories)
now enter this id into ps_hook module id_module then in the next field enter 8 which is the idhook for home then enter 1 for the possition value

No idea why your getting hack attempt but the above should work. If not fix this issue before using this module
search for forum maybe someone has the same issue if not go back & see what the developers say.

To completely change the subject will RC3 be released in the next few days?


Filter Search 2.1 Enterprise Edition Now Available

Available Soon
Filter Search 2.1 Lite Edition

Follow us on twitter

#7
jolvil

    PrestaShop Fanatic

  • Members
  • PipPipPipPip
  • 2706 posts
I've installed this module on a RC2 test shop, it works perfectly.  You can see result at
Categories are dispayed in a single column, it could be nice to be able to choose 1,2,3 or 4... columns on admin.

Thanks for this works

#8
ejectcore

    PrestaShop Addict

  • Members
  • PipPipPip
  • 827 posts
All you have to do to get your column layout is add some new styles to global.css or set css to the same as the featured module blocks  :)
<div id="featured-products_block_center" class="block products_block">
Filter Search 2.1 Enterprise Edition Now Available

Available Soon
Filter Search 2.1 Lite Edition

Follow us on twitter

#9
ejectcore

    PrestaShop Addict

  • Members
  • PipPipPip
  • 827 posts
I am currently looking at a 3 column layout for one of my own projects & will try to update zip when complete  ::)
Filter Search 2.1 Enterprise Edition Now Available

Available Soon
Filter Search 2.1 Lite Edition

Follow us on twitter

#10
ejectcore

    PrestaShop Addict

  • Members
  • PipPipPip
  • 827 posts
Frontpage Categories Module V0.2
3 Column Front Page Category layout  8)
(Make sure you have the category size in the admin set to the same size as your images)

here's the css you need to add to global.css within your themes directory

#homeCatWrapper {
 margin-left: 6px; /* You may not need this unless you want to try to center categories */
}
#homeCat {
 float: left;
 width: 124px; 
}
#homeCat h5 {
 text-align: center; 
}

Attached Files


Filter Search 2.1 Enterprise Edition Now Available

Available Soon
Filter Search 2.1 Lite Edition

Follow us on twitter

#11
ejectcore

    PrestaShop Addict

  • Members
  • PipPipPip
  • 827 posts

Quote

Quick note: Make sure categories are enabled on the left column for the frontpage categories to work.
Question for the Prestashop Team how do I get this module to work in any position, it seems to only work when categories are displayed on the left column  ???

I missed out the obvious  :-[
allow for both hooks in header & footer

header.php
<?php
require_once(dirname(__FILE__).'/init.php');

/* CSS */
$css_files[_THEME_CSS_DIR_.'global.css'] = 'all';

/* Hooks are volontary out the initialize array (need those variables already assigned) */
$smarty->assign(array(
	'HOOK_HEADER' => Module::hookExec('header'),
	'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'),	
	'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn'),
	'HOOK_TOP' => Module::hookExec('top'),
));

if(isset($css_files) AND !empty($css_files)) $smarty->assign('css_files', $css_files);
if(isset($js_files) AND !empty($js_files)) $smarty->assign('js_files', $js_files);

/* Display a maintenance page if shop is closed */
if (isset($maintenance))
{
	header('HTTP/1.1 503 temporarily overloaded');
	$smarty->display(_PS_THEME_DIR_.'maintenance.tpl');
	exit;
}

$smarty->display(_PS_THEME_DIR_.'header.tpl');

?>

footer.php
<?php

if (isset($smarty))
{
	$smarty->assign(array(
     	'HOOK_RIGHT_COLUMN' => Module::hookExec('rightColumn'),	
		'HOOK_LEFT_COLUMN' => Module::hookExec('leftColumn'),
		'HOOK_FOOTER' => Module::hookExec('footer')));
	$smarty->display(_PS_THEME_DIR_.'footer.tpl');
}

?>

Filter Search 2.1 Enterprise Edition Now Available

Available Soon
Filter Search 2.1 Lite Edition

Follow us on twitter

#12
negoce

    PrestaShop Apprentice

  • Members
  • PipPip
  • 264 posts
Hi,

I like this contribution,

I try in RC3 stable...

Buy
------
Merci Presta et ses amis :cheese:
------

Negoce...

#13
RC3

    PrestaShop Newbie

  • Members
  • Pip
  • 12 posts
OK on RC3: http://www.asie-shop....com/boutique/ 

#14
negoce

    PrestaShop Apprentice

  • Members
  • PipPip
  • 264 posts
Hi,

thanks  ;)

how to creating on home categories on 3 or 4 columns ?

buy...
------
Merci Presta et ses amis :cheese:
------

Negoce...

#15
ejectcore

    PrestaShop Addict

  • Members
  • PipPipPip
  • 827 posts
Just use the css provided in the post above & download the latest zip  ;)
if not provide web link & I have a quick look  :)
Filter Search 2.1 Enterprise Edition Now Available

Available Soon
Filter Search 2.1 Lite Edition

Follow us on twitter

#16
negoce

    PrestaShop Apprentice

  • Members
  • PipPip
  • 264 posts
Hi,

Thanks & good night from France  :o

buy
------
Merci Presta et ses amis :cheese:
------

Negoce...

#17
ejectcore

    PrestaShop Addict

  • Members
  • PipPipPip
  • 827 posts
au revoir  ;D
Filter Search 2.1 Enterprise Edition Now Available

Available Soon
Filter Search 2.1 Lite Edition

Follow us on twitter

#18
Project 14

    PrestaShop Newbie

  • Members
  • Pip
  • 23 posts
Hi,
How can I get the category description to show in the {foreach} loop with this module? I've tried all the combinations of $category.desc / .description / .description_short - nothing seems to pull out the information - I just get a blank space.

Thanks,

#19
Project 14

    PrestaShop Newbie

  • Members
  • Pip
  • 23 posts
Any help on this - it must be a very simple answer...

#20
ejectcore

    PrestaShop Addict

  • Members
  • PipPipPip
  • 827 posts
Please post you code & I will see if I can help
I have plans to update this module but have a few more requests before going back to this :roll:
Filter Search 2.1 Enterprise Edition Now Available

Available Soon
Filter Search 2.1 Lite Edition

Follow us on twitter