question
How do I restrict access to the shopping cart, so only customers with a current membership can view and purchase products?
Preventing customers who do not have a current membership from viewing or purchasing products (except for the membership product) is quite possible to do, but involves customization of several different shopping cart features. This tutorial requires a basic familiarity with Subscription Products, Customer Groups, Templates, and QuickCode Tags.
Create the "Membership" subscription product
recommended reading
Since customers must purchase a membership in order to view and purchase any other products in the store, the first step is to create the membership product. The membership product will be a subscription product, so that when customers purchase the product, they will be allowed store access for the duration of the subscription. If the subscription expires, customers must purchase a new membership in order to continue shopping at the store.
There are many different options for setting up subscription rules for products. Two of the most common types of subscription are:
Product that bills every X months
Buy X, Start a Subscription to Y
To create a new subscription product, start at [Products > Add a Product]. For a detailed explanation of all of the product options, refer to the Product Editor Knowledge Base article. In this tutorial, we will skip to the Subscription Rules product options, since those are the options specifically relevant to the topic at hand.
example "membership" product subscription rules settings
In this tutorial, the membership will have three different payment plans: annual, monthly, and biweekly. We will create one subscription product for each payment plan. Different types of subscription rules and different numbers of subscriptions products could also be used.
First Product (Membership with Annual Payments)
Subscription Schedule
Product's subscription term: Anniversary Date...
Future orders are processed on the yearly anniversary date of the original order.
Rescheduling Options
First, this product will use its Subscription Schedule to reschedule subscriptions for this product 0 time(s).
...
Then, after rescheduling subscriptions for this product 0 times, it will do the following:
Restart the subscription to itself. (A never-ending subscription.)
Subscription Rules for an annual payment plan membership product
After entering all options for the first membership product, click any of the Submit All buttons on the page. Then scroll to the Related Pages section at the top of the page, and click the Add a Product link.
Second Product (Membership with Monthly Payments)
Subscription Schedule
Product's subscription term: Anniversary Date...
Future orders are processed on the monthly anniversary date of the original order.
Rescheduling Options
First, this product will use its Subscription Schedule to reschedule subscriptions for this product 0 time(s).
...
Then, after rescheduling subscriptions for this product 0 times, it will do the following:
Restart the subscription to itself. (A never-ending subscription.)
Subscription Rules for a monthly payment plan membership product
After entering all options for the second membership product, click any of the Submit All buttons on the page. Then scroll to the Related Pages section at the top of the page, and click the Add a Product link.
Third Product (Membership with Biweekly Payments)
Subscription Schedule
Product's subscription term: X Day of Week/Month/Year...
Future orders are processed on the:
2nd day of every 2 weeks
Orders placed less than 2 day(s) before the next bill day will be pushed to the next billing period.
Rescheduling Options
First, this product will use its Subscription Schedule to reschedule subscriptions for this product 0 time(s).
...
Then, after rescheduling subscriptions for this product 0 times, it will do the following:
Restart the subscription to itself. (A never-ending subscription.)
Subscription Rules for a biweekly payment plan membership product
After entering all options for the third membership product, click any of the Submit All buttons on the page.
Create the "Membership" customer group
A customer group will be used to easily track which customers have a current subscription to any of the three membership products.
recommended reading
To create a new customer group, start at [Customers > Add a Customer Group]. For a detailed explanation of all of the customer group options, refer to the Customer Group Editor Knowledge Base article. In this tutorial, we will skip to the options dealing with the customer group rules, since those are the options specifically relevant to the topic at hand.
example "membership" customer group settings
In this tutorial, the membership payment plan product SIDs are 123, 124, and 125. We will create one customer group for any customer with a current subscription to any of those three products.
Customer Group Options
How to apply rules below match ANY of the rules below
Rule Type Subscriptions
Rule Details Product SID is 123
After entering the options for the first rule, scroll to the bottom of the page and click Save Changes. A new row of rule options will appear. In the new row, enter the following rule options:
Rule Type Subscriptions
Rule Details Product SID is 124
Again, scroll to the bottom of the page and click Save Changes. Yet another new row of rule options will appear. In this new row, enter the following rule options:
Rule Type Subscriptions
Rule Details Product SID is 125
Scroll to the bottom of the page once more and click Save Changes again. The complete customer group should have three rules, one for each "membership" product SID, and should be set to match ANY rule, so that any variation of the membership will allow the customer to qualify for the customer group.
Rules to create a group of all customers with any of the three membership subscriptions
tip: write down the customer group sid
After the new customer group has been saved, the page will reload, and an SID number will now be assigned to the customer group. The SID number will be displayed as Option 1 System ID (SID). Make note of the SID number, as it will be needed later.
Prepare the template package
In the third and most complex part of the process, brief changes will need to be made to the code of each template in the live template package to check for login and current membership. A more involved change will also need to be made to the checkout template, so that customers who do not yet have a membership can still complete an order, as long as the order includes a new membership.
recommended reading
There are over 36 templates available, and if all of the available templates are present in the template package, each of of them will need to be edited. Using the universal template to control the design of as many store pages as possible, will minimize the number of templates to edit.
There are three pages that will need to be accessible by customers who are not yet part of the membership group: the basket page, the checkout page, and the checkout receipt page. Customers who are in the process of purchasing a new membership will need to be able to access the checkout page in order to purchase the membership, and may also need to access the basket page in case they decide to purchase a different payment plan than initially selected. And customers who have just completed a new membership purchase would need to be able to view the receipt for their order, even though it might take about 15 minutes after completing the order before they are assigned to the correct membership customer group to be able to place future orders.
Since those three pages will handle the login check differently, those templates may need to be populated to work with individually.
Ideally, at this point the template package will contain only the universal template, the basket template, the checkout template, and the checkout receipt template.
tip: backup the template package
Making a backup copy before starting any major edits to a template package is a good idea, so that if anything goes wrong, it is possible to quickly load the backup template package into the sandbox and go live with the backup copy.
This is discussed in more detail in the following Knowledge Base article:
Copy a template package
Customize the universal template
recommended reading
Go to [Design > Template Package Sandbox]. In the first section, titled Select a Template Package, from the dropdown menu select the current LIVE template package (such as athena (LIVE)). From the Template Package Files column on the left, select the universal template (such as universal.tpl). The selected template will then display in the Template Editor pane for review and editing.
For this type of customization, working in preview mode is not recommended. If the Template Editor pane is currently displaying a preview of the store website, click the Switch to Plain Text Editor link in the right side of the Template Editor title bar. The page will update, to display the source code of the selected template in the Template Editor pane.
Scroll through the source code looking for the following code:
example of default code to locate and replace
<!-- BEGIN TEMPLATE-SPECIFIC CONTENT -->
{UNIVERSAL-CONTENT}
<!-- END TEMPLATE-SPECIFIC CONTENT -->
Two "IF" QuickCode Tag sets will be used to wrap the {UNIVERSAL-CONTENT} QuickCode Tag, so that the main page content will only be displayed to customers who are logged in, and who are assigned to the customer group that tracks customers with current memberships. The {ELSE} QuickCode Tag will also be used, so that customers who do not have a current membership will instead see a login form with instructions to log in to their existing account or to purchase a new membership. An "Add to Cart" link to the membership product will be included. In the example below, the membership product SID number 123 is used.
The "IF" QuickCode Tag sets are {IF-CUSTOMER-LOGGED-IN-BEGIN}{IF-CUSTOMER-LOGGED-IN-END} and {IF-CUSTOMER-IN-GROUP-BEGIN:X}{IF-CUSTOMER-GROUP-END}. The X in {IF-CUSTOMER-IN-GROUP-BEGIN:X} will be replaced by the SID number of the "membership" customer group.
In the example below, 1 is the SID of the membership customer group. Replace 1 with the actual SID of the membership customer group for your store.
In the "Add to Cart" links, www.example-store.com is the store's URL. Replace www.example-store.com with your store's URL (including directory if the shopping cart is installed in a specific directory).
Finally, 123, 124, and 125 are the product SIDs of the membership products. Replace 123, 124, and 125 with the product SIDs of your membership products. Delete any extra "Add to Cart" links. If you have more than three membership products, create an additional "Add to Cart" link for each additional membership product.
example of customized code to replace the above default code
<!-- BEGIN TEMPLATE-SPECIFIC CONTENT -->
{IF-CUSTOMER-LOGGED-IN-BEGIN}
{IF-CUSTOMER-IN-GROUP-BEGIN: 1}
{UNIVERSAL-CONTENT}
{ELSE}
You must have a current membership in order to purchase from {COMPANY-NAME}. Select one of the options below:
<p><a href="http:// www.example-store.com/quick_checkout.php?id1= 123&qty1=1">Click here</a> to purchase a membership with an annual payment plan.</p>
<p><a href="http:// www.example-store.com/quick_checkout.php?id1= 124&qty1=1">Click here</a> to purchase a membership with a monthly payment plan.</p>
<p><a href="http:// www.example-store.com/quick_checkout.php?id1= 125&qty1=1">Click here</a> to purchase a membership with a biweekly payment plan.</p>
{IF-CUSTOMER-IN-GROUP-END}
{ELSE}
You must have a current membership in order to purchase from {COMPANY-NAME}. If you already have a current membership, please log in to your account.
<form name="sample_login_form" method="post" action=" {THIS-PAGE}">
<span class="MISC-TITLE">Email Address:</span> <input type="text" name="login_email" size="30" />
<p><span class="MISC-TITLE">Password:</span> <input type="password" name="login_password" size="30" /></p>
<p><input type="submit" name="cmr_login" class="SUBMIT-BUTTON" value="Log in to your Customer Account" /></p>
</form>
<br />
<p>If you have forgotten your password, enter the email address associated with your customer account in the field below. The login information associated with that email address will be emailed to it.</p>
<form id="form1" name="form1" method="post" action=" {THIS-PAGE}">
<p><span class="MISC-TITLE">Email Address:</span> {FIELD-EMAIL-FETCH-LOGIN}</p>
<p><input name="submit" type="submit" id="submit" value="Submit" class="SUBMIT-BUTTON" /></p>
</form>
<br />
If you do not yet have a membership, select one of the options below to purchase a membership now:
<p><a href="http:// www.example-store.com/quick_checkout.php?id1= 123&qty1=1">Click here</a> to purchase a membership with an annual payment plan.</p>
<p><a href="http:// www.example-store.com/quick_checkout.php?id1= 124&qty1=1">Click here</a> to purchase a membership with a monthly payment plan.</p>
<p><a href="http:// www.example-store.com/quick_checkout.php?id1= 125&qty1=1">Click here</a> to purchase a membership with a biweekly payment plan.</p>
{IF-CUSTOMER-LOGGED-IN-END}
<!-- END TEMPLATE-SPECIFIC CONTENT -->
After replacing the original three lines of code with the new expanded code, scroll to the File Options section at the bottom of the Template Package Sandbox page, select Save and click Go.
note: extended template packages
The steps above are based on a customized minimal template package, that only contains the template files basket.tpl, checkout_1.tpl, checkout_receipt.tpl, and universal.tpl.
If your store is using a template package that contains additional templates, then the steps to customize the universal template will need to be repeated for all templates corresponding to pages that should be restricted access, such as product.tpl, category.tpl, vendor.tpl, etc. In those pages, the code to wrapped in the login check will be more extensive, and will likely consist of the <!-- BEGIN TEMPLATE-SPECIFIC CONTENT --> comment followed by many lines of code, and then the <!-- END TEMPLATE-SPECIFIC CONTENT --> comment. The login check "BEGIN" QuickCode Tags would be inserted immediately after the beginning <!-- BEGIN TEMPLATE-SPECIFIC CONTENT --> comment. The remaining custom code would be insert immediately before the ending <!-- END TEMPLATE-SPECIFIC CONTENT --> comment.
Customize the checkout template
Customers will need to be able to complete the checkout process to purchase a membership, so the same login and membership check cannot be used on the checkout template. Hiding the main options of the checkout page if the customer does not yet have a current membership would prevent anyone from ever purchasing a membership. On the checkout page, additional changes will be required, so that customers who have the membership product in their basket can complete their order, as well as customers who already have a current membership.
In addtion to the {IF-CUSTOMER-LOGGED-IN-BEGIN}{IF-CUSTOMER-LOGGED-IN-END} and {IF-CUSTOMER-IN-GROUP-BEGIN:X}{IF-CUSTOMER-GROUP-END} QuickCode Tag sets, the checkout page will use the {IF-PRODUCT-IN-ORDER-BEGIN:Y}{IF-PRODUCT-IN-ORDER-END} QuickCode Tags so that new customers will be able to see the payment options and complete their order, as long as their order includes the membership product. The Y in {IF-PRODUCT-IN-ORDER-BEGIN:Y} will be replaced by the SID number of the specific membership product. If there are multiple membership products, Y will be replaced by a comma-separated list of the SID numbers of all of the membership products.
The change to the checkout template will be fairly extensive, and will be made a bit easier by using Notepad (not Wordpad) to put everything together.
Leaving the Template Package Sandbox page open in the browser, open Notepad.
copy and paste the following text into a new Notepad document:
{IF-CUSTOMER-LOGGED-IN-BEGIN}
{IF-CUSTOMER-IN-GROUP-BEGIN: 1}
<!--Insert payment options here.-->
{ELSE}
{IF-PRODUCT-IN-ORDER-BEGIN: 123, 124, 125}
<!--Repeat payment options here.-->
{ELSE}You must have a current membership to complete your order. If you do not yet have a membership, select one of the options below to purchase a membership now:
<p><a href="http:// www.example-store.com/quick_checkout.php?id1= 123&qty1=1">Click here</a> to purchase a membership with an annual payment plan.</p>
<p><a href="http:// www.example-store.com/quick_checkout.php?id1= 124&qty1=1">Click here</a> to purchase a membership with a monthly payment plan.</p>
<p><a href="http:// www.example-store.com/quick_checkout.php?id1= 125&qty1=1">Click here</a> to purchase a membership with a biweekly payment plan.</p>
{IF-PRODUCT-IN-ORDER-END}
{IF-CUSTOMER-IN-GROUP-END}
{ELSE}
{IF-PRODUCT-IN-ORDER-BEGIN: 123, 124, 125}
<!--Repeat payment options here.-->
{ELSE}You must have a current membership to complete your order. If you do not yet have a membership, select one of the options below to purchase a membership now:
<p><a href="http:// www.example-store.com/quick_checkout.php?id1= 123&qty1=1">Click here</a> to purchase a membership with an annual payment plan.</p>
<p><a href="http:// www.example-store.com/quick_checkout.php?id1= 124&qty1=1">Click here</a> to purchase a membership with a monthly payment plan.</p>
<p><a href="http:// www.example-store.com/quick_checkout.php?id1= 125&qty1=1">Click here</a> to purchase a membership with a biweekly payment plan.</p>
{IF-PRODUCT-IN-ORDER-END}
You must have a current membership to complete your order. If you already have a current membership, please log in to your account.
<form name="sample_login_form" method="post" action=" {THIS-PAGE}">
<span class="MISC-TITLE">Email Address:</span> <input type="text" name="login_email" size="30" />
<p><span class="MISC-TITLE">Password:</span> <input type="password" name="login_password" size="30" /></p>
<p><input type="submit" name="cmr_login" class="SUBMIT-BUTTON" value="Log in to your Customer Account" /></p>
</form>
If you do not yet have a membership, select one of the options below to purchase a membership now:
<p><a href="http:// www.example-store.com/quick_checkout.php?id1= 123&qty1=1">Click here</a> to purchase a membership with an annual payment plan.</p>
<p><a href="http:// www.example-store.com/quick_checkout.php?id1= 124&qty1=1">Click here</a> to purchase a membership with a monthly payment plan.</p>
<p><a href="http:// www.example-store.com/quick_checkout.php?id1= 125&qty1=1">Click here</a> to purchase a membership with a biweekly payment plan.</p>
{IF-CUSTOMER-LOGGED-IN-END}
Replace the 1 in {IF-CUSTOMER-IN-GROUP-BEGIN:1} with the SID of the membership customer group. Replace 123,124,125 in {IF-PRODUCT-IN-ORDER-BEGIN:123,124,125} with the SID number(s) of your store's membership product(s). And replace www.example-store.com with your store's URL (including directory if the shopping cart is installed in a specific directory).
Now go back to the browser window that should still be open to the Template Package Sandbox page, and scroll back to the top Select a Template to Edit section. The dropdown menu should still have the current LIVE template package selected. From the Template Package Files column on the left, select checkout_1.tpl.
The checkout template will then display in the Template Editor section. For this type of customization, working in preview mode is not recommended. The Template Editor pane should already be in Plain Text mode, but if the editor is instead displaying a preview of the page, click the Switch to Plain Text Editor link in the right side of the Template Editor title bar. The page will reload again, to display the source code of the selected template in the Template Editor pane.
Scroll through the source code looking for the code that begins with:
<span class="BLACK-15 PADDING-3 DISPLAY-BLOCK SECTION-TITLE">Payment Options</span>
And ends with:
{IF-PAY-WITH-COUPON-END}
</form>
Highlight that section, starting with (and including) <span class="BLACK-15 PADDING-3 DISPLAY-BLOCK SECTION-TITLE">Payment Options</span> and ending with (and including) {IF-PAY-WITH-COUPON-END}. Copy the highlighted text and go back to the open Notepad file.
In the Notepad file, locate <!--Insert payment options here.--> and paste the copied text to replace that line. Scroll down in the Notepad file to <!--Repeat payment options here.--> and paste the copied text there as well to also replace that line. Scroll down in the Notepad file to the second occurance of <!--Repeat payment options here.--> and paste the copied text there to also replace that line. Now highlight and copy the entire Notepad file.
Go back to the browser window that is open to the HTML Templates page. Replace the payment section of code (starting with and including <span class="BLACK-15 PADDING-3 DISPLAY-BLOCK SECTION-TITLE">Payment Options</span> and ending with and including {IF-PAY-WITH-COUPON-END}) with the code from the Notepad file. After replacing the original code with the new expanded code, scroll to the File Options section at the bottom of the Template Package Sandbox page, select Save and click Go.
Final result
Now, customers must be logged in and must have a current membership in order to view any products in the store. Customers that do not yet have a membership will be able to click a link to add a membership product to the basket, and as long as a membership product is in the basket, new customers will be able to complete the order. If a membership product is not in the basket, customers will only be able to complete an order if they are logged in and have a current membership.
|