MMv4 KB
 
Creating templates with content viewable only by specific Customer Groups
  Last Edited - 04/18/2014 10:47am PDT
  Category Path - Shopping Cart Software Components > Administration Area > Design > FAQs & Tutorials
 
quote
I would like for the contents of certain store categories to be viewed only by select groups of customers. The customers able to view these categories will be belonging to Customer Group SID 43.

How can I make this work in my store's template package?

This can be accomplished using the Template Package Sandbox, located in the store's Administration Area through [Design > Template Package Sandbox]. To do this, we will need to:
  1. Populate the category template into the store's template package.
  2. Edit that template to wrap desired content in the {IF-CUSTOMER-IN-GROUP-BEGIN}/END QuickCode Tags.
  3. Save the edited template as a brand new template.
  4. Assign the new template to your category.

prerequisites
This tutorial assumes that the reader:

• Has already created their Customer Group(s) and Category(ies).
• Has experience with the Template Package Sandbox and QuickCode Tags.

 
Populating your template package

If it isn't already, the category.tpl template will need to be populated into your template package. This will give you access to editing the category template directly.

1. In your Administration Area, locate [Design > Template Package Sandbox].

2. Select the desired template package from the dropdown menu.
 
3. In the Template Package Options row, click Populate Templates. The populate tool may be used to add one or more missing templates to a template package. Templates that are missing from the package are listed in black text. Templates that are already present in the template package are listed in red text.
 
warning
If the populate tool is used to generate a template that is already present in the template package, the template will be replaced by its default version.

4. Locate category.tpl, then click its associated checkbox.

5. Click Populate Selected Templates.

 
Creating the Custom Category Template

Now that the template has been populated into your template package, we may move on to creating the custom category template. The custom category template will utilize the {IF-CUSTOMER-IN-GROUP-BEGIN} and {IF-CUSTOMER-IN-GROUP-END} QuickCode Tags; making its contents viewable only by customers within specific group(s).
 
1. In your Administration Area, locate [Design > Template Package Sandbox].

2. Select the desired template package from the dropdown menu.

3. Under Template Package Files, select category.tpl. This will open it in the Template Editor.
 
4. If the Plain Text Editor is not currently being viewed, click the "Switch to Plain Text Editor" link in the top right of the Template Editor menu.

5. Next we will implement the {IF-CUSTOMER-IN-GROUP-BEGIN} and {IF-CUSTOMER-IN-GROUP-END} tags. The {IF-CUSTOMER-IN-GROUP-BEGIN} tag can accept two optional parameters:
 
1st parameter: Comma separated list of Customer Group SID numbers.
2nd parameter: Whether the customer must be in "any" or "all" of those groups.
(Example: {IF-CUSTOMER-IN-GROUP-BEGIN:1,2,3:any})

Wrap the {IF-CUSTOMER-IN-GROUP-BEGIN} and {IF-CUSTOMER-IN-GROUP-END} tags around the content you wish to only have displayed to your group(s) of customers.
 
example
The exact placement of these tags is up to you. The content between them will be displayed only to customers that are in the Customer Group, so wrap them around content with that in mind.

An example of how this could be used, would be to hide the Add to Cart buttons to non-group members on the category page:

code that controls the buttons in the category template
{IF-PRODUCT-GROUP-PARENT-BEGIN}
<button type="button" name="" value="" class="CLICKABLE SELECT-VERSION-BUTTON" onclick="location.href='{PRODUCT-URL}'">SELECT VERSION</button>
{ELSE}                                
{IF-PRODUCT-FIELDS-BEGIN}
<button type="button" name="" value="" class="CLICKABLE SELECT-VERSION-BUTTON" onclick="location.href='{PRODUCT-URL}'">SELECT VERSION</button>
{ELSE}
<button type="button" name="" value="" class="CLICKABLE MORE-INFO-BUTTON" onclick="location.href='{PRODUCT-URL}'">MORE INFO</button>
<div class="HEIGHT-10"></div>
<button type="button" name="" value="" class="CLICKABLE ADD-TO-CART-BUTTON" onclick="location.href='quick_return.php?id={PRODUCT-SID}&qty=1'">ADD TO CART</button>
{IF-PRODUCT-FIELDS-END}                            
{IF-PRODUCT-GROUP-PARENT-END}

 

