Jump to content
St055

Random home featured in v1.6

Recommended Posts

Hello,

 

How to have the featured product dispolayed randomly on home?... Ive opened homefeatured.php but all is in cache, I don't know how to do that... Any idea please?

Share this post


Link to post
Share on other sites

on homefeutured.php about row 113 you will find something like this

HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position');

Coment this text and paste this

 

HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, 100, 'position');
      if (HomeFeatured::$cache_products) {
        shuffle(HomeFeatured::$cache_products);
        array_splice(HomeFeatured::$cache_products, ($nb ? $nb : 8));
  • Like 2

Share this post


Link to post
Share on other sites

Thanks! But sorry, doesn't work... The products are still the same, and same order... :-(

Share this post


Link to post
Share on other sites

Hi 

 

Change that:

 

domain/module/homefeatured/homefeatured.php

 

 

-----------------------------------------

 

 

OLD:

 

 

public function hookDisplayHome($params)
{
if (!$this->isCached('homefeatured.tpl', $this->getCacheId()))
{
$this->_cacheProducts();
$this->smarty->assign(
array(
'products' => HomeFeatured::$cache_products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
)
);
}


return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId());
}
 
 
 
 
 
 
----------------------------------------------------------------------------------------------
 
NEW:
 
 
 
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');
}

--------------------------------------------

 

 

:)

Edited by Daniel - PrestaBR (see edit history)
  • Like 8

Share this post


Link to post
Share on other sites

everything is because of caching. this module uses caching so it will show new products ( by new i mean randomly) only with force compile and without cache.

this is why it's necessary to remove caching functions :)

  • Like 1

Share this post


Link to post
Share on other sites

use this:

$category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position',null,false,true,true);
  • Like 1

Share this post


Link to post
Share on other sites

 

use this:

$category->getProducts((int)Context::getcontext()->language->id, 1, ($nb ? $nb : 8), 'position',null,false,true,true);

Thanks Vekia, I will try this as soon as I am on my PC. Should I edit stock homefeatured.php or this edited one?

 

Regards,

 

Vedran

Share this post


Link to post
Share on other sites

you can edit actual file that you already changed

Share this post


Link to post
Share on other sites

Hi Vekia, 

Thanks for you reply.

I just replaced the following line in my edited homefeatured.php

$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);

With yours

 

$category->getProducts((int)Context::getcontext()->language->id, 1, ($nb ? $nb : 8), 'position',null,false,true,true);

 

But then I get following error:

Notice: Undefined variable: category in /home5/hejkupim/public_html/test/modules/homefeatured/homefeatured.php on line 129

Fatal error: Call to a member function getProducts() on a non-object in /home5/hejkupim/public_html/test/modules/homefeatured/homefeatured.php on line 129
 
This is my edited code:
public function hookDisplayHome($params){
$category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position',null,false,true,true);$nb = (int)(Configuration::get('HOME_FEATURED_NBR'));
/*$products = $category->getProducts((int)Context::getContext()->language->id, 7, ($nb ? $nb : 10));*/
$products = $category->getProducts((int)Context::getContext()->language->id, 7, ($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');
}
What am I doing wrong, did I edited the right line?
 
 
Thanks in advance.

Regards,

Vedran

Share this post


Link to post
Share on other sites

you have to use code that i suggested instead of:

$products = $category->getProducts((int)Context::getContext()->language->id, 7, ($nb ? $nb : 10), 'date_add', 'DESC', false, true, true, $nb);

Share this post


Link to post
Share on other sites

 

you have to use code that i suggested instead of:

$products = $category->getProducts((int)Context::getContext()->language->id, 7, ($nb ? $nb : 10), 'date_add', 'DESC', false, true, true, $nb);

Hi Vekia,

 

I just did that, but same 10-15 products are randomly displayed when refreshed (I have more than 15 products in my home category). I Also have this modification on my live 1.5 site which is working great.

 

Edit:

 

Actually, I got an following error:

 

Warning: shuffle() expects parameter 1 to be array, null given in /home5/hejkupim/public_html/test/modules/homefeatured/homefeatured.php on line 134

And no homefeaured products, just this message: No featured products at this time.

 

Here is my 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));*/
$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('home_default'),
));
return $this->display(__FILE__, 'homefeatured.tpl');
}

My test site: http://hejkupi.me/test

