Differnt Prices for Different User Groups

Drupal Commerce – Different prices for different customer groups

Posted on Fri, 2012-09-14 09:14

What are we looking to do?

When you have an online store, by default a product has a set price which is what everyone pays. You may have discounts through voucher codes but occasionally you want to offer a different price to shoppers i.e. wholesalers.

So what we will be doing is creating a new role called ‘Wholesaler’, adding a new price field to our product, then we will set up a rule which will calculate the right price for the wholesaler.

The tutorial will be focused around a basic Drupal 7 install with the Commerce module (and the other relevant modules installed).

Tutorial

Create user role

Go to admin/people/permissions/roles and add a new role.

Whenever you have a wholesaler wishing to use the site, you will need to give the wholesaler role to that user.

Set up a new price field

Go to admin/commerce/products/types/product/fields and in the Add new field, type Wholesaler price.

For the field type select Price, then chose the Price with currency widget type and add the field.

On the settings form, it is up to you whether you want to make it required etc. But leave the Number of values set to 1.

Set up the pricing rule

Go to admin/commerce/config/product-pricing and click the Add a pricing rule link.

For the name, just enter Wholesaler price rule.

Under events, it will automatically set the event called Calculating the sell price of a product.

Skip past to the Conditions section and click the Add condition link.

From the drop-down, select Entity has field.

Under Entity, for the Data selector set it to commerce-line-item. From the drop-down this will be listed as commerce-line-item (Product line item).

For the field, select commerce_product. Click Save.

Add another condition, and select Entity has field again. For the Data selector, choose commerce-line-item:commerce-product. In the drop-down you will need to select commerce-line-item… (Product line item) (not the …) which will bring up a few more options, from these select commerce-line-item:commerce-product (Product).

Then in the field box select field_wholesaler_price or whatever you called the field in step 2.

Lastly, had a new condition called and select User has role(s). From the data selector chose site:current-user. You can choose this by going to site:…(Site information) then choosing site: current-user (Logged in user).

Then in the Roles section click your wholesaler role.

Save the condition.

Finally, under Actions click Add action. In the drop down under Commerce Line Item, select Set the unit price to a specific amount.

The Data selector should already be set to commerce_line_item.

Under Amount, click the link which says Switch to data selection.

From the drop down select commerce-line-item:… (Product line item) then select commerce-line-item: commerce-product:… (Product).

Then select your price field which will be commerce-line-item: commerce-product: field-wholesaler-price:… (Wholesaler price). Then select commerce-line-item: commerce-product: field-wholesaler-price: amount (Amount).

Leave the Price component type set to Base price. Under Price rounding mode it is up to you how this is set.

Conclusion

If you now set up a dummy user, give them the role wholesaler and login as them and browse the site, all the prices will now be showing the wholesaler price by default. Log out and the prices will go back to retail prices.

You can set up multiple different pricing structures thanks to Drupals fields module which allows an infinite amount of price fields.

Potential problem

This may cause a few issues for people on how they want data to appear. When a wholesaler is logged in they will see the wholesaler price and not the retail price. If you want to show the retailer price as well you will have to alter your product display template file to show both prices.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s