Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-from-login-user [2017/12/18 19:19] Jackson Zhang |
litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-from-login-user [2017/12/18 19:37] (current) Lisa Clarke |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Can you Exclude the Price Block from public Cache for Only the Logged-in Users? ====== | + | ====== Can you Exclude the Price Block from Public Cache for Only the Logged-in Users? ====== |
- | You might have a situation where pricing varies per user and is fetched via API from an external ERP system. This system only applies to logged-in users. Users who are logged out should not see pricing at all. | + | You might have a situation where pricing varies per logged-in user and is fetched via API from an external ERP system. Under this system, logged-out users would see no pricing at all. |
- | + | What a non-logged-in user would see: | |
- | For non-logged-in user: | + | |
{{ :litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-loginrequired.png?600 |}} | {{ :litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-loginrequired.png?600 |}} | ||
{{ :litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-loginrequired-header.png?400 |}} | {{ :litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-loginrequired-header.png?400 |}} | ||
- | For the logged-in user: | + | What a logged-in user would see: |
{{ :litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-logged-in.png?600 |}} | {{ :litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-logged-in.png?600 |}} | ||
{{ :litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-loginrequired-header.png?400 |}} | {{ :litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-loginrequired-header.png?400 |}} | ||
- | On product page click "login" to see the discounted prices from API. Fetch the prices directly from a external API solution to have separate customer pricing. There are two customer groups: group id 1 and group id 2. You would want the API price update for only one customer group 1 and store 1, but not group 2. How? | + | Here's how it should work: When a user clicks ''login'', that customer's discounted prices would be fetched directly from an external API solution. We would set this up through two customer groups: group ID 1, which would be for logged-in users, and group ID 2, for everyone else. The API update would happen for everyone in group 1 and store 1, but not group 2. |
- | Caching pages with this kind of setup is tricky. LiteMage is able to cache different prices per customer group, but not per individual customers. We cannot punch a hole for price block, however, we can simply make the whole page either not cache, or privately cache. For this example, we would like to make customer group 1 logged-in user and store ID 1 to be private cache. | + | Caching pages with this kind of setup is tricky. LiteMage is able to cache different prices per customer group, but not per individual customers. We cannot punch a hole for the price block, however, we can simply make the whole page either not cached, or privately cached. For this example, we would like to make customer group ID 1 (logged-in users) and store ID 1 to be privately cached. |
- | To enable private cache, you will need to add ''CacheLookup private on'' in .htaccess after ''LiteMage on'', looks like the following: | + | To enable private cache, you will need to add ''CacheLookup private on'' in ''.htaccess'' after ''LiteMage on'', as follows: |
<IfModule Litespeed> | <IfModule Litespeed> | ||
LiteMage on | LiteMage on | ||
Line 22: | Line 21: | ||
</IfModule> | </IfModule> | ||
| | ||
- | Also you will need to change LiteMage Esi.php code by adding the following to app/code/community/Litespeed/Litemage/Helper/Esi.php | + | Also you will need to modify LiteMage's ''app/code/community/Litespeed/Litemage/Helper/Esi.php''. In ''protected function _getDefaultEnvCookieValue()'', line 1160 - 1164 within ''if ($diffGrp = $this->_config->getConf(Litespeed_Litemage_Helper_Data::CFG_DIFFCUSTGRP))'' add the following: |
- | to ''protected function _getDefaultEnvCookieValue()'' line 1160 - 1164 within ''if ($diffGrp = $this->_config->getConf(Litespeed_Litemage_Helper_Data::CFG_DIFFCUSTGRP))'' | + | |
/* customized code added by for case 1 */ | /* customized code added by for case 1 */ | ||
Line 32: | Line 29: | ||
/* end of customized code change */ | /* end of customized code change */ | ||
- | The final code looks like: | + | The final code looks like so: |
protected function _getDefaultEnvCookieValue() | protected function _getDefaultEnvCookieValue() | ||
Line 54: | Line 51: | ||
if ($currCustomerGroup == 1 && $currStoreId == 1) { | if ($currCustomerGroup == 1 && $currStoreId == 1) { | ||
$this->_cacheVars['flag'] |= self::CHBM_PRIVATE; | $this->_cacheVars['flag'] |= self::CHBM_PRIVATE; | ||
- | // $this->setNotCacheable(); | ||
} | } | ||
/* end of customized code change */ | /* end of customized code change */ | ||
Line 63: | Line 59: | ||
} | } | ||
- | So for the logged-in user with group 1 and store 1, it will be served from private cache and private ESI blocks. The rest users will be served from public cache with private ESI blocks. | + | So for the logged-in user in customer group 1 and store 1, product pages will be served from private cache and private ESI blocks. All other users will be served from public cache with private ESI blocks. |
- | Updated LiteMage configuration: | + | Update the LiteMage configuration: |
Separate Cache Copy per Customer Group -> Yes | Separate Cache Copy per Customer Group -> Yes | ||
| | ||
- | After the above change, you should be able to found the pages are being served from LiteMage private cache. | + | After the above change, you should be able to see that the pages are being served from LiteMage private cache. |
{{ :litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-logged-in.png?600 |}} | {{ :litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-logged-in.png?600 |}} | ||
{{ :litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-logged-in-privatecache-header.png?600 |}} | {{ :litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-logged-in-privatecache-header.png?600 |}} | ||
- | You should make a backup of this file since it is a customized solution and will be overided by LiteMage upgrade next time. You should copy back the custommized solution when you complete your next upgrade. | ||