Regards,

 

Vedran

Edited by vmarkovic (see edit history)

Share this post


Link to post
Share on other sites

works great for me. but sometimes displays items out of stock, theres any way to sort just with products in stock ?

 

 

www.bostonrecycling.net

Share this post


Link to post
Share on other sites
$category->getProducts((int)Context::getcontext()->language->id, 1, ($nb ? $nb : 8), 'position',null,false,true,true);

to

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

Share this post


Link to post
Share on other sites

sorry for misunderstanding but my post was to vmarkovic.

in your case it's necessary to modify core function getProducts, but in this case it will affect also other part of shop where the product listings are visible

Share this post


Link to post
Share on other sites

i try the code from mendi_xtv but i lose the ribbons :(

 

I want to show randomly all my "home" products but to show 8 or 12 at home page!

 

how i do that?

Edited by iGiorgis (see edit history)

Share this post


Link to post
Share on other sites

I think a " } " was missed and that's why is not working...i put at the end of the line the  } and works for my 

HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, 100, 'position');
 if (HomeFeatured::$cache_products) {
	shuffle(HomeFeatured::$cache_products);
	array_splice(HomeFeatured::$cache_products, ($nb ? $nb : 8));
}

Look the code, there is an if.

Then Clean the Cache from the store, and it's work!,

Share this post


Link to post
Share on other sites

The changes only randomise the same 20 products for my store, i want to be able to get a total random selection of products not just move around the same products. 

 

www.w2g.co.uk 

 

thanks in advance for any help

 

lots of posts are confusing does anyone have simpled down version for a total random selection of products from you entire inventory? 

Edited by mike117 (see edit history)

Share this post


Link to post
Share on other sites

Just change this function:

 

public function hookDisplayHome($params)
{
if (!$this->isCached('homefeatured.tpl', $this->getCacheId()))
{
$this->_cacheProducts();
$this->smarty->assign(
array(
'products' => HomeFeatured::$cache_products,
'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
)
);
}
return $this->display(__FILE__, 'homefeatured.tpl', $this->getCacheId());
}

 

for this 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');
}

 

 

Replace the whole function, and it works.

Share this post


Link to post
Share on other sites

Thanks but, two days ago works perfectly, but now not works... I replace again but is the same....

Hi,

 

Did you updated Top sellers module in those 2 days?

 

Regards,

 

Vedran

Edited by vmarkovic (see edit history)

Share this post


Link to post
Share on other sites

Hi webonmaster,

You have to edit /public_html/modules/homefeatured/homefeatured.php.

Replace this part:

public function hookDisplayHome($params)
	{
		if (!$this->isCached('homefeatured.tpl', $this->getCacheId()))
		{
			$this->_cacheProducts();
			$this->smarty->assign(
				array(
					'products' => HomeFeatured::$cache_products,
					'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
					'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
				)
			);
		}

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

with this one:

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');
}

I just tried this on my 1.6.0.9 - it works.

Regards, 

Vedran

  • Like 1

Share this post


Link to post
Share on other sites
 
thanks vmarkovic I have that part solved with the same code.
the one I need is for thumbnails 30 other products in the same category.
Also many thanks and sorry for my English.

Share this post


Link to post
Share on other sites

Hi webonmaster,

 

 

Sorry didnt catched that. Interesting question though, would like to know that myself.

 

Regards,

 

Vedran

Share this post


Link to post
Share on other sites

It works.
is possible via a query to show only the products in stock ?

Share this post


Link to post
Share on other sites

Hi Verdan,

I try your edit but it works only if I switch between New arrivals and Popular. But I have Popular on 1st switch and New arrivals on 2nd switch on my homepage. When I come to my website I can see on both switches (Popular and New arrivals) the same products. Your edit take effect after I switch Popular -> News and back to Popular and take effect only once. I have to refresh my website, switch Popular -> New arrivals and back and after this product random. Do I something wrong?

Thanks for help.

jirikcz

 

Hi webonmaster,

You have to edit /public_html/modules/homefeatured/homefeatured.php.

Replace this part:

public function hookDisplayHome($params)
	{
		if (!$this->isCached('homefeatured.tpl', $this->getCacheId()))
		{
			$this->_cacheProducts();
			$this->smarty->assign(
				array(
					'products' => HomeFeatured::$cache_products,
					'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
					'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
				)
			);
		}

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

with this one:

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');
}

