Ready to watch this entire course?
Become a member and get unlimited access to the entire skills library of over 4,900 courses, including more Business and personalized recommendations.Start Your Free Trial Now
- View Offline
- Surveying the store-building process
- Installing Drupal Commerce using Commerce Kickstart
- Accepting PayPal payments
- Processing orders
- Understanding rules and line items
- Listing and importing products
- Managing inventory, orders, and customer profiles
- Streamlining the checkout process
- Launching a store
- Offering product discounts
- Analyzing site traffic with Google Analytics
Skill Level Intermediate
Part of Drupal Commerce Kickstart is a Drupal Module called Rules, which is available separately at drupal.org/project/rules. A lot of Drupal Commerce's functioning depends on the Rules module. For example, it comes with a rule that sends the customer an e-mail message when checkout is completed. You'll see rules a lot as we go through the course. I want to just take a moment now to show you how the module works in general. Now, unless you're experienced with Drupal administration, you'll mostly only deal with rules as you configure your store.
They show up in several places. One of them is related to something we already started playing with; taxes, and we can see that by going up to Store, Configuration, and Taxes. Here's our Flat 8% tax we created earlier. Let's click edit, and take a closer look at it. This is fairly simple. You get to define the rate, and what type of tax it is, as we described. But if we go back a screen, and then click configure component, we see some of the inner workings, which are a little more complicated. This is where you can add conditions.
Let's take a common one. Let's say that our store is in Ohio, and U.S. tax laws say that we only have to collect state sales taxes for sales that are shipped to addresses within that state. So we only want to apply the sales tax when an order is being sent to an address that's inside Ohio. If we look here, we see that there's a Condition section. This is where we're going to add the condition to check to see if it's in Ohio. Most rules also have a section up here; Events, and we'll get to that a little bit later. And as I said earlier in the course, actions defines exactly what happens when the conditions are met.
For now, we'll just click Add condition, and the condition we are going to add will be an address component comparison. This Data selector area is quite complicated; there is a few different ways that you can do this. You can type things in, you can choose them from a list, and if you click and open this Data Selectors, it shows you all of the different options. If you want more information about how all of this works, I would suggest that you take a look at the Rules documentation, which again, you can get to at drupal.org/project/rules. But going down, let's take a look at what our values are. We are going to take the billing information, it will be the state or province, and the value has to equal Ohio, and then save.
Now if we look again, we can see it describes exactly what we're going for. Now, let's take a look and see if it worked. I'll close out this overlay, and we already have an item in the shopping cart which I added previously. Take a look at the cart. Okay, there it is, $8, and let's check out. Now at this point, we're going to add our address in the billing Information. So Tom Geller, Address 1, let's just say, 1 Main Street, Oberlin, Ohio, 44074. Now, if I did this correctly, I should be charged tax.
Let's continue and see, and indeed I am. There is our 8% sales tax. Let's go back and change that address to something in New York, in which case it shouldn't actually charge us the tax. So I'll go back and let's say 1 Spencer Street, Mount Kisco, New York, 10549, and continue. Indeed, it worked; we're not charged tax. Now I want to go back a little, and show you some of the complexities of rules.
We won't be able to go into the details, because there really are a lot of them, but I am hoping that a little more exposure will help you debug rules that don't do exactly what you expect. To show you that, I'll go up to Store, Configuration, and Product pricing rules, and let's take a look at our sales tax calculation here. Now you see that little extra bit at the top, the Events section, which I mentioned earlier. Here you can change when an event occurs; when a rule is triggered, so to speak.
Let's take a look at that. One example that's sort of outside of the whole world of taxes is this After adding a product to the cart. You could, for example, ask the person, would you like this to be gift-wrapped? Pop up a window, or something like that, each time that they add a product to the cart. Similarly, you could change how and when Drupal Commerce calculates shipping charges, and anything else that happens on the site. To see all the rules at once, click Configuration, and then go down and click Rules, and there's your introduction to rules.
If you want to dive deeper, check out the project's homepage at drupal.org/project/rules. To really understand them, scroll down, and click Read documentation. That leads to this URL: drupal.org/node/298476. It happens that Rules has a very active development community, and this project page also has links to a FAQ -- a Frequently Asked Questions page -- and even to a discussion group. Chances are, you won't need this kind of help when you first set up your store, but it is good to have, and it's a great example of the strength of the open-source Drupal community.