Jump to content

Need help with Home Featured Products (Randomly).....


MrWade

Recommended Posts

Yes, I am using the Classic Core Theme version 8..1.7 I have about 24 products on featured and also on the main root. My question is it shows 24 on the main root display 8 on the main page. Every time I refresh the page it doesn't randomly changes products. How can I fix this?

  • Like 1
Link to comment
Share on other sites

1 hour ago, Daresh said:

It is like that because of caching. A workaround is to send all 24 products to the template, then shuffle them and cut to 8. It requires some changes to the TPL file.

Where is the file and what is the code??

Link to comment
Share on other sites

5 hours ago, Knowband Plugins said:

I hope you are using the default featured products module of the Pretashop.

Have you enabled the "Randomly display featured products" in the featured module?

image.thumb.png.4f7a09de1aff08a5750c5a21c0749553.png

  

It's already like that. It's not randomly or shuffling the products.

Link to comment
Share on other sites

27 minutes ago, Knowband Plugins said:

Ideally, it should not. 

In that case, there can be the following possibilities 

1. Cache issue

2. The selected category does not have enough products

3. Home page use the other module instead of this feature module? 

Do you have the site URL to share ?

Yes, its:

https://www.galaxyhomedecor.us

Link to comment
Share on other sites

Like I said before, it's cache. But not any issue but this module simply works this way. The randomization occurs when the module content gets generated, but before it's cached. So by default, you will never have a random effect on every page refresh with this module, just on every cache refresh.

Link to comment
Share on other sites

1 hour ago, Daresh said:

Like I said before, it's cache. But not any issue but this module simply works this way. The randomization occurs when the module content gets generated, but before it's cached. So by default, you will never have a random effect on every page refresh with this module, just on every cache refresh.

Well, the cache is enable in the back office. Then I clear the cache on my browsers. Still no change. Here is the setting in the back office for caching.

Screen Shot 2025-02-22 at 12.52.35 PM.png

Link to comment
Share on other sites

Hi.

Somehow I do not understand:

Quote

My question is that it shows 24 in the main root display 8 in the main page.

Do you have two modules?

Maybe editing the module and inserting the PHP function shuffle($products) will help

Link to comment
Share on other sites

4 minutes ago, ps8modules said:

Hi.

Somehow I do not understand:

Do you have two modules?

Maybe editing the module and inserting the PHP function shuffle($products) will help

Actually, I am using just one module and its the Featured Products for the main page.

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

You need to check the database in the ps_configuration table what the value for 'HOME_FEATURED_RANDOMIZE' is.

SELECT a.value FROM ps_configuration a WHERE a.name = 'HOME_FEATURED_RANDOMIZE'; 

The value should be 1.

 

The module is probably not enabled at the moment. It is not visible on the main page.

 

Or you can edit the module and insert the shuffle function:
./modules/ps_featuredproducts/ps_featuredproducts.php

obrazek.thumb.png.cb7e72021a305d5e837ced0fb5af8f91.png

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

19 minutes ago, ps8modules said:

You need to check the database in the ps_configuration table what the value for 'HOME_FEATURED_RANDOMIZE' is.

SELECT a.value FROM ps_configuration a WHERE a.name = 'HOME_FEATURED_RANDOMIZE'; 

The value should be 1.

 

The module is probably not enabled at the moment. It is not visible on the main page.

 

Or you can edit the module and insert the shuffle function:
./modules/ps_featuredproducts/ps_featuredproducts.php

obrazek.thumb.png.cb7e72021a305d5e837ced0fb5af8f91.png

Well adding that shuffle didn't work. It show one image with no image at all. So I had to remove the shuffle code.

Link to comment
Share on other sites

If you really need to have it random on each page load, you may try to disable cache use in the module:

    public function renderWidget($hookName = null, array $configuration = [])
    {
        //if (!$this->isCached($this->templateFile, $this->getCacheId('ps_featuredproducts'))) {
            $variables = $this->getWidgetVariables($hookName, $configuration);

            if (empty($variables)) {
                return false;
            }

            $this->smarty->assign($variables);
        //}

        return $this->fetch($this->templateFile);
        //return $this->fetch($this->templateFile, $this->getCacheId('ps_featuredproducts'));
    }

 

  • Like 1
Link to comment
Share on other sites

5 hours ago, Daresh said:

If you really need to have it random on each page load, you may try to disable cache use in the module:

    public function renderWidget($hookName = null, array $configuration = [])
    {
        //if (!$this->isCached($this->templateFile, $this->getCacheId('ps_featuredproducts'))) {
            $variables = $this->getWidgetVariables($hookName, $configuration);

            if (empty($variables)) {
                return false;
            }

            $this->smarty->assign($variables);
        //}

        return $this->fetch($this->templateFile);
        //return $this->fetch($this->templateFile, $this->getCacheId('ps_featuredproducts'));
    }

Sorry, I just tried that. It didn't work. It removed the module from the main page.

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

The problem will be elsewhere. As soon as he returned the code of the module, everything changed on the main page and after a while it stopped. So now the question is, does it happen to have some extra cache module installed, or does the web hosting have its own cache.

It's easy to write that it doesn't work, but we can't see if you've edited the function correctly. We don't see how the module is set.

 

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

The store looks quite simple with the Classic theme used. And the "Featured products" module never displays random products on each page refresh if smarty cache is enabled. So I would still follow this path.

Link to comment
Share on other sites

2 minutes ago, Daresh said:

The store looks quite simple with the Classic theme used. And the "Featured products" module never displays random products on each page refresh if smarty cache is enabled. So I would still follow this path.

How can I make it work.

Link to comment
Share on other sites

47 minutes ago, Daresh said:

Did you replace the function with the one that I sent? What is the version of your module?

My version is v2.1.5 and yes I did try your code and disable the cache I got a blank featured module. When I went back to the original code the module is back on the screen.

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

19 hours ago, ps8modules said:

You need to check the database in the ps_configuration table what the value for 'HOME_FEATURED_RANDOMIZE' is.

SELECT a.value FROM ps_configuration a WHERE a.name = 'HOME_FEATURED_RANDOMIZE'; 

The value should be 1.

 

The module is probably not enabled at the moment. It is not visible on the main page.

 

Or you can edit the module and insert the shuffle function:
./modules/ps_featuredproducts/ps_featuredproducts.php

obrazek.thumb.png.cb7e72021a305d5e837ced0fb5af8f91.png

I don't see the HOME_FEATURED_RANDOMIZE in the ps_configuration in MySQL.

Link to comment
Share on other sites

1 minute ago, ps8modules said:

We are interested in whether the settings in the module are saved. If the setting is saved, the value must be written to ps_configuration. If it doesn't register, it can't display randomly.

According to my end (Back office) its show that is saved in module itself.

Link to comment
Share on other sites

3 minutes ago, ps8modules said:

If you don't do what we ask you to do here, we can't help. There is printScr (print screen) on the keyboard, when you give us a picture of the ps_homefeatured module settings.

 

Screenshot 2025-02-23 at 11.00.08 PM.png

Link to comment
Share on other sites

23 minutes ago, ps8modules said:

Please go to the module settings page in the e-shop administration.

Modules -> Module Manager -> Featured products (Configure)

Here is my settings for the Featured Products Module.

Screenshot 2025-02-23 at 11.38.50 PM.png

Link to comment
Share on other sites

Change the renderWidget Function & Use the below code. 

 

public function renderWidget($hookName = null, array $configuration = [])
    {
        //if (!$this->isCached($this->templateFile, $this->getCacheId('ps_featuredproducts'))) {
            $variables = $this->getWidgetVariables($hookName, $configuration);

            if (empty($variables)) {
                return false;
            }

            $this->smarty->assign($variables);
        //}

        return $this->fetch($this->templateFile);
    }

 

Link to comment
Share on other sites

https://help-center.prestashop.com/hc/en-us/articles/18898613995026-Customize-your-site-s-CSS

./themes/classic/assets/css/custom.css

@media (max-width:499px) {
    .page-index .product,
    .page-search .product {
        width: 100% !important;
        min-width: 250px
    }

    .page-index .product-miniature .thumbnail-container,
    .page-search .product-miniature .thumbnail-container {
        width: 100% !important;
    }
}

 

Edited by ps8modules
updated CSS (see edit history)
Link to comment
Share on other sites

8 hours ago, ps8modules said:

https://help-center.prestashop.com/hc/en-us/articles/18898613995026-Customize-your-site-s-CSS

./themes/classic/assets/css/custom.css

@media (max-width:499px) {
    .page-index .product-miniature .product,
    .page-search .product-miniature .product {
        width: 100%;
        min-width: 250px
    }

    .page-index .product-miniature .thumbnail-container,
    .page-search .product-miniature .thumbnail-container {
        width: 100% !important;
    }
}

custom.css 338 B · 0 downloads

Ok, no change.

Link to comment
Share on other sites

6 minutes ago, ps8modules said:

And again, we don't know if you uploaded everything correctly and to the right folder on FTP. 

And we don't know if you used the magic button in the performance settings "Clear cache".

I did all that and yes it is in the right folder.

Link to comment
Share on other sites

@media (max-width:499px) {
  .page-index .product,
  .page-search .product {
      width: 100%;
      min-width: 250px;
  }

  .page-index .product-miniature .thumbnail-container,
  .page-search .product-miniature .thumbnail-container {
      width: 100% !important;
  }
}

image.png.5d0029c76e4336421d798767216f1331.png

 

The problem is that you are editing the styles directly in theme.css. You can tell by the fact that your css is decompressed.

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

5 minutes ago, ps8modules said:
@media (max-width:499px) {
  .page-index .product,
  .page-search .product {
      width: 100%;
      min-width: 250px;
  }

  .page-index .product-miniature .thumbnail-container,
  .page-search .product-miniature .thumbnail-container {
      width: 100% !important;
  }
}

 

That did it, Thank you.

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...