Creating a book catalog with Drupal and the CCK, Views, and Amazon modules

Print Friendly

Effective January 1, 2010, this site does not use Drupal and instead uses only WordPress. Some of the links below may not work.

I set up a little project for myself this weekend: how could I use Drupal to put together a catalog of my science fiction and fantasy books for my website, and do this as efficiently as possible? I also wanted to have the book information link to Amazon so people could learn more about the books and possibly purchase them. Note that this is in addition to my listing of Hugo and Nebula award winners for best science fiction and fantasy novels.

My experience with Drupal was basic but not completely elementary. All the non-blog content on my website is in Drupal and I know enough about looking for and using modules (addons) that can give me more functionality. However, not all the modules are well documented and using them together can be an interesting learning experience. I chose this project to provide that and to play with some ideas that might be the foundation of later projects. If you are looking at doing a similar project, I hope this gives you an idea where to start. I’m still early in this, so this final catalog may very well change in structure by the time I’m done. The way I make it will get better too.

Let me begin by thanking the people who pointed me in the right direction on Twitter: Amy Stephen, David Wheeler, David Lanier, Bob Morse and Dave Reid.

At the moment, by catalog listing is pretty basic:

Screen shot of book catalog

To cut to the punchline: there is no ready-made solution, but it is not hard to build one using the CCK (Content Construction Kit), Views, and Amazon modules for Drupal. These are all very powerful, but of the the three, the Amazon module is the least well documented. I should also add that I’m using Drupal 6 here in September, 2009. Drupal 7 is on the horizon and I know that some things from CCK, at least, will be shifting into the core.

The basic idea is that you need to create a new content type to hold your book data. Drupal comes with several more or less built-in content types like blog entries, pages, and stories. (Drupal is infinitely flexible and wonderful, but some features and capabilities are not enabled by default.)

You create a new content type in Administer > Content management. After playing around with this for a while and experimenting with the Amazon modules, I decided that I just needed four fields:

  • ASIN: this is an Amazon unique identifier, and in the case of a book is the same as the ISBN-10 number
  • Title: though I can get this from the extracted Amazon information, it is useful to be able to know which book I am editing since the ASIN is rather cryptic
  • Category: this is the Amazon category of the book such as Entertainment, History, Politics, or, in my case, Science Fiction & Fantasy. The list is often displayed in the left column when browsing books in Amazon. This information is not available in the information retrieved via the ASIN, so I’m adding it manually.
  • Status: this is “Read”, “Reading”, or “Unread”. I own all the books, so this simple scheme suffices.

If you look at the screenshot, all information other than the category and status are gotten via Amazon look-up based on the ASIN, including the book cover images.

