Dynamic Module on the homepage

#1
Hello,

We have a wishlist module with two template on the homepage.

One of the template is ok (The number of product in our wishlist display in the menu. The number is not cached and changes when you add / remove a product in your wishlist)

But the button to add / remove a product in the wishlist is cached and never change.

It's called from a hook using the renderWidget function :

PHP:
public function renderWidget($hookName = null, array $params = [])
    {
        switch($hookName) {
            case 'displayNav':
                //Fetch the .tpl file to show how many product is in the wishlist with the correct information
                break;
            case 'displayAfterThumbnailProduct':
                //fetch the .tpl fil to display the add to wishlist button with different state
                break;
            default:
                //just is case
                return 'ko';
        }
    }
How it should look :

1.jpg

But the "heart button" to add on wishlist never change his state. If I click on the second product "heart button" and refresh, the heart will still being empty

How can I exclude this from being cached ?

Thank you for your help !
 

serpent_driver

Well-Known Member
#2
That could be tricky, but you can try to solve it with a new ESI block in customize tab of plugin settings. Add new ESI block and search for the module name in form select. If it exists select private and leave TTL blank.
 
#3
When I add an ESI block, the first time the hook is called the template is cached, so if the first product is in the wishlist, all the heart will be filled with the information from the first product on all the other product.

Here I have only the first product in my wishlist, but all the heart are filled :

2.jpg

The source code for all the heart button are like this :
3.jpg
The "data-id_product" and data-id_product_attributye" should changes.

I hope you understand, thank you !
 

serpent_driver

Well-Known Member
#4
The "data-id_product" and data-id_product_attributye" should changes.
These attributes are not the problem. data-url is the primary reason and in my mind if https://www.kadolis.com/fr/wishlist-ajax request will be excluded from being cached it should work. Only the cache plugin is the problem. It has no functions to exclude URLs from being cached, so it must be done with .htaccess.

Add this code to your .htaccess and look if it works.

Code:
RewriteCond %{REQUEST_URI} \/wishlist-ajax [NC]
RewriteRule .* - [E=Cache-Control:no-cache]
 

serpent_driver

Well-Known Member
#8
Let me take a closer look on it. For testing I will create an account to see how it works, but I am just busy and must do it later in the evening. Have you disabled the cache plugin?
 
#13
Nop, the ESI block work for the template in the "displayNav" hook, but the "displayAfterThumbnailProduct" hook act strangely

The first time this hook is called it cache the template so it never change the other time it's called
 

serpent_driver

Well-Known Member
#14
Okay, other try..... If you define a new ESI block for displayNav the complete template for Nav should be excluded from being cached. That should work, but will rise up page loading time.
 
Top