I just tried this on my 1.6.0.9 - it works.

Regards, 

Vedran

Edited by jirikcz (see edit history)

Share this post


Link to post
Share on other sites

Hi Verdan,

I try your edit but it works only if I switch between New arrivals and Popular. But I have Popular on 1st switch and New arrivals on 2nd switch on my homepage. When I come to my website I can see on both switches (Popular and New arrivals) the same products. Your edit take effect after I switch Popular -> News and back to Popular and take effect only once. I have to refresh my website, switch Popular -> New arrivals and back and after this product random. You can see it on my website at http://76345.w45.wedos.ws/en/ . Do I something wrong?

Thanks for help.

jirikcz

Hi jirikcz,

 

I just copy/pasted code and instructions from this topic so I am not sure are you doing something wrong.

 

Regards,

 

Vedrav

Share this post


Link to post
Share on other sites

I'm using with success mendi_xtv, but I have a question, It's possible to show random product taken from all products at catalog instead on only products assigned to home category?

Edited by DARKF3D3 (see edit history)
  • Like 1

Share this post


Link to post
Share on other sites

I'm using with success mendi_xtv, but I have a question, It's possible to show random product taken from all products at catalog instead on only products assigned to home category?

 

No one know I can do that?

Share this post


Link to post
Share on other sites

Hi DARF3D3

 

You have to change ".../modules/homefeatured/homefeatured.php"

 

at line 107

replace this:

	public function _cacheProducts()
	{
		if (!isset(HomeFeatured::$cache_products))
		{
			$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
			$nb = (int)Configuration::get('HOME_FEATURED_NBR');
			HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position');
		}

		if (HomeFeatured::$cache_products === false || empty(HomeFeatured::$cache_products))
			return false;
	}

with this:

	public function _cacheProducts()
	{
		if (!isset(HomeFeatured::$cache_products))
		{
			$category = new Category(Context::getContext()->shop->getCategory(), (int)Context::getContext()->language->id);
			$nb = (int)Configuration::get('HOME_FEATURED_NBR');
			/*HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position');*/
			HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 10), NULL,NULL,false,true,true,($nb ? $nb : 100));
		}

		if (HomeFeatured::$cache_products === false || empty(HomeFeatured::$cache_products))
			return false;
	}

Regards,

 

prestatuga

 

  • Like 1

Share this post


Link to post
Share on other sites

Hi prestatuga,

I copied your code into the homefeatured.php file but to me the products showed seem to be the same as before, I countinue seeing only products assigned to home category.

Share this post


Link to post
Share on other sites

Hi DARF3D3

 

Sorry for my mistake and the incomplete information.
In my shop I added all products to the home category besides having its own main category.
In this store have less than 100 items. If necessary, you can increase the number of random items.
This is not the most elegant solution, but it was the only one that got it working.
I do not have many products and in my case it was easy. In a very large store will be painful to edit all items.

 

best regards,

Prestatuga

Share this post


Link to post
Share on other sites

Ok now it's clear, thanks Prestatuga.

Infact I was looking for something that can show random products also in not assigned to home category because I have a large amount of products at catalogue.

Share this post


Link to post
Share on other sites

Hi Jhonny, what do you mean with your phrase? I'm sorry but m English it's not the best.

Share this post


Link to post
Share on other sites

Hi Jhonny, what do you mean with your phrase? I'm sorry but m English it's not the best.

 

The new version of the module, including the random option.

 

(La nueva versión del módulo, incluye la opción "aleatorios").

 

My English is very bad, sorry.  :D

Share this post


Link to post
Share on other sites

Do you know the version number? Mine it's the 1.5 and i don't see the random option and PS doesn't show the message of new update available.

Share this post


Link to post
Share on other sites

Do you know the version number? Mine it's the 1.5 and i don't see the random option and PS doesn't show the message of new update available.

 

The new version is available in ps1.6

Share this post


Link to post
Share on other sites

Yes I have PS1.6 and the last version of the module i find is the 1.5 but i don't see the random product feature.

Share this post


Link to post
Share on other sites

can someone please update the new hole homefeatured.php file, for just replace it

 

thanks

Share this post


Link to post
Share on other sites

can someone please update the new hole homefeatured.php file, for just replace it

 

thanks


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

