EnablingInstead of creating a product that is exclusive a role product, Ubercart uses its product feature system to attach role assignment to any product. This way if you wanted to offer a tangible product as well as exclusive access to the site, you could create your standard product then attach a role assignment feature to it. To get started, enable the Roles under Administer > Site building > Modules. Check the box next to Roles and press the "Save settings" button.
PermissionsAfter enabling the module, the next step is to set permissions with the Roles module. Do this by browsing to Administer > User management > Access control. This form will show you all the roles on your Drupal configuration and what permissions they have. You will want to scroll down to the permissions for the uc_roles module. Here you will see one permission for "view all role expirations", this will give a user the permission to view any role expiration on anyone's user page. It is recommend that you only give this role to a site or store administrator.
SettingsOnce the module is enabled, it still needs to be configured to work. If you haven't setup the module you will see a warning message at Administer > Store administration
The Roles module is set up under Administer > Store administration > Configuration > Product settings > Product features. You should see a link that says Role assignment settings, after clicking the link it should open up a form to specify settings for the Roles module. It's here where you'll set the following settings:
- Order status
- This specifies when to grant the role to the user; when an order status reaches the status specified the customer will be granted the role. By default, this happens when the order goes to Completed status.
- Default expiration
- This is the default expiration length of role assignment features when a store administrator begins to add a role assignment to a product.
- Default role
- This is the default role the role assignment feature grants when a store administrator begins to add a role assignment to a product. If this blank, you will need to select roles to use in the Product role form field below.
- Product roles
- These are the roles that can be used for role assignment features. If there are no roles listed here you will need to add a role under Administer > User management > Roles.
- Show expirations on user page
- If this box is checked, any expirations of roles is displayed on a customer's user page (My account).
- If "Show expirations on user page" is checked this is the header that shows on the user page. Depending on what you call access to your site, you might want to change this text.
- For each role expiration a Title & Message is displayed. By default, the title is the name of the role that is expiring.
- The message informing the user of the expiration of the role. By default, the message is "The role will expire on !date" where "!date" is formatted string containing the expiration date.
CronIf you have any role assignments that have expirations you will need to set up a cron job to run on your site. For more information on to configure cron jobs, see configuring cron jobs on drupal.org.
Adding Role Assignment to ProductsFrom here you need to start adding role assignment features to your products. This tutorial assumes the reader already knows how create an Ubercart product. If you do not you can reference ubercart product creation. Once your product is created you should see a "Features" tab on the product edit page. After clicking the "Features" link, you'll see a empty list of product features. Select "Role assignment" from the Add a new feature select box and click "Add".
The next step is to fill out the feature form with the following details:
- The Model/SKU of the product that grants the role assignment. If the product you are selling is solely a role assignment you'll want to keep this to "Any". If however the product you're selling has different SKU adjustments you might only want to grant a role assignment on a specific SKU (e.g. you sell a product with an attribute that can add optional access to website forum).
- The role that will be granted when a customer purchases the product.
- Time until expiration
- How long the role will last. If set to "never" the role will never expire. The expiration date is set based on when a customer is granted the role.
- Shippable product
- This checkbox specifies whether the product associated with the role assignment is shippable or not (if there are no shippable items in a customers order he won't be asked for a shipping address at checkout). If there is a shippable product included with this role assignment you will need to check this box, otherwise leave it blank.
- Multiply by quantity
- Checking this box will specify whether the product qty affects the role expiration length. In other words, if a role assignment attached to a product lasts for a year, buying 10 products will make the role last for 10 years. If a role assignment has no expiration this option has no effect on the role assignment. It is set by default.