Jump to content

Random product display on featured page


Recommended Posts

clear shop cache now ! :)


also, try to use this one:

public function hookDisplayHome($params)
	{

			$this->_cacheProducts();

$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));
        $products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100);
        if ($products) {
        shuffle($products);
        array_splice($products, ($nb ? $nb : 10));
        }


			$this->smarty->assign(
				array(
					'products' => $products,
					'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
					'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
				)
			);
		

		return $this->display(__FILE__, 'homefeatured.tpl');
	}
  • Like 1
Link to comment
Share on other sites

cicciotargatona you try to change some of the examples vekia provided before in this same post, try modifing your homefeatured.php  after this you may make it work.

 

Amcm112 I have try really all the examples, but nothing change. I know that the codes of Vekia are corrects, but in my version of prestashop don't work it, I'm not lucky,,,

Link to comment
Share on other sites

Amcm112 I have try really all the examples, but nothing change. I know that the codes of Vekia are corrects, but in my version of prestashop don't work it, I'm not lucky,,,

 

the only one thing you have to do is change this line:

$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));

to:

$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true);

and it was already said somewhere, in various topic i think ;)

can you try, please?

  • Like 1
Link to comment
Share on other sites

the only one thing you have to do is change this line:

$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));

to:

$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true);

and it was already said somewhere, in various topic i think ;)

can you try, please?

 

I have try :) but nothing have change, i lose my mind...

if (!defined('_PS_VERSION_'))
	exit;

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

	function __construct()
	{
		$this->name = 'homefeatured';
		$this->tab = 'front_office_features';
		$this->version = '1.1';
		$this->author = 'PrestaShop';
		$this->need_instance = 0;

		parent::__construct();

		$this->displayName = $this->l('Featured products on the homepage.');
		$this->description = $this->l('Displays featured products in the middle of your homepage.');
	}

	function install()
	{
		$this->_clearCache('homefeatured.tpl');
		Configuration::updateValue('HOME_FEATURED_NBR', 8);

		if (!parent::install()
			|| !$this->registerHook('displayHome')
			|| !$this->registerHook('header')
			|| !$this->registerHook('addproduct')
			|| !$this->registerHook('updateproduct')
			|| !$this->registerHook('deleteproduct')
		)
			return false;
		return true;
	}
	
	public function uninstall()
	{
		$this->_clearCache('homefeatured.tpl');
		return parent::uninstall();
	}

	public function getContent()
	{
		$output = '<h2>'.$this->displayName.'</h2>';
		if (Tools::isSubmit('submitHomeFeatured'))
		{
			$nbr = (int)Tools::getValue('nbr');
			if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr))
				$errors[] = $this->l('An invalid number of products has been specified.');
			else
				Configuration::updateValue('HOME_FEATURED_NBR', (int)($nbr));
			if (isset($errors) AND sizeof($errors))
				$output .= $this->displayError(implode('<br />', $errors));
			else
				$output .= $this->displayConfirmation($this->l('Your settings have been updated.'));
		}
		return $output.$this->displayForm();
	}

	public function displayForm()
	{
		$output = '
		<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
			<fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
				<p>'.$this->l('To add products to your homepage, simply add them to the "home" category.').'</p><br />
				<label>'.$this->l('Define the number of products to be displayed.').'</label>
				<div class="margin-form">
					<input type="text" size="5" name="nbr" value="'.Tools::safeOutput(Tools::getValue('nbr', (int)(Configuration::get('HOME_FEATURED_NBR')))).'" />
					<p class="clear">'.$this->l('Define the number of products that you would like to display on homepage (default: 8).').'</p>

				</div>
				<center><input type="submit" name="submitHomeFeatured" value="'.$this->l('Save').'" class="button" /></center>
			</fieldset>
		</form>';
		return $output;
	}

	public function hookDisplayHeader($params)
	{
		$this->hookHeader($params);
	}

	public function hookHeader($params)
	{
		$this->context->controller->addCSS(($this->_path).'homefeatured.css', 'all');
	}


