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.
User/Role expiration AdministrationIf for whatever reason, you need to manually add/edit/view role expirations that occur within your site, the Roles module helps you accommodate this. For viewing any role expirations you can browse to Administer â€º User management > Users > Role expiration. On this page you will see all role expirations that are set to occur. From this page you can view people's user page, edit their role expirations, or delete their role expirations.
Customer NotificationAt this point, any customers that purchase the product should have a new role once their order goes into the status you have specified. From here it is up to you to set up a workflow configuration that will move the order into the correct status once a customer has paid. If you wish to send the customer a notification about new roles, you can do so with the built in notification support. To do this make sure you enable the Notify module in the same place where you enabled the Roles module. After the Notify module is enabled, you can browse to Administer â€º Store administration â€º Configuration > Notification settings > Role assignment where you can set up the email templates that will get set out to the customer once they complete the sale. On this form you will see four links, each dealing with a different notification: new role assignment, expiration of a role, renewal of a role, and a reminder message of a pending expiration. Three of these message templates are the same; checking the box will allow a message to be sent at role granted/expiration/renewal. The fourth is slightly different in that you specify the amount of time before an expiration occurs that a user is notified. Setting this to "never" means a user won't be sent a reminder message about a role expriation. Everything else is the same in the message templates. The token [role-expiration-short] and [role-name] contain the expiration date and the role name, respectively. Other tokens will let you customize the message further (a link in the notification form will describe each token you can use).
At this point you should know everything there is to assigning roles to your product.