Custumer group lscache issue

#1
Hello there,

Opencart Version: 3.0.3.7
Journal: 3.1.8

I've recently tried upgrading everything regarding my website by building a test environment in "test.cattex.com" where I'm currently experimenting...

I'm having some issues with the lscache, and I was hoping that maybe someone could help shed some light on how to proceed.

When the user is not logged in everything works perfectly, pages get cached and cart gets updated, the site works fast and gives satisfying results.

The problems start when the user is logged in, you see, my website has 4 different price lists that means that also my clients will have different price lists associated to their account. Sometimes a client with a high discount views the prices associated to a different account, basically the first person that visits the page sets the price for future logged-in users visiting the same page. In my situation, dividing gusts and logged-in users isn't enough, I would need a way to either create 4 different private caches or not have the prices cache at all.

Any help on this matter would be greatly appreciated.
 
#3
Yes, separate view for logged-in users is turned on, the problem is that my logged-in users have 4 diffrent prices depending on who they are, so I would need 4 diffrent cached version of the same page to visualize prices correctly.
 

AndreyPopov

Well-Known Member
#4
Yes, separate view for logged-in users is turned on, the problem is that my logged-in users have 4 diffrent prices depending on who they are, so I would need 4 diffrent cached version of the same page to visualize prices correctly.
may be you are right.

LSCache build different copies of cache by add to _lscache_vary cookie variable corresponding value.

by default for logged-in users added only one value - lsc_private=e70f67d087a65a305e80267ba3bfbc97

to build 4 different copies of cache you need add value. for example
lsc_private=e70f67d087a65a305e80267ba3bfbc97,customer=group1
lsc_private=e70f67d087a65a305e80267ba3bfbc97,customer=group2
lsc_private=e70f67d087a65a305e80267ba3bfbc97,customer=group3
lsc_private=e70f67d087a65a305e80267ba3bfbc97,customer=group4