public function hookDisplayHome($params)
	{

			$this->_cacheProducts();

$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true);
        $products = $category->getProducts(intval($params['cookie']->id_lang), 1, 100);
        if ($products) {
        shuffle($products);
        array_splice($products, ($nb ? $nb : 10));
        }


			$this->smarty->assign(
				array(
					'products' => $products,
					'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
					'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
				)
			);
		

		return $this->display(__FILE__, 'homefeatured.tpl');
	}

	public function hookAddProduct($params)
	{
		$this->_clearCache('homefeatured.tpl');
	}

	public function hookUpdateProduct($params)
	{
		$this->_clearCache('homefeatured.tpl');
	}

	public function hookDeleteProduct($params)
	{
		$this->_clearCache('homefeatured.tpl');
	}
}

Link to comment
Share on other sites

<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/afl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2013 PrestaShop SA
*  @license    http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/

if (!defined('_PS_VERSION_'))
	exit;

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

	function __construct()
	{
		$this->name = 'homefeatured';
		$this->tab = 'front_office_features';
		$this->version = '1.1';
		$this->author = 'PrestaShop';
		$this->need_instance = 0;

		parent::__construct();

		$this->displayName = $this->l('Featured products on the homepage.');
		$this->description = $this->l('Displays featured products in the middle of your homepage.');
	}

	function install()
	{
		$this->_clearCache('homefeatured.tpl');
		Configuration::updateValue('HOME_FEATURED_NBR', 8);

		if (!parent::install()
			|| !$this->registerHook('displayHome')
			|| !$this->registerHook('header')
			|| !$this->registerHook('addproduct')
			|| !$this->registerHook('updateproduct')
			|| !$this->registerHook('deleteproduct')
		)
			return false;
		return true;
	}
	
	public function uninstall()
	{
		$this->_clearCache('homefeatured.tpl');
		return parent::uninstall();
	}

	public function getContent()
	{
		$output = '<h2>'.$this->displayName.'</h2>';
		if (Tools::isSubmit('submitHomeFeatured'))
		{
			$nbr = (int)Tools::getValue('nbr');
			if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr))
				$errors[] = $this->l('An invalid number of products has been specified.');
			else
				Configuration::updateValue('HOME_FEATURED_NBR', (int)($nbr));
			if (isset($errors) AND sizeof($errors))
				$output .= $this->displayError(implode('<br />', $errors));
			else
				$output .= $this->displayConfirmation($this->l('Your settings have been updated.'));
		}
		return $output.$this->displayForm();
	}

	public function displayForm()
	{
		$output = '
		<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
			<fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
				<p>'.$this->l('To add products to your homepage, simply add them to the "home" category.').'</p><br />
				<label>'.$this->l('Define the number of products to be displayed.').'</label>
				<div class="margin-form">
					<input type="text" size="5" name="nbr" value="'.Tools::safeOutput(Tools::getValue('nbr', (int)(Configuration::get('HOME_FEATURED_NBR')))).'" />
					<p class="clear">'.$this->l('Define the number of products that you would like to display on homepage (default: 8).').'</p>

				</div>
				<center><input type="submit" name="submitHomeFeatured" value="'.$this->l('Save').'" class="button" /></center>
			</fieldset>
		</form>';
		return $output;
	}

	public function hookDisplayHeader($params)
	{
		$this->hookHeader($params);
	}

	public function hookHeader($params)
	{
		$this->context->controller->addCSS(($this->_path).'homefeatured.css', 'all');
	}

	public function hookDisplayHome($params)
	{
		if (!$this->isCached('homefeatured.tpl', $this->getCacheId('homefeatured')))
		{
			$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
			$nb = (int)Configuration::get('HOME_FEATURED_NBR');
			$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true);

			$this->smarty->assign(array(
				'products' => $products,
				'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
				'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
			));
		}
		return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId('homefeatured'));
	}

	public function hookAddProduct($params)
	{
		$this->_clearCache('homefeatured.tpl');
	}

	public function hookUpdateProduct($params)
	{
		$this->_clearCache('homefeatured.tpl');
	}

	public function hookDeleteProduct($params)
	{
		$this->_clearCache('homefeatured.tpl');
	}
}

