Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
What you're about to see might be the most powerful video of the entire course. That's because you're going to learn about one of the systems that underlies your entire store, and once you understand how it works, you will be able to change the organization of pretty much everything in it. This magical system is called views, and it's included as part of Drupal Commerce. Views is the single most popular extension to Drupal, and it's quite complex. This video gives you only a peek into its power, but it'll be enough to let us see at a glance how many of each product we have in stock.
First, let's look at how we see products by default. To do that, we go to Store, and Products, or of course, we could just click View products. In the video about managing inventory, we added a module that keeps track of our holdings, but we don't actually see that in this list. We look at any particular product, say by editing Olive oil; there is our Stock field. But let's go back to our list of products. One thing you might not have noticed throughout this course is when you move your cursor over it, you see this little gear up here.
This is what's called a contextual menu. It lets you edit the view that you're seeing here. You see, this list is actually just a simple view, which you can edit. So we go up, and click it, and Edit view. By the way, there is another way to get there. You would click Structure, and Views, and then find the view that you want. To tell you the truth, I prefer to do it through the contextual menu, because then I know exactly what I'm editing. The way we are going to add that field is actually fairly simple. We go down here to this Field section, and click add. I am then going to do a search for stock, and there it is; Commerce Product: Stock.
Add and configure fields. I'll just leave it in its default, and then before you do anything else, you might want to see what it looks like. So we will scroll down, and look at the preview, and there's our stock. If we wanted, we could move it around by clicking rearrange. Let's say, move it up a little bit, and apply it. All sorts of things you can do in views, but before we go, we have to save it. So scroll up to the top, and click Save. Now as you see, we are here on our View products list, and there's our stock. The great thing is, you can do this on just about any screen in your store, and with views, you can do a lot more than just add fields.
Here; I will show you with the order screen. We go to View orders, and then click this contextual menu to edit the view. Here I am going to change the filtering, so we are going to add an exposed filter. Click add, and add order total. Again, I just happened to know this, but you could scroll through and see which one you wanted. This is the one I want. So I will add and configure. I will expose this filter, and say that I only want to see those orders which are, let's say, greater than 10, and apply.
By the way, I am doing a mistake here, which I will show you in a minute. If we scroll down to the bottom here, we see we now have this filter available to us. Let's go ahead and save, and see what that looks like. Again, if I click View orders, there it is. I can change the filter here, like let's say we only want to see things that are above 20. That should cut out this one that's $19, right? Oh! But it didn't. So I must've done something wrong. Let's go back in and check. Edit view, go down to our filter, and edit this particular one.
Now, as it turns out, the thing that you need to know is that it's counting by pennies, not dollars. This is the kind of error that will drive you crazy when you go through it. The thing I would recommend is go and take a look at the documentation that's either on drupalcommerce.org, or drupal.org/project/views. I am going to change this so that it shows us $10 by default. Then I will go back up and save it. Now if I want to see only those things that are above $20, I'll enter 2000, and apply, and indeed, everything below $20 drops out.
But you know what? I don't think I like having this available. Fortunately, I can revert it back to its factory settings. So once again, I'll go up to my contextual menu, and edit the view. Now, here I will notice, the name of the view is Orders (Commerce Order). In order to change this view, I have to go up one level to where it shows all the views, and then find that one. Orders, yep, that looks like the one. I will go back here, and choose revert. Yep, that's really what I wanted to do. Now if I go back and view orders, it's as it was before; there is no filter.
I do have to warn you, though: you can't revert views that you specifically create, and as you can see, you can get yourself into a lot of trouble with them. If you really want to play around with them, I strongly recommend you watch my Drupal 7 Reporting and Visualizing Data series on lynda.com. It's really amazing what you can do with views, though. You can, for example, create a map of all of your customers' shipping addresses, add totals to the order page, and so much more. You don't need to do that to run a successful store, of course, but the flexibility that you get with views is worth the learning curve.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 74456 Viewers
80 Video lessons · 129690 Viewers
52 Video lessons · 63925 Viewers
59 Video lessons · 49717 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.