Drupal Commerce: A Flexible and Powerful e-Commerce Solution

Submitted by Luke Dekker on 07/19/2016 - 12:23:pm

One of the biggest and fastest growing aspects of the web today is online stores. There are plenty of services that will integrate with your website to allow users to purchase content from your website. Services like Magento and Shopify allow for you to place products on your site for customers to purchase, but they are fairly limited.

We recently built an e-commerce that wanted users to be able to call in and have employees place orders for them. Employees placing orders were given different informational prompts, and fields, along with a way to do real-time price adjustments to the order. They also allowed users to use coupons which would update the order total, give them free shipping, or even add a free product to their cart.

Price Adjust in Drupal Commerce

Here is a brief, step-by-step explanation of how I implemented this price adjustment functionality:

  1. First create a new product type: Admin > Store > Products > Product Types > Add a Product Type. I named mine “Price Adjustment”.
  2. Create a new line item type Admin > Store > Configuration > Line Item Types > Add a Line Item Type (Requires the contrib module commerce_custom_products).
  3. Add a price field to the line item and check the box to display that field on the add to cart form.
  4. Next, you need to create a product. Give it a price of $0 and an SKU along the lines of PRICE-ADJ.
  5. Now we want to create a view (block display) of products and limit by type of Price Adjustment Products. Make sure and set the view to render the add to cart form.
  6. Now, wherever place that block, users will be able to enter a price adjustment (either positive or negative) and add it directly to the cart. It’s advisable to add some permissions checking on the view to ensure that only people who are authorized to make price adjustments can see the block.
  7. At this point, you may notice that if you add a price adjustment product to your cart, it has a price of $0, which we set above. This doesn’t do a whole lot. The last piece of the puzzle is to create a rule to set the price of the line item based on that field that we entered the price into.

Go to Configuration > Workflow > Rules and create a new rule. The event for the rule should be “Calculating the sell price of a product”. You’ll need to add conditions for the bundle of the line item, and then make sure that the field isn’t empty. Once you’ve confirmed that the price adjustment field isn’t empty, then you can set the price of the line item to equal the value entered into the price adjustment field.

And Presto – you should now be able to manually adjust the price of an order to suit your needs!

*If you haven’t already, you’ll need to install the Rules and Rules UI modules.