Here are some of the things you need to do:

  • Install Drupal and get a basic understanding for how it works.
  • Install and enable the CCK (Content Construction Kit), Views, and Amazon modules for Drupal.
  • Via Administer > Content management create a new content type called Book Information. The fields are listed above. The title is the default node title text; the ASIN is an Amazon item; the category is a text field using the checkbox/radio buttons with 1 value allowed; and the status is the same with the three values shown above. The title is always required and make the others required as well. I made the default value for category “Science Fiction & Fantasy” and the default status “Read.”
  • Now go to Create Content and make a few nodes. That is, add a few books of Book Information content type. Look up the ASINs on Amazon and enter the title. As I said above, the ASIN for a book is the same as the ISBN-10 value. For titles, move beginning words like “The” and “A” to the end, as in “Curse of Chalion, The”. This will help the initial sorting.
  • So now we can create the content and we have a dedicated type. We need a view and a page to show it. I’m still tinkering with this, but go to Administer > Site building > Views to get started.
  • Click on Add on top and enter a view name and a description. Create the view as a Node (ignore the Amazon item option) and hit the Continue button.
  • Most of what you’ll be doing in Defaults but create a page to Display in the upper lefthand corner. On the lower left where it says Path: None, click the None and add a name so that you can access your page. In the Basic Settings area you click on the values to change them, just as you did with None. While still on the page, change the Title to something interesting. I used “My Science Fiction and Fantasy Library”.
  • Go back to the upper lefthand corner and click Defaults.
  • The most important thing to do, and the thing that took me the longest to figure out, is to click the “+” next to Relationships in the top middle. Click the box next to Content: ASIN and Update and Save. This now makes a lot of extra fields available to you, all created via the ASIN from information retrieved from Amazon.
  • You will now add seven fields in the middle Fields section:
    (field_asin_asin) Amazon: Product image
    (field_asin_asin) Amazon: Title Title
    (field_asin_asin) Amazon: Participant name Author
    (field_asin_asin) Amazon: Publisher Publisher
    (field_asin_asin) Amazon: Pages Pages
    Content: Category Default
    Content: Status Default
  • The first 5 are all generated from the ASIN, and the category and status are our regular content fields. Note that I changed the display name of “Participant name” to “Author”. Again, you can see these in the screenshot above. I did not put a label on the small image since visually I associate that with the title. Note that I am not using the title field that we manually defined, I’m using the title as gotten from Amazon via the ASIN.
  • Make sure you keep hitting Update and Save as appropriate. If you don’t, your changes will not be preserved.
  • Generally you use the “+” button in each of the sections and the up-down-arrows button to change the order in which information is displayed or processed.
  • My Basic Information section looks like:
    Name: Defaults
    Title: My Science Fiction and Fantasy Library
    Style: Table
    Use AJAX: Yes
    Use pager: Yes
    Items per page: 25
    More link: No
    Distinct: No
    Access: Unrestricted
    Caching: None
    Exposed form in block: No
    Header: Full HTML
    Footer: None
    Empty text: None
    Theme: Information
  • Click the little gear button after you have changed the style to Table. This allows you to do fancy things with the columns (such as combine them) and make them sortable. All my columns except the image one are sortable.
  • The pager option lets you put only a subset of the book entries on a page, and then adds “previous” and “next” clickable text at the bottom of the page. I have it set to show 25 items per page.
  • My Sort Criteria section looks like: Node: Title asc and this is the only use in the view of our basic title content field. Since we moved the “The” and “A” words, the initial sort will be correct. If you start clicking the columns to sort, the definite and indefinite articles will be used in ordering the titles, unfortunately.
  • Finally, I have three filters:
    (field_asin_asin) Amazon: ASIN not empty
    Content: Category = Science Fiction & Fantasy
    (field_asin_asin) Amazon: Participant role contains author

    This means that we only want entries that have Amazon items (ASIN not empty), in the “Science Fiction & Fantasy” category, and the participant we list is the author. Note that multiple authors or others such as illustrators will each be displayed in separate entries, by default. There is a more general participant field, but for some reason it is not sortable. I’m still working on this. My sense is that I should first be checking for the correct content type, but the ASIN being non-empty works for now. Note to self: fix.

I think that’s about it. Go the URL of the path you entered and look at your work. In fact, do this as you go along.

As I said, I’m just getting into this and will undoubtedly change things as I learn more. Suggestions for corrections and improvements in the comments are very welcome. I’ll eventually give an update when any new and improved version stabilizes.

Let me reiterate that the relationship connection to the ASIN was key to making this work.


2 Comments

  1. I saw your tweet a few days ago about starting this. At one point I had started to put together a catalog site for my books, but gave up because I couldn’t find an appropriate solution (this was about 4 years ago). I’m not really familiar with Drupal, but after the tweet I searched through their add-ons repository for book cataloging solutions and found a number of modules for libraries and book cataloging. Care to elaborate on why you chose this particular solution over some of the existing ones?

  2. Ultimately it was because I wanted to play with CCK and Views, and the Amazon module appealed to me since I had been playing with various Amazon Associates tools. I wanted to enter a minimum of data (such as the ASIN) and get the information supplied from elsewhere.

    If something better comes along, especially for D7, I’ll be happy to look at it.

Comments are closed