LSCache plug-in provide only basic features that not cover all possible variants :(
like in my thread
Advanced crawler for recache. some ideas and code
cache algorithm must be modified:
- read customer group
- add value to coockie _lscache_vary


not sure, but may be ESI features can solve your problem. are your server LiteSpeed Web Server Enterprise with ESI support?

may be temporary solution is:
- leave Separate View for logged-in users
- Disable cache for Product Pages for logged-in users
 
Last edited:
#5
Yeah, that's what I figured, I honestly have no idea how to tell the cache to recognize customer groups, but it would be a very useful thing to add as I believe I'm not the only one to utilize different prices depending on the customer group.

Yes, my website runs on a LiteSpeed server and it seems like ESI works correctly.

I have done as you said and disabled cache for pages that show prices (home - category - product), the system now works, but it's basically the equivalent of shutting off LScache for logged-in users. If no other solution is possible, I guess this will do for the time being.
 

AndreyPopov

Well-Known Member
#8
thank you for your help, but I'll need more help as I don't understand exactly what to do
1. protected function checkVary

this function check what cookies must be added at cache request and send cookies to add to request

2. private function crawlUrls

at the beginning also check what cookies must be added for cache generate (this is for build whole cache for future use)


short algorithm what to do:
- read customer_group table from database
- for each group add cookie value: group='customer_group_id'

for example after this:
PHP:
$vary['session'] = 'loggedIn';
add:
PHP:
$vary['group'] = $this->checkCustomerGroup();


next code more suitable for crawlURLs !!!!!!!!!!!! (sorry)
PHP:
foreach($this->checkCustomerGroup as $customer_group_number){
$vary['group'] = $customer_group_number;
            }
or "by hand"
PHP:
for ($customer_group_number = 1 ; $customer_group_number <= $customer_group_numbers ;  $customer_group_number++ ) {
$vary['group'] = $customer_group_number;
            }
 
Last edited:
#9
"you mean here?"

private function crawlUrls($urls, $cli = false)
{
set_time_limit(0);

$count = count($urls);
if ($count < 1) {
return "";
}

$cached = 0;
$acceptCode = array(200, 201);
$begin = microtime();
$success = 0;
$current = 1;

ob_implicit_flush(TRUE);
if (ob_get_contents()) {
ob_end_clean();
}
$this->log('Start Recache:');

$recacheOption = isset($this->lscache->setting['module_lscache_recache_option']) ? $this->lscache->setting['module_lscache_recache_option'] : 0;
$recacheUserAgents = isset($this->lscache->setting['module_lscache_recache_userAgent']) ? explode(PHP_EOL, $this->lscache->setting['module_lscache_recache_userAgent']) : array("lscache_runner");
if (empty($recacheUserAgents) || empty($recacheUserAgents[0])) {
$recacheUserAgents = array('lscache_runner');
}

if ($this->lscache->esiEnabled) {
$cookies = array('', '_lscache_vary=session%3AloggedOut;lsc_private=e70f67d087a65a305e80267ba3bfbc97');
} else {
$cookies = array('');
}

$this->load->model('localisation/language');
$languages = array();
$results = $this->model_localisation_language->getLanguages();
foreach ($results as $result) {
if ($result['status']) {
$languages[] = array(
'code' => $result['code'],
'name' => $result['name'],
);
}
if (($recacheOption == '1') && ($result['code'] != $this->config->get('config_language'))) {
$cookies[] = '_lscache_vary=language%3A' . $result['code'] . ';language=' . $result['code'] . ';lsc_private=e70f67d087a65a305e80267ba3bfbc97';
}
}

$this->load->model('localisation/currency');
$currencies = array();
$results = $this->model_localisation_currency->getCurrencies();
foreach ($results as $result) {
if ($result['status']) {
$currencies[] = array(
'code' => $result['code'],
'title' => $result['title'],
);
}

if (($recacheOption == '2') && ($result['code'] != $this->config->get('config_currency'))) {
$cookies[] = '_lscache_vary=currency%3A' . $result['code'] . ';currency=' . $result['code'] . ';lsc_private=e70f67d087a65a305e80267ba3bfbc97';
}
}

if ($recacheOption == '3') {
foreach ($languages as $language) {
foreach ($currencies as $currency) {
if (($language['code'] != $this->config->get('config_language')) && ($currency['code'] != $this->config->get('config_currency'))) {
$cookies[] = '_lscache_vary=language%3A' . $language['code'] . ',currency%3A' . $currency['code'] . ';language=' . $language['code'] . ';currency=' . $currency['code'] . ';lsc_private=e70f67d087a65a305e80267ba3bfbc97';
}
}
}
}
 
#11
"sorry sorry do you mean here?"

protected function checkVary()
{
$vary = array();

if ($this->session->data['currency'] != $this->config->get('config_currency')) {
$vary['currency'] = $this->session->data['currency'];
}

if ((isset($this->session->data['language'])) && ($this->session->data['language'] != $this->config->get('config_language'))) {
$vary['language'] = $this->session->data['language'];
}


//cookie not enabled
if ((count($vary) == 0) && !$this->checkCookiesEnabled() ){
return;
}


if ($this->customer->isLogged() && isset($this->lscache->setting['module_lscache_vary_login']) && ($this->lscache->setting['module_lscache_vary_login'] == '1')) {
$vary['session'] = 'loggedIn';

}

if (isset($this->lscache->setting['module_lscache_vary_safari']) && ($this->lscache->setting['module_lscache_vary_safari'] == '1') && $this->checkSafari()) {
$vary['browser'] = 'safari';
}

if (isset($this->lscache->setting['module_lscache_vary_mobile']) && ($this->lscache->setting['module_lscache_vary_mobile'] == '1') && ($device = $this->checkMobile())) {
$vary['device'] = $device;
}

if ((count($vary) == 0) && (isset($_COOKIE['lsc_private']) || defined('LSC_PRIVATE'))) {
$vary['session'] = 'loggedOut';
}
 

AndreyPopov

Well-Known Member
#15
try:

PHP:
if ($this->customer->isLogged() && isset($this->lscache->setting['module_lscache_vary_login']) && ($this->lscache->setting['module_lscache_vary_login'] == '1')) {
$vary['session'] = 'loggedIn';
$vary['group'] = $this->customer->getGroupId();
}
 
#16
I was about to write that with your previous suggestion I was receiving a Fatal Error.

This newer version seems to work correctly, I am able to access the website as 2 diffrent people with diffrent price lists and everybody views what they are supposed to.

Thank you for the help, I don't use web crawlers so the second part is not needed in my case.
This is a simple and effective solution to a big problem.

Bonus question (if you don't mind):
my website shows the logged in customer name inside the header and footer... ESI feature should be able to handle them pretty easily but in my case it breaks the way the header looks when ESI is set to "private cache" for the header. Person logs-in does everything they need to do then they log-out, they will still be able to see their name on header and footer if they visit previously opened pages.
Am I doing something wrong? The path for header is set to "common/header", should it be something else when using journal?

Thank you again for all the help, I really appriciate it.
 

AndreyPopov

Well-Known Member
#17
I was about to write that with your previous suggestion I was receiving a Fatal Error.
it was only example what need to do. yesterday not enough time to find solution.


Bonus question (if you don't mind):
my website shows the logged in customer name inside the header and footer... ESI feature should be able to handle them pretty easily but in my case it breaks the way the header looks when ESI is set to "private cache" for the header. Person logs-in does everything they need to do then they log-out, they will still be able to see their name on header and footer if they visit previously opened pages.
Am I doing something wrong? The path for header is set to "common/header", should it be something else when using journal?
my hoster use OpenLiteSpeed that not support ESI.
I have not experience with ESI.


but may be try Disable ESI for header and footer or use ESI without cache for they.



P.S. crawler used for generate cache for quick site response.
 
Last edited:
#18
sorry I might have spoken too soon, the system still doesn't work. When I tested before the 2 clients were on different languages therefore they were looking at 2 diffrent thing. With same language whichever customer logs-in first caches the page for every other customer that logs-in.
 
#20
Yes all caches have been purged, tried scenario on different browsers and also on different devices... Unfortunately, this still happens:

1) customer A logs-in and views the website with his discounts, moves around the different pages correctly.
2) customer B logs-in and if he visits pages where customer A has been, then he sees customer A info and prices. If he goes to a page where only he has been, then that page will get cached with Customer B info and prices.

Like before, the first client to visit the page while being logged-in will cache the page for everyone else who logs-in afterwards.
 
Top