Voilà :) but nothing change :( 

But i display 16 products in home page, change something it?

Thanks Vekia for the help

Link to comment
Share on other sites

clear shop cache or change:

	public function hookDisplayHome($params)
	{
		if (!$this->isCached('homefeatured.tpl', $this->getCacheId('homefeatured')))
		{
			$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
			$nb = (int)Configuration::get('HOME_FEATURED_NBR');
			$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true);
shuffle($products);

			$this->smarty->assign(array(
				'products' => $products,
				'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
				'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
			));
		}
		return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId('homefeatured'));
	}

to

	public function hookDisplayHome($params)
	{
		
			$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
			$nb = (int)Configuration::get('HOME_FEATURED_NBR');
			$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true);

			$this->smarty->assign(array(
				'products' => $products,
				'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
				'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
			));
		
		return $this->display(__FILE__, 'homefeatured.tpl');
	}
  • Like 1
Link to comment
Share on other sites

believe me or not, but you don't use default module :P search for "addhomefeatured" i think that this is proper module :P

Fuckkk you're right! hahaha, and how i can edit?

<?php

if (!defined('_PS_VERSION_'))

	exit;



class AddHomeFeatured extends Module

{

	private $_html = '';

	private $_postErrors = array();



	function __construct()

	{

		$this->name = 'addhomefeatured';

		$this->tab = 'front_office_features';

		$this->version = '1.0';

		$this->author = 'Custom';

		$this->need_instance = 0;

		parent::__construct();

		$this->displayName = $this->l('Add Featured Products on the homepage');

		$this->description = $this->l('Displays Featured Products in the middle of your homepage.');

	}



	function install()

	{

		if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) || !parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('displayHeader'))

			return false;

		return true;

	}



	public function getContent()

	{

		$output = '<h2>'.$this->displayName.'</h2>';

		if (Tools::isSubmit('submitAddHomeFeatured'))

		{

			$nbr = (int)(Tools::getValue('nbr'));

			if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr))

				$errors[] = $this->l('Invalid number of products');

			else

				Configuration::updateValue('HOME_FEATURED_NBR', (int)($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 = '

		<div class="clearfix"></div>

		<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">

			<fieldset><legend>'.$this->l('Settings').'</legend>

				<p>'.$this->l('In order to add products to your homepage, just add them to the "home" category.').'</p><br />

				<label>'.$this->l('Number of products displayed').'</label>

				<div class="margin-form">

					<input type="text" size="5" name="nbr" value="'.Tools::safeOutput(Tools::getValue('nbr', (int)(Configuration::get('HOME_FEATURED_NBR')))).'" />

					<p class="clear">'.$this->l('The number of products displayed on homepage (default: 10).').'</p>



				</div>

				<center><input type="submit" name="submitAddHomeFeatured" value="'.$this->l('Save').'" class="button" /></center>

			</fieldset>

		</form>';

		return $output;

	}

		function hookHeader($params)

	{

		$this->context->controller->addCSS($this->_path.'css/addhomefeatured.css');

	}



	public function hookDisplayHome($params)

	{

		$category = new Category(Context::getContext()->shop->getCategory(), Configuration::get('PS_LANG_DEFAULT'));

		$nb = (int)(Configuration::get('HOME_FEATURED_NBR'));





$products = $category->getProducts($params['cookie']->id_lang, 1, ($nb ? $nb : 10));

$p=array();

for($i=0;$i<count($products);$i++){

$product=$products[$i];

unset ($pid);

$pid=$product['id_product'];

$sql= "SELECT * FROM `"._DB_PREFIX_."image` WHERE `id_product` = '{$pid}' AND cover = '0' ORDER BY `id_image` ";

$results = Db::getInstance()->ExecuteS($sql);

@$result=$results['0'];

$p[$pid]=$result['id_image'];

}

$this->smarty->assign('addimages',$p);



		$this->smarty->assign(array(

			'products' => $products,

			'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),

			'homeSize' => Image::getSize('home'),

		));



		return $this->display(__FILE__, 'addhomefeatured.tpl');

	}

}
Link to comment
Share on other sites