adjusted code that prevents non-group members from viewing the buttons
{IF-CUSTOMER-IN-GROUP-BEGIN:43}
{IF-PRODUCT-GROUP-PARENT-BEGIN}
<button type="button" name="" value="" class="CLICKABLE SELECT-VERSION-BUTTON" onclick="location.href='{PRODUCT-URL}'">SELECT VERSION</button>
{ELSE}                                
{IF-PRODUCT-FIELDS-BEGIN}
<button type="button" name="" value="" class="CLICKABLE SELECT-VERSION-BUTTON" onclick="location.href='{PRODUCT-URL}'">SELECT VERSION</button>
{ELSE}
<button type="button" name="" value="" class="CLICKABLE MORE-INFO-BUTTON" onclick="location.href='{PRODUCT-URL}'">MORE INFO</button>
<div class="HEIGHT-10"></div>
<button type="button" name="" value="" class="CLICKABLE ADD-TO-CART-BUTTON" onclick="location.href='quick_return.php?id={PRODUCT-SID}&qty=1'">ADD TO CART</button>
{IF-PRODUCT-FIELDS-END}                            
{IF-PRODUCT-GROUP-PARENT-END}
{
IF-CUSTOMER-IN-GROUP-END}

placement of the quickcode tags may vary
Examples provided were from the default version of the "athena" template package. The concept of using the QuickCode Tags remains the same, but the examples may differ from other template packages.

6. Optionally, the {ELSE} QuickCode Tag could be used to display a message for customers who are not in the customer group.

The {ELSE} tag can be used with any QuickCode Tags that contain an "IF" statement. Using the {ELSE} tag will cause whatever is displayed between the "ELSE" and "END tag" to only be displayed if the original condition was not met.

This works by inserting the {ELSE} tag immediately before the {IF-CUSTOMER-IN-GROUP-END} tag. In between the two tags, you may leave your message. When the {ELSE} tag and message are inserted right before the END tag:

• Customers of the group will the contents between the "BEGIN" and "ELSE" tags.

• Customers who are not in the group will view the contents between the "ELSE" and "END" tags.

example
{IF-CUSTOMER-IN-GROUP-BEGIN:43}
       Content here will appear to customers in the specified group.
{ELSE}
       This message appears to customers who are not in the group.
{IF-CUSTOMER-IN-GROUP-END}

{IF-CUSTOMER-IN-GROUP-BEGIN:43}
{IF-PRODUCT-GROUP-PARENT-BEGIN}
<button type="button" name="" value="" class="CLICKABLE SELECT-VERSION-BUTTON" onclick="location.href='{PRODUCT-URL}'">SELECT VERSION</button>
{ELSE}                                
{IF-PRODUCT-FIELDS-BEGIN}
<button type="button" name="" value="" class="CLICKABLE SELECT-VERSION-BUTTON" onclick="location.href='{PRODUCT-URL}'">SELECT VERSION</button>
{ELSE}
<button type="button" name="" value="" class="CLICKABLE MORE-INFO-BUTTON" onclick="location.href='{PRODUCT-URL}'">MORE INFO</button>
<div class="HEIGHT-10"></div>
<button type="button" name="" value="" class="CLICKABLE ADD-TO-CART-BUTTON" onclick="location.href='quick_return.php?id={PRODUCT-SID}&qty=1'">ADD TO CART</button>
{IF-PRODUCT-FIELDS-END}                            
{IF-PRODUCT-GROUP-PARENT-END}

{ELSE}
Purchasable by members only.
{IF-CUSTOMER-IN-GROUP-END}
 
7. Under "File Options", select "Save as a copy...". This will bring up a field to enter a new template name. Enter the template name following the instructions given below the field, and click "Save Changes".
 
Applying the template to the categories

The final step is to apply the newly created template to the store's categories. To do this:

1. In your Administration Area, locate [Products > Search Categories].
2. Open the category in the Category Editor, using the SID or edit link.
3. For the "Template" option, select the newly created template from the dropdown menu. It should have the prefix "category." and suffix ".tpl", for a result of something along the lines of "category._________.tpl".
 
4. Click "Save All".
 
Result

Customers belonging to the specified group of customers will be able to view the contents of your categories. Customers who are not in the group will not be able to see the group specific content.
Powered by ModularKB