Jump to content

Featured products on the homepage v1.6.4 - Random


Recommended Posts

PrestaShop 1.6.0.9

 

Hi all,

 

I am using this module to display popular products on the homepage..I have two issues;

 

1 - The randomise feature only works if you disable all SMARTY caching. This doesnt make any sense to me, if the randomise option is selected it should ignore the cache because every query should bring up a new set of products.

 

2 - This is probably due to my lack of understanding of how the categories work...it always confuses me, but the default 2 in the category box brings up no products but if I enter the ID of one of my existing categories all is well.

 

According to the category edit page there is no available HOME cateogry (there was previous to me adding categories) but when I edit a main category it displays as being underneath the home category.

 

Very confused =)

 

Thanks for any help

Rolf

post-881080-0-76665400-1430499961_thumb.png

post-881080-0-87356300-1430499962_thumb.png

Link to comment
Share on other sites

The Home category, is the start category for your shop.

To edit the Home category (for example, if you would like to rename 'Home' or so), click on the little edit icon on the right (see image)

post-455771-0-92956100-1430579537_thumb.png

post-455771-0-95462400-1430579560_thumb.png

 

The categories on the start page when editing categories, are the children of the home category, which in turn can have their own children etc. All these categories you will make yourself.

 

 

About the cache:

Random showing the products indeed doesn't seem to work with cache on. The problem is, that getting the products is time consuming (quite a complex SQL statement, which needs to go through many table, SQL functions are called inside the statement etc), which, if you have many products, may slow down the page loading dramaticaly. Therefore they opted to use the caching here, I think.

 

If you can live with the slower loading, you may try this (Didn't test it myself, but give it a try)

 

in file:

modules/homefeatured/homefeatured.php   (Make backup!!)

 

There is a function: (Sample from SP 1.6.0.14)

 

public function _cacheProducts()
{
  if (!isset(HomeFeatured::$cache_products)|| Configuration::get('HOME_FEATURED_RANDOMIZE'))
  {
    $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;
}
 

 

Add the red code, and see if that helps. Let me know.

 

pascal.

 

 

P.S. If this works, we will need to do something similar in other modules, like blocknewproducts, blockspecials.

Maybe see if you can find tis yourself here. If not, let me know and I will see what I can do.

Edited by PascalVG (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...