<?php

if (!defined('_PS_VERSION_'))

exit;



class AddHomeFeatured extends Module

{

private $_html = '';

private $_postErrors = array();



function __construct()

{

$this->name = 'addhomefeatured';

$this->tab = 'front_office_features';

$this->version = '1.0';

$this->author = 'Custom';

$this->need_instance = 0;

parent::__construct();

$this->displayName = $this->l('Add Featured Products on the homepage');

$this->description = $this->l('Displays Featured Products in the middle of your homepage.');

}



function install()

{

if (!Configuration::updateValue('HOME_FEATURED_NBR', 8) || !parent::install() || !$this->registerHook('displayHome') || !$this->registerHook('displayHeader'))

return false;

return true;

}



public function getContent()

{

$output = '<h2>'.$this->displayName.'</h2>';

if (Tools::isSubmit('submitAddHomeFeatured'))

{

$nbr = (int)(Tools::getValue('nbr'));

if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr))

$errors[] = $this->l('Invalid number of products');

else

Configuration::updateValue('HOME_FEATURED_NBR', (int)($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 = '

<div class="clearfix"></div>

<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">

<fieldset><legend>'.$this->l('Settings').'</legend>

<p>'.$this->l('In order to add products to your homepage, just add them to the "home" category.').'</p><br />

<label>'.$this->l('Number of products displayed').'</label>

<div class="margin-form">

<input type="text" size="5" name="nbr" value="'.Tools::safeOutput(Tools::getValue('nbr', (int)(Configuration::get('HOME_FEATURED_NBR')))).'" />

<p class="clear">'.$this->l('The number of products displayed on homepage (default: 10).').'</p>



</div>

<center><input type="submit" name="submitAddHomeFeatured" value="'.$this->l('Save').'" class="button" /></center>

</fieldset>

</form>';

return $output;

}

function hookHeader($params)

{

$this->context->controller->addCSS($this->_path.'css/addhomefeatured.css');

}



public function hookDisplayHome($params)

{

$category = new Category(Context::getContext()->shop->getCategory(), Configuration::get('PS_LANG_DEFAULT'));

$nb = (int)(Configuration::get('HOME_FEATURED_NBR'));





$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true);

$p=array();

for($i=0;$i<count($products);$i++){

$product=$products[$i];

unset ($pid);

$pid=$product['id_product'];

$sql= "SELECT * FROM `"._DB_PREFIX_."image` WHERE `id_product` = '{$pid}' AND cover = '0' ORDER BY `id_image` ";

$results = Db::getInstance()->ExecuteS($sql);

@$result=$results['0'];

$p[$pid]=$result['id_image'];

}

$this->smarty->assign('addimages',$p);



$this->smarty->assign(array(

'products' => $products,

'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),

'homeSize' => Image::getSize('home'),

));



return $this->display(__FILE__, 'addhomefeatured.tpl');

}

}




Link to comment
Share on other sites

Can I have random products (12) but from all "home" products?

 

I use the default theme of Presta 1.6.0.6!

what files must change? and what code? (I dont find the above codes at my homefeatured.php) :(

My "Homefeatured.php" is different from other people here.

 

and how i disable the caching for this module?

 

thanks a lot for the help

Edited by iGiorgis (see edit history)
Link to comment
Share on other sites

This code works perfectly on 1.6.0.6

Many thanks to Vekia and cicciotargatona.

 

public function hookDisplayHome($params)
{
 
$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
$nb = (int)Configuration::get('HOME_FEATURED_NBR');
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true,($nb ? $nb :  8));
 
$this->smarty->assign(array(
'products' => $products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
));
 
return $this->display(__FILE__, 'homefeatured.tpl');}
  • Like 3
