Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-from-login-user [2017/12/11 20:28]
Jackson Zhang created
litespeed_wiki:cache:litemage:troubleshooting:exclude-price-block-from-login-user [2017/12/18 19:37] (current)
Lisa Clarke
Line 1: Line 1:
-====== ​How to exclude price block from the logged ​in users? ======+====== ​Can you Exclude the Price Block from Public Cache for Only the Logged-in Users? ======
  
-The Setup is: +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.
- 1. Hide prices for all "​not ​logged in" customers +
- 2. For logged in users: Fetch product prices ​via API from external ERP system ​for each user.+
  
-How to exclude the price block "​Mage_Catalog_Block_Product_View_Type_Simple"​ And "​Mage_Catalog_Block_Product_Price"​ from template: +What a non-logged-in user would see
-"​frontend/​base/​default/​template/​rodin/​product/​price.phtml"​ so that the logged in users see their own prices directly from API call and not cache? +{{ :​litespeed_wiki:​cache:​litemage:​troubleshooting:​exclude-price-block-loginrequired.png?600 |}} 
-{{ :​litespeed_wiki:​cache:​litemage:​troubleshooting:​exclude-price-block.png?​800 |}}+{{ :​litespeed_wiki:​cache:​litemage:​troubleshooting:​exclude-price-block-loginrequired-header.png?400 |}}
  
-How do you price for logged in users? are they different prices ​based on customer group? Or are they different ​for each user? +What a logged-in user would see: 
-Currentlylitemage ​can only do cache based on customer group, ​not individual ​users.+{{ :​litespeed_wiki:​cache:​litemage:​troubleshooting:​exclude-price-block-logged-in.png?​600 |}} 
 +{{ :​litespeed_wiki:​cache:​litemage:​troubleshooting:​exclude-price-block-loginrequired-header.png?​400 |}} 
 + 
 +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 the price blockhowever, 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'',​ as follows: 
 +  <​IfModule Litespeed>​  
 +  LiteMage on  
 +  CacheLookup private on 
 +  </​IfModule>​ 
 +   
 +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:​ 
 + 
 +  /* customized code added by for case 1 */ 
 +          if ($currCustomerGroup == 1 && $currStoreId == 1) { 
 +                    $this->​_cacheVars['​flag'​] |= self::​CHBM_PRIVATE;​ 
 +          } 
 +  /* end of customized code change */ 
 + 
 +The final code looks like so: 
 + 
 +   ​protected function _getDefaultEnvCookieValue() 
 +    { 
 +    ... 
 +    ... 
 +                 if ($diffGrp = $this->​_config->​getConf(Litespeed_Litemage_Helper_Data::​CFG_DIFFCUSTGRP)) { 
 +                        // diff cache copy per customer group 
 +                        $currCustomerGroup = Mage::​getSingleton('​customer/​session'​)->​getCustomerGroupId() ; 
 +                        if ( Mage_Customer_Model_Group::​NOT_LOGGED_IN_ID != $currCustomerGroup ) { 
 +                                if ($diffGrp == 1) // diff copy per group 
 +                                        $default['​cgrp'​] = $currCustomerGroup ; 
 +                                elseif ($diffGrp == 2)    // diff copy for logged in user 
 +                                        $default['​cgrp'​] = '​in'​ ; 
 +                                elseif ($diffGrp == 3) { 
 +                                        $cgset = $this->​_config->​getConf(Litespeed_Litemage_Helper_Data::​CFG_DIFFCUSTGRP_SET);​ 
 +                                        if (isset($cgset[$currCustomerGroup])) 
 +                                                $default['​cgrp'​] = $cgset[$currCustomerGroup];​ 
 +                                } 
 +                /* customized code added for case 1 */ 
 +                                if ($currCustomerGroup == 1 && $currStoreId == 1) { 
 +                                        $this->​_cacheVars['​flag'​] |= self::​CHBM_PRIVATE;​ 
 +                                } 
 +                /* end of customized code change */ 
 +                        } 
 +                } 
 +  ... 
 +  ... 
 +  } 
 + 
 +So for the logged-in user in customer group 1 and store 1product pages will be served from private cache and private ESI blocks. All other users will be served from public cache with private ESI blocks. 
 + 
 +Update the LiteMage configuration:​ 
 +  Separate Cache Copy per Customer Group -> Yes 
 +   
 +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-privatecache-header.png?​600 |}}
  
-For logged in users, you can make those price block as private ESI block and not cacheable. but this may need custom change, cannot directly do by configuration. Because for non-logged-in users you do not want to have this logic. 
  
-This will require a custom project to achieve what you want if you do have different pricing at each user level. 
  • Admin
  • Last modified: 2017/12/11 20:28
  • by Jackson Zhang