Customer Groups
To accommodate variable pricing and/or visibility for specific customer group, we will introduce two additional parameters to every API request.
- priceFieldSuffix
- visibilityGroupID
See: Modify Request Overview for details on preparing for Klevu JS overriding
See : Klevu API Documentation for Customer Groups
Indexing
The additional currency pricing data must be supplied at the product level during catalog indexing.
XML FEED example
Below is a FEED XML example for specific group visibility
<item>
. . .
<price>123.45 GBP</price>
<sale_price>100 GBP</sale_price>
<groups>
<group>
<id>vip_customer_group</id>
</group>
</groups>
. . .Below is a FEED XML example for specific group visibility and/or variable pricing
<item>
. . .
<price>123.45 GBP</price>
<sale_price>100 GBP</sale_price>
<groups>
<group>
<id>vip_customer_group</id>
<price>49.99 GBP</price>
<sale_price>49.99 GBP</sale_price>
</group>
</groups>
. . .If you intend to use multiple currencies in addition to group variable pricing and/or visibility, please review the Template JS Multi-Currency guide for more details
Template JS Override
The desired group visibility and/or prices are applied to all queries via overrides using the "all" scope value.
See: Modify Request Overview for details on preparing for Klevu JS overriding
Example 1
Exclude all records which do not belong to the group
<script type=“text/javascript”>
// the group id of the currently logged in customer
var klevu_loginCustomerGroupId = '{{customer.customer_group_id}}' ? '{{customer.customer_group_id}}' : '';
var klevu_loginCustomerGroup = klevu_loginCustomerGroupId ? 'groupid_' + klevu_loginCustomerGroupId : '';
// only modify the requests when there is a valid customer group id
if (klevu_loginCustomerGroupId) {
klevu.modifyRequest('all', function(data, scope){
klevu.each(data.request.current.recordQueries, function(key, query){
klevu.setObjectPath(query, "settings.visibilityGroupID", klevu_loginCustomerGroup);
});
});
}
</script>API Parameter | Description | Format |
|---|---|---|
visibilityGroupID | Exclude all records which do not belong to the group | {GROUPID} |
See : Klevu API Documentation for Customer Groups
Example 2
Apply the specific customer group pricing for the appropriate currency
<script type="text/javascript">
// the currency and group of the currently logged in customer
var klevu_currency = '{{currency_selector.active_currency_code}}';
var klevu_loginCustomerGroupId = '{{customer.customer_group_id}}' ? '{{customer.customer_group_id}}' : '';
// only modify the requests when there is a valid customer group id
if (klevu_loginCustomerGroupId) {
klevu.modifyRequest('all', function(data, scope){
klevu.each(data.request.current.recordQueries, function(key, query){
klevu.setObjectPath(query, 'settings.priceFieldSuffix', klevu_currency + '-groupid--' + klevu_loginCustomerGroupId);
});
});
}
</script>API Parameter | Description | Format |
|---|---|---|
priceFieldSuffix | Fetch prices/currency specific to a customer group | {CURRENCY}-{GROUPID} |
See : Klevu API Documentation for Customer Groups