class HomeFeatured extends Module
{
	protected static $cache_products;

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

		$this->bootstrap = true;
		parent::__construct();

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

	public function install()
	{
		$this->_clearCache('*');
		Configuration::updateValue('HOME_FEATURED_NBR', 8);
		Configuration::updateValue('HOME_FEATURED_CAT', (int)Context::getContext()->shop->getCategory());
		Configuration::updateValue('HOME_FEATURED_RANDOMIZE', false);

		if (!parent::install()
			|| !$this->registerHook('header')
			|| !$this->registerHook('addproduct')
			|| !$this->registerHook('updateproduct')
			|| !$this->registerHook('deleteproduct')
			|| !$this->registerHook('categoryUpdate')
			|| !$this->registerHook('displayHomeTab')
			|| !$this->registerHook('displayHomeTabContent')
		)
			return false;

		return true;
	}

	public function uninstall()
	{
		$this->_clearCache('*');

		return parent::uninstall();
	}

	public function getContent()
	{
		$output = '';
		$errors = array();
		if (Tools::isSubmit('submitHomeFeatured'))
		{
			$nbr = Tools::getValue('HOME_FEATURED_NBR');
			if (!Validate::isInt($nbr) || $nbr <= 0)
			$errors[] = $this->l('The number of products is invalid. Please enter a positive number.');

			$cat = Tools::getValue('HOME_FEATURED_CAT');
			if (!Validate::isInt($cat) || $cat <= 0)
				$errors[] = $this->l('The category ID is invalid. Please choose an existing category ID.');
				
			$rand = Tools::getValue('HOME_FEATURED_RANDOMIZE');
			if (!Validate::isBool($rand))
				$errors[] = $this->l('Invalid value for the "randomize" flag.');
			if (isset($errors) && count($errors))
				$output = $this->displayError(implode('<br />', $errors));
			else
			{
				Configuration::updateValue('HOME_FEATURED_NBR', (int)$nbr);
				Configuration::updateValue('HOME_FEATURED_CAT', (int)$cat);
				Configuration::updateValue('HOME_FEATURED_RANDOMIZE', (bool)$rand);
				Tools::clearCache(Context::getContext()->smarty, $this->getTemplatePath('homefeatured.tpl'));
				$output = $this->displayConfirmation($this->l('Your settings have been updated.'));
			}
		}

		return $output.$this->renderForm();
	}

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

	public function hookHeader($params)
	{
		if (isset($this->context->controller->php_self) && $this->context->controller->php_self == 'index')
			$this->context->controller->addCSS(_THEME_CSS_DIR_.'product_list.css');
		$this->context->controller->addCSS(($this->_path).'homefeatured.css', 'all');
	}

	public function _cacheProducts()
	{
		if (!isset(HomeFeatured::$cache_products))
		{
			$category = new Category((int)Configuration::get('HOME_FEATURED_CAT'), (int)Context::getContext()->language->id);
			$nb = (int)Configuration::get('HOME_FEATURED_NBR');
			if (Configuration::get('HOME_FEATURED_RANDOMIZE'))
				HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), null, null, false, true, true, ($nb ? $nb : 8));
			else
				HomeFeatured::$cache_products = $category->getProducts((int)Context::getContext()->language->id, 1, ($nb ? $nb : 8), 'position');
		}

		if (HomeFeatured::$cache_products === false || empty(HomeFeatured::$cache_products))
			return false;
	}

	public function hookDisplayHomeTab($params)
	{
		if (!$this->isCached('tab.tpl', $this->getCacheId('homefeatured-tab')))
			$this->_cacheProducts();

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

	public function hookDisplayHome($params)
	{
		if (!$this->isCached('homefeatured.tpl', $this->getCacheId()))
		{
			$this->_cacheProducts();
			$this->smarty->assign(
				array(
					'products' => HomeFeatured::$cache_products,
					'add_prod_display' => Configuration::get('PS_ATTRIBUTE_CATEGORY_DISPLAY'),
					'homeSize' => Image::getSize(ImageType::getFormatedName('home')),
				)
			);
		}

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

	public function hookDisplayHomeTabContent($params)
	{
		return $this->hookDisplayHome($params);
	}

	public function hookAddProduct($params)
	{
		$this->_clearCache('*');
	}

	public function hookUpdateProduct($params)
	{
		$this->_clearCache('*');
	}

	public function hookDeleteProduct($params)
	{
		$this->_clearCache('*');
	}

	public function hookCategoryUpdate($params)
	{
		$this->_clearCache('*');
	}

	public function _clearCache($template, $cache_id = NULL, $compile_id = NULL)
	{
		parent::_clearCache('homefeatured.tpl');
		parent::_clearCache('tab.tpl', 'homefeatured-tab');
	}

	public function renderForm()
	{
		$fields_form = array(
			'form' => array(
				'legend' => array(
					'title' => $this->l('Settings'),
					'icon' => 'icon-cogs'
				),
				'description' => $this->l('To add products to your homepage, simply add them to the corresponding product category (default: "Home").'),
				'input' => array(
					array(
						'type' => 'text',
						'label' => $this->l('Number of products to be displayed'),
						'name' => 'HOME_FEATURED_NBR',
						'class' => 'fixed-width-xs',
						'desc' => $this->l('Set the number of products that you would like to display on homepage (default: 8).'),
					),
					array(
						'type' => 'text',
						'label' => $this->l('Category from which to pick products to be displayed'),
						'name' => 'HOME_FEATURED_CAT',
						'class' => 'fixed-width-xs',
						'desc' => $this->l('Choose the category ID of the products that you would like to display on homepage (default: 2 for "Home").'),
					),
					array( 
						'type' => 'switch',
						'label' => $this->l('Randomly display featured products'),
						'name' => 'HOME_FEATURED_RANDOMIZE',
						'class' => 'fixed-width-xs',
						'desc' => $this->l('Enable if you wish the products to be displayed randomly (default: no).'),
						'values' => array(
							array(
								'id' => 'active_on',
								'value' => 1,
								'label' => $this->l('Yes')
							),
							array(
								'id' => 'active_off',
								'value' => 0,
								'label' => $this->l('No')
							)
						),
					),
				),
				'submit' => array(
					'title' => $this->l('Save'),
				)
			),
		);

		$helper = new HelperForm();
		$helper->show_toolbar = false;
		$helper->table = $this->table;
		$lang = new Language((int)Configuration::get('PS_LANG_DEFAULT'));
		$helper->default_form_language = $lang->id;
		$helper->allow_employee_form_lang = Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') ? Configuration::get('PS_BO_ALLOW_EMPLOYEE_FORM_LANG') : 0;
		$this->fields_form = array();
		$helper->id = (int)Tools::getValue('id_carrier');
		$helper->identifier = $this->identifier;
		$helper->submit_action = 'submitHomeFeatured';
		$helper->currentIndex = $this->context->link->getAdminLink('AdminModules', false).'&configure='.$this->name.'&tab_module='.$this->tab.'&module_name='.$this->name;
		$helper->token = Tools::getAdminTokenLite('AdminModules');
		$helper->tpl_vars = array(
			'fields_value' => $this->getConfigFieldsValues(),
			'languages' => $this->context->controller->getLanguages(),
			'id_language' => $this->context->language->id
		);

		return $helper->generateForm(array($fields_form));
	}

	public function getConfigFieldsValues()
	{
		return array(
			'HOME_FEATURED_NBR' => Tools::getValue('HOME_FEATURED_NBR', (int)Configuration::get('HOME_FEATURED_NBR')),
			'HOME_FEATURED_CAT' => Tools::getValue('HOME_FEATURED_CAT', (int)Configuration::get('HOME_FEATURED_CAT')),
			'HOME_FEATURED_RANDOMIZE' => Tools::getValue('HOME_FEATURED_RANDOMIZE', (bool)Configuration::get('HOME_FEATURED_RANDOMIZE')),
		);
	}
}

  • Like 1

Share this post


Link to post
Share on other sites

Why was the method originally date_add then changed to position?

I am using date_add but after I saw this post using position, I'm trying to understand getProducts different orders.

 

 if ($order_by == 'id_product' || $order_by == 'price' || $order_by == 'date_add' || $order_by == 'date_upd')
                        $order_by_prefix = 'p';
                else if ($order_by == 'name')
                        $order_by_prefix = 'pl';
                else if ($order_by == 'position')
                        $order_by_prefix = 'c';
 
p, pl, and c. 
Can someone explain please?
 
TIA
Edited by zeki893 (see edit history)

Share this post


Link to post
Share on other sites

×

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More