Using Textpattern to manage an e-commerce website
When it comes to blogging software, Textpattern is one of the most popular open-source solutions, frequently mentioned in the same breath as those other market leaders, Wordpress and MovableType.
It is undoubtedly one of the best choices to make to run a simple blog, but how does it compare to the bigger purpose-built CMS when it comes to running a commercial e-commerce website?
NB: This article refers to Textpattern RC3. Download it here.
The benefits of Content Management
By creating a separation between the maintenance of the content of a website and its underlying code, we as designers/developers can ensure that our clients (even the most technically-illiterate!) are able to easily manage their own sites; they feel more in control of their own online presence, and are not forced to wait to update content; while on the business side, we avoid the constant requests to make minor changes to content after launch, and can concentrate on the important bits and pieces – such as the code – which is made easier by the built-in functions of the CMS; no more database design or writing complicated SQL queries, as the CMS handles all that stuff.
The more advanced types of CMS (retailing for tens of thousands of pounds) feature a multitude of advanced features, such as integrated workflow engines to manage sign-off procedures, complex document and image libraries, and of course 24/7 technical support helplines.
But before we look at which of the above Textpattern does for free, let’s first run through a few things it doesn’t do.
What Textpattern cannot do
If you’re operating an e-commerce website, you are by definition selling products from that site. Whether they will be downloaded or delivered is not important – Textpattern does not currently include a means to manage an online shopping experience (and I suspect adding that sort of functionality would be more than a simple plugin could handle). So an alternative means of handling shopping baskets and checkout will have to be found – PayPal is a good place to start, although there are other providers out there.
Textpattern is also missing a user management function, so that too must be handled by a third-party service like PayPal.
Apart from those two biggies, everything else you would expect to find on an e-commerce site – products, categories, prices, stock, reviews – is possible; so let’s get straight into it!
Establishing a taxonomy
If you have used Textpattern in the past for its intended purpose – running a blog – then you will be familiar with the terms it uses and what they mean.
On the public-facing side, you write
- articles which are classified within
- categories and published within
- sections; these articles may receive
- comments from site visitors.
You can also upload
- images and
- files
and write much shorter entries known as
- links
Behind the scenes of the site, each
- section uses a
- page as its template; these pages can include
- forms, which are smaller sections used to manipulate and display articles, categories or comments
So that’s how it comes, out of the box. Obviously that classification would make little sense for an e-commerce site, so let’s re-assign our labels to help build a mental picture of how the site is going to hang together.
Articles
Each article is an individual entry, the core unit of the site. These will be our products. The fact that they also have published dates and variable statuses (Draft, Hidden, Pending, Live, Sticky) can be used to launch new ranges without manual intervention, or to temporarily remove products that are out of stock.
Sections
A section defines the area of the site where the articles can be found. On a blog these might be ‘About Me’, ‘Latest News’, ‘Photolog’ – the e-commerce equivalent is the product range.
Comments
Comments are individual entries from other people attached to individual articles. Or in other words, reviews.
A short word about Categories
You may be tempted to try and use Textpattern’s categories to categorise the products. Unfortunately this doesn’t work; the categories are really only a secondary way (sections being the primary way) of classifying articles, and do not control where articles will appear on the site.
They can however be used to group related items together, for example to provide a “You might also like” cross-sale feature.
Custom fields
Okay, so now we know what to call everything, let’s get started with creating our online shop. The first thing we need is some products.
The basic article comes ready made for blogging, with a Title, a Date and not a lot else. That’s where the new custom fields in RC3 come into their own. Open up textpattern/lib/admin_config.php in a text editor and about half-way down there are 10 custom fields that can be used to store additional meta data about our product:
'custom_1_set' => '', 'custom_2_set' => '', 'custom_3_set' => '', 'custom_4_set' => '', 'custom_5_set' => '', 'custom_6_set' => '', 'custom_7_set' => '', 'custom_8_set' => '', 'custom_9_set' => '', 'custom_10_set' => '',
Simply enter the name of the extra information we will need – price, shipping cost, colour options, whatever – and save admin_config.php. Our new fields are now available under ‘Advanced Options’ when creating or editing an article/product entry.
To output the contents of a custom field (to display the price of a product in a form, for example), we can now use <txp:custom_field name="price" />.
txp:output_form is your friend
As we mentioned above, the Textpattern sections have now become our product ranges – Books, DVDs, Clothing, whatever the store offers. Each range must have its own page, or template, to output the products found within that range. Unfortunately this means that the list of pages can get rather long if you have a large or diverse store, so it is important to have a strategy to reduce the work involved in making changes to those product pages.
The <txp:output_form form="formname" /> tag simply returns the contents of the named form. In this way it functions much like a PHP or ASP include statement, so we can move common page elements like the page header or footer into a form for easier maintenance.
Built in PHP functions
While not specific to working with Textpattern, it is worth covering a few PHP functions that can be very useful when working with product databases.
getimagesize()
This function returns an array of the width, height, type and HTML string of the referenced image. It can be used to bicubically resize product images to artificially restrict them to a certain width and/or height.
if_file_exists()
This function does exactly what it says on the tin. It returns boolean true if the referenced file exists, or false if it doesn’t. It is useful for excluding products without an associated picture.
Shopping integration
The most common method of integrating a third-party shopping service like PayPal into a site is by including HTML forms that pass variables relating to the products to the third-party site. This is simple to achieve with Textpattern; simply create a form (or use an existing one) called ‘Single’ – this will contain all the information to be displayed on a single product page.
Within the form, include the HTML form code supplied by the third-party supplier; PayPal’s code looks like this:
<form action="https://www.paypal.com/cgi-bin/webscr" id="add" method="post"> <fieldset> <input type="image" src="/images/add-to-basket.gif" name="submit" alt="Add <txp:title /> to your shopping basket" /> <input type="hidden" name="add" value="1" /> <input type="hidden" name="cmd" value="_cart" /> <input type="hidden" name="business" value="example@example.com" /> <input type="hidden" name="item_name" value="<txp:title />" /> <input type="hidden" name="shipping" value="0" /> <input type="hidden" name="no_shipping" value="2" /> <input type="hidden" name="amount" value="<txp:custom_field name="price" />" /> <input type="hidden" name="return" value="http://www.example.com/completed" /> <input type="hidden" name="cancel_return" value="http://www.example.com/cancelled" /> <input type="hidden" name="currency_code" value="GBP" /> </fieldset> </form>
Notice how we can use Textpattern’s article tags like <txp:title /> to dynamically populate the form fields. Now any new products will automatically be available to purchase online.
Customizing the admin interface
Of course it is no use delivering an easily manageable website to our clients if they are unable to work out how to use it! Obviously some sort of User Manual will be required, but there are also a few easy steps we can take to make our clients’ lives easier.
Perhaps the easiest is to change the tag headings in the admin interface. We have already discussed our new taxonomy, so open up textpattern/lang/en-gb.txt (or your own language file, if different, find the entries that start “tab_” (they are listed alphabetically) and amend the relevant items. There are a few other entries that would benefit from a slight change, notably the “Article saved…” ones (“Product added”?)
Check through the whole language file, making any amends necessary to better represent an e-commerce site rather than a blog.
Last things to remember
Textpattern comes with a few settings switched on for bloggers by default that we want to turn off. Turn off ‘Update Ping-o-matic’ in the admin panel, and also check through the settings in textpattern/lib/admin_config.php for anything that may cause issue for a non-blog.
Conclusion
Aside from the obvious lack of shopping cart functionality (although aside from products like osCommerce there are no CMS that boast this), there is nothing to stop you using Textpattern to power a multi-product, multi-range e-commerce website; and with some fairly simple plugins additional functionality, such as saved user information, could be added.
It will never be capable of running Amazon, but Textpattern is certainly a viable alternative to other non-blog CMS.