Author Topic: Currency selector and VirtueMart Products module caching  (Read 236 times)

rvbgnu

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 119
    • Puma-IT.ie
Currency selector and VirtueMart Products module caching
« on: February 22, 2019, 16:11:46 pm »
Hello,

I am trying to fix a problem with the currency selector. It is not necessarily an issue, it could be a feature to add, or a setting that I should adjust.
The VM site in multilingual, with one currency, but displaying a few other for customer information.
When selecting another currency, one should see the products prices updated. But the problem here is that the prices are not refreshed, because of the module caching.

1. On any page using VirtueMart Products modules, I can see the problem when:
- Show product price = Yes
- Advanced > Caching = Yes
If Caching is on No, then the prices are refreshed with the selected currency, which is the expected behaviour.

2. On any page directly from VM component, like Product Detail, and Category Layout:
- the Product prices are refreshed
- but not if they are in a cached module

Also, the settings are:
- Global Configuration > System Cache = On - Conservative
- Modules > VirtueMart Currency Selector > (default settings) > Advanced > Layout = default, Enable cache = No

Of course, a quick solution is to disable the caching in all Modules, one by one. I have more than 100 modules, spread out on the categories landing pages. But exactly because most of them are on landing pages, including the home page, I would prefer to leverage the caching for performance reasons. Also I don't see as an issue if, after selecting another currency, the page takes a few seconds to reload (because cache flushed). It should not happen more than once for one user, and it is not on the first visited page (landing page), where page loading speed is crucial to make a good impression.

I've read quite a lot, and googled to find similar issue or discussion, but to no avail.

Do you have any solution for that, please?

I also read this
https://docs.virtuemart.net/manual/general-concepts/223-caches.html

Do you have some insights about the caching?

Thanks for your help!
Best Regards, Hervé Boinnard - Irish Time (GMT)
Joomla! multilingual website and online business made easy - https://www.puma-it.ie

Updated for VM3 and Joomla 3.x! Stripe.com payment plugin for VirtueMart: https://www.puma-it.ie/en/joomla-and-virtuemart-extensions/stripe-for-virtuemart
Authipay (AIB Merchant Services) for VirtueMart 2 & 3: https://www.puma-it.ie/en/joomla-and-virtuemart-extensions/authipay-aib-merchant-services-for-virtuemart

rvbgnu

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 119
    • Puma-IT.ie
Re: Currency selector and VirtueMart Products module caching
« Reply #1 on: February 27, 2019, 19:40:45 pm »
So I decide to find some code to help with this issue.

For the moment, it will be in the Currency selector module
Code: [Select]
virtuemart/modules/mod_virtuemart_currencies/mod_virtuemart_currencies.phphttp://dev.virtuemart.net/projects/virtuemart/repository/changes/trunk/virtuemart/modules/mod_virtuemart_currencies/mod_virtuemart_currencies.php

I add this piece of code at the end:
Code: [Select]
// Clean the cache when the currency is changed with the selector
$cache = VmConfig::getCache();
$cache->clean('com_virtuemart_cats');
$cache->clean('com_virtuemart_cat_childs');
$cache->clean('mod_virtuemart_product');
$cache->clean('mod_virtuemart_category');

It would be better to be able to decide which caches to clean, and it could be in the module settings (for later).

But this first attempt is not great: it happens at every page load when the module is displayed.

Please could you tell me where is executed the actual change of currency?
Best Regards, Hervé Boinnard - Irish Time (GMT)
Joomla! multilingual website and online business made easy - https://www.puma-it.ie

Updated for VM3 and Joomla 3.x! Stripe.com payment plugin for VirtueMart: https://www.puma-it.ie/en/joomla-and-virtuemart-extensions/stripe-for-virtuemart
Authipay (AIB Merchant Services) for VirtueMart 2 & 3: https://www.puma-it.ie/en/joomla-and-virtuemart-extensions/authipay-aib-merchant-services-for-virtuemart

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 9789
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Currency selector and VirtueMart Products module caching
« Reply #2 on: February 27, 2019, 20:09:27 pm »
When selecting another currency, one should see the products prices updated. But the problem here is that the prices are not refreshed, because of the module caching.
There are 1 or even 2 hidden configs which controll this. Ahh now I got you. Actually the prices do not "change". But there is actually a hidden config, which really use another price entry if existing, when you change to another currency.

1. On any page using VirtueMart Products modules, I can see the problem when:
- Show product price = Yes
- Advanced > Caching = Yes
If Caching is on No, then the prices are refreshed with the selected currency, which is the expected behaviour.

2. On any page directly from VM component, like Product Detail, and Category Layout:
- the Product prices are refreshed
- but not if they are in a cached module
Yeh, for such complex setup, there is no caching. You can add a manual caching, you can see an example in the category module. Ah yes, and please join and committ the code (first send it to me, 2-3 committs later I may give you rights to committ yourself).

The manual caching could handle the selected currency. Then it should work.

Also, the settings are:
- Global Configuration > System Cache = On - Conservative

Correct! Very important.

- Modules > VirtueMart Currency Selector > (default settings) > Advanced > Layout = default, Enable cache = No
Actually this one can be imho cached, you may try.

https://docs.virtuemart.net/manual/general-concepts/223-caches.html
Thank you. I hope it helped.

So as written above, I think the best solution is to add a "manual" cache, which considers the selected currency.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

rvbgnu

  • 3rd party VirtueMart Developer
  • Jr. Member
  • *
  • Posts: 119
    • Puma-IT.ie
Re: Currency selector and VirtueMart Products module caching
« Reply #3 on: February 28, 2019, 00:01:03 am »
Thanks Max for these precision. It really helps.

Quote
Actually the prices do not "change". But there is actually a hidden config, which really use another price entry if existing, when you change to another currency.
This is my main concern for the moment. When the user change to another currency, in the currency selector, the priceDisplay is not refreshed if mod_virtuemart_product is cached. So I am looking at a way to clean the cache ONLY when the currency selector form is submitted.

But I did not find where to catch this form submit. I don't want to clean the cache every time a mod_virtuemart_product is displayed. I can add an hidden input param in the mod_virtuemart_currencies, but where should I catch it to add the cache cleaning?
Best Regards, Hervé Boinnard - Irish Time (GMT)
Joomla! multilingual website and online business made easy - https://www.puma-it.ie

Updated for VM3 and Joomla 3.x! Stripe.com payment plugin for VirtueMart: https://www.puma-it.ie/en/joomla-and-virtuemart-extensions/stripe-for-virtuemart
Authipay (AIB Merchant Services) for VirtueMart 2 & 3: https://www.puma-it.ie/en/joomla-and-virtuemart-extensions/authipay-aib-merchant-services-for-virtuemart