Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
If you're using Drupal Commerce to start an online business, you can now go off and merrily add products as you saw in previous videos. But some of you already have inventory that you want to sell through Drupal Commerce. In that case, you either have the data in an online store, or it's in some kind of database, list, or spreadsheet. Now, I can't tell you how to get the data out of some other store system, but I can tell you how to move a simple, tab delimited list of products into Drupal Commerce. For this, we will need to add a few modules. The first one, and most important, is called Commerce Feeds.
You get it by going to drupal .org/project/commerce_feeds. And as usual, we go down here and copy our link, then go back to our site and click Modules, and then click Install new module to install it. Paste, Install, and go. Now, if we go back to enable that newly added module, we will find that we are not able to. Let's go down and take a look. So there is Commerce Feeds, and an example, but we can't actually click it, because it has several requirements.
It needs Commerce Feeds, which in turn has its own requirements. Well, that's okay. We will just go drupal.org/project/feeds. Then do the same thing. Go back to our Modules page, and install that. Once again, we attempt to enable the modules we just added. Nope, it's still not working. We will go down and enable Feeds. Oh, but that in turn requires job scheduler, and back we go.
This is something that you'll find with Drupal sometimes. You have one module that depends on another module, which in turn depends on another one. That's okay; we will get to the end of this. I'm going to go do drupal.org/ project/job_scheduler, and download that. Remember, you have to grab the Drupal 7 version, even though it's an Alpha. Hopefully by the time you watch this, it will be out of alpha, and more ready to use, but I haven't had any problems with it. Back up to the top of the page; Install.
Now I believe we can enable our module. We will find out by collapsing all of these, and there is Commerce Feeds, and Commerce Feeds Example. When I enable that, it asks if I want to enable all of the other parts. The last thing I am going to do is just take a look and make sure that everything is enabled that we need enabled. So down here, Commerce Feeds; very good. We don't really need Commerce Feeds Example. And for feeds, I'm also going to add Feeds Admin UI, and Feeds Import.
Then Job Scheduler is fine, and we're done. Now we're ready to start importing our products. Let's take a look at the controls. There are two parts. First, you set up the import, then you execute it. To set up the import, you go to Structure, and Feeds importers. We have two examples here, but I am going to create a new one, which I'll call a Product import. You need both, a name that you can read, Product import, and then also one for the machine, which is all lowercase with an underscore, and create.
Now, the Feeds module has a lot of settings. I will only change those that are relevant to our particular import, but I definitely recommend you spend some time exploring these controls, and reading the documentation for feeds if you want to know more. That documentation is linked from the Feeds Project page, which is at drupal.org/project/feeds. But here we go. First I'll look at the Basic settings. We don't need to import every 30 minutes; we will just do it once. We're going to change it so that instead of going out to the Web to look for information, it goes to a file.
The parser isn't going to change an RSS feed; instead we are going to be using our Comma Separated Value file, or CSV. For the CSV parser itself, we will change the delimiter to Tab, because that's the way that we have the file set up, as you will see in a minute. Of course, you will make these changes depending on what sort of data file you have. For processor, we are going to change it so that it creates products instead of nodes, and then we'll look at those settings. Instead of having it as an anonymous author, I will change it to admin, and the Product type becomes a Product; very good.
Those are the basic changes. Then there's a few we have to look at the data file itself to understand. I already have that file open here. As I said, our bits of data are separated by tabs, but of course, they could be by commas, or other delimiters between the different fields. Our fields are listed here at the top; the SKU, the Product Name, Price, and Description. This is called the Header row, and you might have noticed that we had to specify that we are using a Header row. Now we go back to our Commerce Product processor, and we will change the mapping so that we know what fields in Drupal are going to be match with what fields in our text file.
The source field -- if we look back here, the first is called SKU, and that gets mapped to Product SKU. We will add that, and then continue with the other fields. The Product Name becomes the title. The Price becomes the Price Amount, and for the Description, we actually don't have any place for it to go.
Remember, the description shows up in the product display node, not in the product itself. So we will actually come back to that in just a minute, because we're also going to repeat this import for the node, so that we can display the product we've created. So we save this, and now we are ready to import. To do so, go up to the name of your site, slash, import. There is our Product import, I select it; look through the different settings. Yup, TAB delimiter; looks good. There are headers, that's unchecked, so now all we have to do is choose our file, and click Import, and when it's done, we see that three items were imported.
We can check this by going up to Store, and Products, and there they are: Guided tour of our orchard, Friday- night concert, and Night in our lodge. So now we have our products in Drupal Commerce, but if you've been watching the series this far, you know we have to create the product display nodes as well. But that's okay. We can use the same exact procedure, and in fact, we will use the same data file. We will just match the products to their nodes using the SKU field. To do that, once again, we'll create an importer. Go up to Structure, Feeds importer, and New Importer.
We're going to call this Product display importer, and save. Once again, we have to change many settings. I will just go through this quickly.
Finally, we get back to our mapping. To see what the mapping will be, once again, we'll look at our text file. So the first one is SKU; paste it in there, and this one actually gets mapped to two different places. First, it gets mapped to the SKU as you'd expect, but it also gets mapped to something called the GUID, which is a Global ID, and I will add that. Then we go back and map the other parts. Product Name goes to the title. The Price doesn't go in, because that showed up in the product, not in the product display node.
However, the Description goes to the body. Now we're ready for our import. I'll save that, and go to slash, import. This time we are going to import Product display. Make sure that we have the file we want, I will go up and find it, and away we go. There; three items were imported. We go back to our front page, and we see them right there. Because we had no images for them, we have this default image; that's all good, and we can add them to the cart, just like any other product.
If we go in and take a look at the nodes themselves, they work fine. That worked pretty well, huh? But the truth is, a lot can go wrong. Here are some of the biggies. The first common error is when you have malformed separators. That's when you put in a comma when you're expecting a Tab, or if you have quotes in the wrong place, and Feeds importer thinks that that's the end of a field. The second big error is if you misspell a header. That's why you saw me often go in and copy and paste, even if it was something very simple like SKU, because I wanted to make sure that I got it exactly right, otherwise Feed importer simply won't work.
Finally -- and this is a biggie -- if your file has non-UNIX or Linux line endings, as you sometimes get in some text processors on Mac or Windows. That commonly comes up if you save the file into Excel, and then save it out as an Excel text file. I have to tell you, I've use the Feeds module a lot, and I have run into all of these problems when I started out, but when it works, it is beautiful. I recommend that you run a few small test imports before bringing in your entire inventory file, so you'll be able to tell whether errors are caused by your procedure, or by issues in the data.
As always, backup your site before attempting any big imports or other changes.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 98739 Viewers
80 Video lessons · 141629 Viewers
59 Video lessons · 59969 Viewers
52 Video lessons · 73133 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.