In this section we'll look at two different approaches for organizing customers into groups. First, we'll look at how user roles can be used to limit access to discounts or other functionality within Drupal Commerce. Then, we'll look at how taxonomies can be used in situations where the number of different groups makes the user role approach impractical.
If neither user roles nor taxonomies provide enough functionality for your needs, there may be a contribued Drupal module that would work. See the User management modules listing.
You can use User roles to organize customers to limit access to payment gateways, promotions, or certain fees/charges based on customer type. Drupal Commerce provides plugin-based Conditions functionality and includes a condition for Customer role. As an example, let's suppose we have a select group of wholesale customers that should receive a 10% discount on all products. Here's how we could set that up:
You will also need to assign this role to the appropriate customers by editing their Customer accounts at
/admin/people. You can make bulk assignments by using the checkboxes to select customers and selecting the appropriate option under the Action menu:
If you have a high number of different customer groups, creating a user role for each might not be practical. For example, suppose you sell products to individual customers at universities. You might want to track sales based on university or provide discounts to specific universities. Creating a Universities taxonomy and populating it with the names of all your university customers is a good way to handle this.
This University field will now appear on user account edit forms, and customers will be able to enter their own universities. If you do not want customers to have access to this field, you can use the Field permissions contrib module to provide that functionality. Also, you might want to consider using Profiles to store the information instead of customer accounts, depending on what other information you might need to capture. The Profile management documentation page describes how the Field permissions module can be used to limit access to certain fields.
Once you've created your University field, it can be added to Order views and sales reports. If you need to create discounts based on a customer group taxonomy like our Universities example, you'll probably need to look for a contrib module or create custom code. A condition for customer groups based on taxonomies does not exist in Drupal Commerce core. If you decide to write custom code, take a look at the Product category condition that's provided by the Product module. Specifically, you can use the code in the
OrderProductCategory plugin and the
ProductCategoryTrait trait as a starting point.
Found errors? Think you can improve this documentation? edit this page