Link to comment
Share on other sites

  • 3 weeks later...

 

This code works perfectly on 1.6.0.6

Many thanks to Vekia and cicciotargatona.

 

public function hookDisplayHome($params)
{
 
$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
$nb = (int)Configuration::get('HOME_FEATURED_NBR');
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true,($nb ? $nb :  8));
 
$this->smarty->assign(array(
'products' => $products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
));
 
return $this->display(__FILE__, 'homefeatured.tpl');}

 

I was also wondering - If I want to display ALL products randomly as they are being added onto the site, can I use this code, what should I change in it... can any one help answer?

Link to comment
Share on other sites

http://www.prestashop.com/forums/topic/336602-how-to-display-random-products/

Here's the separate thread for that matter. I think we have to try some admin functions for that as there isn't any for loading all products in front end. AdminProductsController loads list of all products. We just need to separate products according to display configuration (throw out disabled, out of stock - if shop doesn't allow buying , etc) and generate small list out of it. Easy to say, hard to make :)

Link to comment
Share on other sites

  • 3 months later...

i tried many solutions but nothing worked, here is my code if someone could help me

public function hookDisplayHome($params)
	{
		if (!$this->isCached('homefeatured_mod.tpl', $this->getCacheId('homefeatured_mod')))
		{
			$category = new Category(Context::getContext()->shop->getCategory(), Configuration::get('PS_LANG_DEFAULT'));
			$nb = (int)(Configuration::get('HOME_FEATURED_NBR'));
			$products = $category->getProducts($params['cookie']->id_lang, 1, ($nb ? $nb : 10));

			if(method_exists('Product','getProductsImgs'))
			{
			$image_array=array();
			for($i=0;$i<count($products);$i++)
			{
				if(isset($products[$i]['id_product']))
					$image_array[$products[$i]['id_product']]= Product::getProductsImgs($products[$i]['id_product']);				
			}
		
			
			$this->smarty->assign('productimg',(isset($image_array) AND $image_array) ? $image_array : NULL);
}
			$this->smarty->assign(array(
				'products' => $products,
				'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
				'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
				));

		}
		return $this->display(__FILE__, 'homefeatured_mod.tpl', $this->getCacheId('homefeatured_mod'));

	}

	public function hookAddProduct($params)
	{
		$this->_clearCache('homefeatured_mod.tpl');
	}
Link to comment
Share on other sites

  • 6 months later...

 

This code works perfectly on 1.6.0.6

Many thanks to Vekia and cicciotargatona.

 

public function hookDisplayHome($params)
{
 
$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
$nb = (int)Configuration::get('HOME_FEATURED_NBR');
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position",null,false,true,true,($nb ? $nb :  8));
 
$this->smarty->assign(array(
'products' => $products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
));
 
return $this->display(__FILE__, 'homefeatured.tpl');}

 

works on PS 1.6.0.8

thanks!!

Edited by cycleelcyc (see edit history)
Link to comment
Share on other sites

  • 3 months later...

Any body can help me please, i'm trying all post but i can't do it :((

 

My prestashop 1.5.6.2

 

My homefeatured.php code:

 

 

<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Academic Free License (AFL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to [email protected] so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
*  @author PrestaShop SA <[email protected]>
*  @copyright  2007-2013 PrestaShop SA
*  @license    http://opensource.or...ses/afl-3.0.php  Academic Free License (AFL 3.0)
*  International Registered Trademark & Property of PrestaShop SA
*/
 
if (!defined('_PS_VERSION_'))
exit;
class HomeFeatured extends Module
{
private $_html = '';
private $_postErrors = array();
 
function __construct()
{
$this->name = 'homefeatured';
$this->tab = 'front_office_features';
$this->version = '1.1';
$this->author = 'PrestaShop';
$this->need_instance = 0;
 
parent::__construct();
 
$this->displayName = $this->l('Featured products on the homepage.');
$this->description = $this->l('Displays featured products in the middle of your homepage.');
}
 
function install()
{
$this->_clearCache('homefeatured.tpl');
Configuration::updateValue('HOME_FEATURED_NBR', 8);
if (!parent::install()
|| !$this->registerHook('displayHome')
|| !$this->registerHook('header')
|| !$this->registerHook('addproduct')
|| !$this->registerHook('updateproduct')
|| !$this->registerHook('deleteproduct')
)
return false;
return true;
}
 
public function uninstall()
{
$this->_clearCache('homefeatured.tpl');
return parent::uninstall();
}
 
public function getContent()
{
$output = '<h2>'.$this->displayName.'</h2>';
if (Tools::isSubmit('submitHomeFeatured'))
{
$nbr = (int)Tools::getValue('nbr');
if (!$nbr OR $nbr <= 0 OR !Validate::isInt($nbr))
$errors[] = $this->l('An invalid number of products has been specified.');
else
Configuration::updateValue('HOME_FEATURED_NBR', (int)($nbr));
if (isset($errors) AND sizeof($errors))
$output .= $this->displayError(implode('<br />', $errors));
else
$output .= $this->displayConfirmation($this->l('Your settings have been updated.'));
}
return $output.$this->displayForm();
}
 
public function displayForm()
{
$output = '
<form action="'.Tools::safeOutput($_SERVER['REQUEST_URI']).'" method="post">
<fieldset><legend><img src="'.$this->_path.'logo.gif" alt="" title="" />'.$this->l('Settings').'</legend>
<p>'.$this->l('To add products to your homepage, simply add them to the "home" category.').'</p><br />
<label>'.$this->l('Define the number of products to be displayed.').'</label>
<div class="margin-form">
<input type="text" size="5" name="nbr" value="'.Tools::safeOutput(Tools::getValue('nbr', (int)(Configuration::get('HOME_FEATURED_NBR')))).'" />
<p class="clear">'.$this->l('Define the number of products that you would like to display on homepage (default: 8).').'</p>
</div>
<center><input type="submit" name="submitHomeFeatured" value="'.$this->l('Save').'" class="button" /></center>
</fieldset>
</form>';
return $output;
}
 
public function hookDisplayHeader($params)
{
$this->hookHeader($params);
}
public function hookHeader($params)
{
$this->context->controller->addCSS(($this->_path).'homefeatured.css', 'all');
}
 
public function hookDisplayHome($params)
{
if (!$this->isCached('homefeatured.tpl', $this->getCacheId('homefeatured')))
{
$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
$nb = (int)Configuration::get('HOME_FEATURED_NBR');
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), "position");
 
$this->smarty->assign(array(
'products' => $products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
));
}
return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId('homefeatured'));
}
 
public function hookAddProduct($params)
{
$this->_clearCache('homefeatured.tpl');
}
public function hookUpdateProduct($params)
{
$this->_clearCache('homefeatured.tpl');
}
 
public function hookDeleteProduct($params)
{
$this->_clearCache('homefeatured.tpl');
}

Link to comment
Share on other sites

  • 7 months later...

Hi All

 

The code:

--

public function hookDisplayHome($params){
$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
$nb = (int)(Configuration::get('HOME_FEATURED_NBR'));
/*$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10));*/
$products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10), 'date_add', 'DESC', false, true, true, $nb);

shuffle($products);
$this->smarty->assign(array(
'products' => $products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize('home_default'),
));
return $this->display(__FILE__, 'homefeatured.tpl');
}

--

is not showing my items in random. Please help.. www.fashiondrobe.in

Regards

Jasbir Singh

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...

Hi...

 

I think better just use the function "transplant a modules".

 

---> Modules & Services --> positions

 

Select module "Featured products on the homepage", then transplant to where you want to display. (displayHomeTabContent)

 

 

After that, go to module "Featured products on the homepage"

--> Modules & Services --> Modules & Services --> Featured products on the homepage

Setting here whatever the product you want to display.

 

 

presta ver - 1.6.15

Edited by sebayutekstil (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...