Originally this post was planned to be a part of building a Drupal website from scratch series post, I did in late 2013. For some reason this post was left unpublished, so today I decided to review it one more time and make it public.
In this article, I'll show how to create simple, but powerful booking engine for fictional tourism company's webpage using Drupal.
Part 1 - Modules
- Download References module
- Node Reference URL Widget
- Extract modules to sites/all/modules
- Enable modules
Part 2 - Content type
I'll use a custom content type - to serve bookings.Go to admin/structure/types/add and create a new content type: Bookings
Next let's add some fields to our new content type: First name, Last name, E-mail and to make a reference work add a reference field:
Settings for reference field: Label: Booking, Field type Node reference, Widget Reference from URL, hit save.
In the next window you will be asked, which content types you would like to reference:
Part 3 - Views
By right now, we have done 2 great things: Enabled necessary modules and created a booking content type.
But how to make them actually work on our tours? By using views and displaying created views as blocks:
I decided to create a view, which contains - Photo, Price, and Booking reference URL:
As you can see from the picture above, the view is not fully themed yet (CSS) but it does show pictures, price and Book this tour (by pressing which, booking reference would be called, like this:
OK, back to views:
Create a new view - call it - Tour Header
Add fields: Title, Price (if you have it), Booking, Photo, NID and 2 times a Custom text:
Why do we need a NID field?
- By using Nid field, we are going to pass URL from our tour to booking.
Why do we need 2 Custom text field?
We are going to use a first custom text field, to create a link to a booking page, but a second custom text field we will use, to override the display of our container.
Make sure Custom text field, which will contain our overrides is the last one in a row. Exclude from display all other fields, expect last Custom text field:
Create a URL with reference to booking page:
Open first custom text field and override it:
Here you can see, how I applied - Book this tour, and how I turned it to url. Note that we are using :node/add/your-content-type/[nid] to reference a node. Field [nid] is unique URL identifier.
And now let's override all display in last Custom text field:
Save the view, and head to block (admin/structure/block), find the newly created block and put in your content section, to make it work.
It's up to you to apply CSS styles.
To make it more convenient, you should think to apply Date to booking content type, so the customer can enter dates. You should apply also some Rules like to end e-mail when a new booking is created.
If you need any assistance of creating this simple, but yet powerful booking engine, let me know by leaving a comment or contacting me.