An OSTraining member asked us about adding barcodes to a Drupal site. They wanted to use barcodes as part of a Point-of-sale (POS) system.
This ended up being a complex task. Several barcode modules are available; however many have not been well-maintained over the years.
After testing, I would not recommend using Drupal's Commerce POS module, unless you are already using Drupal Commerce. The number of module dependencies and dev versions needed to run Commerce POS does not give me a lot of confidence for stability.
Using the Drupal's Barcode module is a better option. This allows you to add barcodes as fields.
You will need the following modules :
If you go to the bottom of the Barcode project page you will see both a stable and dev release. The stable version hasn't updated for some time however the dev version has been recently updated and does appear to be working well.
Going down to the "fields" section of your modules page and you will see the barcode module and that you can enable it here. If you would like to enable examples for the barcode module go down to the "Other" section and you will see the option to enable "Barcode examples". I'm going to enable both modules in this tutorial.
- Go to Configuration > Barcode.
- On this page you can select where the barcodes that are generated are saved. You can also choose which font the barcodes should use.
Now that we have confirmed the barcode settings, let's add the functionality to our site.
- Go to Structure > Content types > Manage fields
- Create the label for the field. In this example, I have called it "basic page barcode".
- In the field type, select the dropdown and you should see "Barcode" as the first option available.
- Save the field.
- This will bring you to a new page where you can define the field settings for the new barcode. As you can see from the image below, the Barcode modules give you access to a series of different barcode types:
Now you have successfully added the barcode to the basic page, let's add a basic page so we can see a barcode on display.
- Go to Add content > Basic page.
- Enter 13 digits for the barcode. This field will only accept numbers.
- Save the page, and your barcode will appear: