Get Adobe Flash playerPlugin by wpburn.com wordpress themes

Archive for the ‘Programming’ Category

TYPO3 4.2 E-Commerce book cover image I was recently asked to review a new book from Packt Publishing, TYPO3 4.2 E-Commerce, written by Inese Liberte and Edgars Karlsons. TYPO3 is an excellent content management system designed for all types of websites, but there is very little information about building e-commerce shops – until now that is. While my TYPO3 experience is very recent, my e-commerce background dates back to late 90’s – so I was very excited to read this book.

First, let me state that although the book title implies the book is written for TYPO3 version 4.2 (which is deprecated now), the content applies equally well for the most recent version of TYPO3 4.4 (same is the case for my book). Second, I expected this book to be targeted at TYPO3 integrators – programmers who need to set up shops. Instead, this book is aimed at small, DIY business owners, trying their foot in e-commerce. The preface promises to walk the reader through setting up the site from scratch to build a profitable web presence. This is somewhat conflicting, as I found that some knowledge about TYPO3 is already required to begin reading this book.

One major issue I stumbled across is the lack of coherent flow in the book. This causes the reader to jump back and forth, as some sections don’t make sense until after subsequent chapters are read. This also leads to a lot of repeated content, and in general makes the book tough to follow. Let me walk through the chapters of the book and provide a better path to follow.

Chapters 1 & 2 cover basic TYPO3 installation, upgrades, templates, typoscript, and extension installation. Enough typoscript is given to confuse a newbie, so these chapters should only be read after some experience with TYPO3 basics. Likewise, if you’ve built a TYPO3 powered site before, you can safely skip this section.

Chapter 3 delves into the core of the book and describes the available commerce extensions. The description is very light, but the reader is instructed to consult the extension manuals for more information. The main extension chosen for the rest of the book is tt_products. Setting up a test paypal account is covered in detail, however most of the details of integrating it with TYPO3 and tt_products are left missing.

Chapter 4 starts by covering content import from CSV files, which is a bit premature at this point. It then explains adding new product using standard TYPO3 record editing features, and explains how to add a tt_products content element to a page. This is a chapter I would recommend rereading after experimenting with the shop setup.

Chapter 5 jumps into user registration, and covers frontend users and user groups. For commerce specific information, the book explains how to setup discounts for returning users.

The next chapter, chapter 6, diverges into menus, sitemap, navigation, and search. A lot of typoscript code is presented, but very little is explained, so the reader is expected to have a good foundation of typoscript at this point.

Chapter 7 provides a very light coverage of order management – something I would have liked to see more of, as it is arguably the most important step in the e-commerce flow after making a sale. No workflows, supply chains, or customer notifications are mentioned. The chapter also covers the basics of SSL and its integration into TYPO3. It also describes payment addins – something that was promised in chapter 3.

Chapter 8 gives an overview of the backend administration. Very little commerce specific information is given, and ideally this chapter should follow the installation chapter. Experienced TYPO3 users can safely skip this chapter.

Chapter 9 gives a top level of SEO optimization techniques. This is a topic that whole books could be, and have been, written on. Some TYPO3 specific information is given, but I would have preferred to see more.

Chapter 10 closes out the book by providing general tips for e-commerce, starting with basic business principles and ideas, and ending with site layout. This information is great for shop owners, but not for technical implementers. No TYPO3 specific information is given.

I was disappointed in not finding any information about TYPO3 and Magento integration, as that is a very popular topic. Unfortunately, its not covered at all in the book.

As a summary, if you were just starting out your TYPO3 e-commerce journey, I would recommend that you get some other introductory TYPO3 books (Building websites with TYPO3 by Michael Peacock and TYPO3: Enterprise Content Management at the minimum). Only then will you have a good foundation for this book, but then some of the chapters would become irrelevant.

If you want to see the language and type of information covered in the book, you can download a sample chapter.

TYPO3: Enterprise Content Management

Multimedia cookbook
February 1st, 2010

My book is about to be released, and some promotional materials have been released into the open to help readers evaluate the type of material covered, and writing style. Here are the tutorials that have been released:

I’m curious as to how well this material represents the book. Let me know your thoughts!

Caching in extensions
January 9th, 2010

TYPO3 4.3 features a new caching framework, which has been backported from FLOW3. The framework (should one choose to use it – more on that later) allows placement of default TYPO3 caches in DB tables, files, memcached, APC, or any other backend that can be created by implementing a PHP interface.

But even more – TYPO3 extensions can easily leverage this framework to cache their output, configuration, or anything else they need to cache. Furthermore, the choice of backend is left up to the individual installations. Some may decide to use DB tables, others files, yet some others will go with an in-memory caching system, like memcached, or APC. Choice of storage would be completely transparent to the extension, which will simply use the framework regardless of the backend.

Given all the caches TYPO3 offers, why would you want your own cache? Reasons vary. If your extension is a USER_INT object (which is not cached), but it queries the database, or external resources, you should use caching in your extension. Should the extension be used on a high traffic page, you don’t want it to become the point of contention.

In this simple guide, I’ll cover some basics of enabling caching in your extensions. I’ll assume you’re running TYPO3 of at least version 4.3.0, and your extension lists this as a dependency. If it doesn’t, make sure to surround all code using the caching framework with checks for TYPO3 version (use t3lib_div::compat_version() function), and test on all supported TYPO3 versions.

First you need to define the cache. Add this to the ext_localconf.php:

// If cache is not already defined, define it
if (!is_array($TYPO3_CONF_VARS['SYS']['caching']
   ['cacheConfigurations']['my_extension'])) {
   $TYPO3_CONF_VARS['SYS']['caching']
      ['cacheConfigurations']['my_extension'] = array(
      'backend' => 't3lib_cache_backend_DbBackend',
      'options' => array(
         'cacheTable' => 'tx_myextension_cache',
         'tagsTable' => 'tx_myextension_cache_tags',
      )
   );
}

We use the database cache as the default. So we need to define the cache tables:

CREATE TABLE tx_myextension_cache (
   id int(11) NOT NULL auto_increment,
   identifier varchar(128) NOT NULL DEFAULT '',
   crdate int(11) unsigned NOT NULL DEFAULT '0',
   content mediumtext,
   lifetime int(11) unsigned NOT NULL DEFAULT '0',
   PRIMARY KEY (id),
   KEY cache_id (`identifier`)
);
CREATE TABLE tx_myextension_cache_tags (
   id int(11) NOT NULL auto_increment,
   identifier varchar(128) NOT NULL DEFAULT '',
   tag varchar(128) NOT NULL DEFAULT '',
   PRIMARY KEY (id),
   KEY cache_id (`identifier`),
   KEY cache_tag (`tag`)
);

Of course, any installation can overwrite the default definition by writing the definition in localconf.php:

$TYPO3_CONF_VARS['SYS']['caching']['cacheConfigurations']
   ['my_extension'] = array(
   'backend' => 't3lib_cache_backend_MemcachedBackend',
   'options' => array(
      'servers' => array('127.0.0.1:11211'),
   )
);

Since the ext_localconf.php in our extension is included after localconf.php, the extension needs to check that the caching definition is not already defined.
Now in your extension you need to create and initialize the cache object:

if (TYPO3_UseCachingFramework) {
   // Create the cache
   try {
      $GLOBALS['typo3CacheFactory']->create(
         'my_extension',
         't3lib_cache_frontend_VariableFrontend',
         $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['my_extension']['backend'],
         $GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['my_extension']['options']
      );
   } catch(t3lib_cache_exception_DuplicateIdentifier $e) {
      // do nothing, the cache already exists
   }
   // Initialize the cache
   try {
      $this->cache = $GLOBALS['typo3CacheManager']->getCache(
         'my_extension'
      );
   } catch(t3lib_cache_exception_NoSuchCache $e) {
      // Unable to load
   }
}

$this->cache will now hold the cache for your extension. You can now check if the cache has a certain ID:
$this->cache->has($id);
If it does, retrieve it:
$this->cache->get($id);
If not, then generate the content and store it:
$this->cache->set($id, $content, $tags, $lifetime);

See the interface for more operations you can perform on the cache. The greatest thing about the caching framework is the fact that the specific caching backend is completely transparent to you – and each installation can use whatever method they deem appropriate, without any changes to your extension.

Today I finished reading “Pragmatic Thinking and Learning: Refactor Your Wetware” by Andy Hunt. Let me start by saying, that I’m really glad I picked up and finished this book right before the New Year. Why? It’s a checklist I’m putting on my New Years resolutions.

The book starts out by describing the differences between novices and experts (and the steps between). Very quickly it dives into learning modes, personality traits, and more. But it doesn’t just cover the theory – on the contrary, it describes practical applications of the theory for personal improvement. It gives action items for applying these ideas and describes the outcomes. Finally, it talks about personal and professional efficiency.

The book is well written, with humor added to make it a fast enjoyable read. Nevertheless, it packs a ton of information into very little space, and makes you think about your own learning and thinking abilities – opening the mind through observations. I definitely enjoyed it, and would recommend it to anyone – not just programmers – who wants to change perspective on their thought process.

Nginx has emerged as one of the popular webservers to run the TYPO3 framework. Advantages to using Nginx are that it is lightweight, fast, and reliable – unlike Apache, which has a much bigger footprint in terms of resources. Nginx is frequently set up to handle static files or cached pages (thanks to its memcached module), while any dynamic requests are forwarded to Apache.

In this blog post I will describe how to set up Nginx to play a role of the load balancer, directing incoming requests to a cluster of Apache servers. There are many advantages to this set up. It allows for scalability, where new servers can be added any time to meet increasing demand (including virtual servers in the cloud). It improves reliability, since Nginx will automatically detect when a server is not responding to requests, and forward the request to another server.

Best of all, implementation would not require any changes in TYPO3 code, only basic configuration changes. I’ll skip basic installation instructions, since you can find them elsewhere on the net. If you’re on a Debian system, I highly recommend compiling from scratch due to outdated packages in default Debian repositories.

Nginx Confguration

First we add an upstream configuration to the main nginx configuration (/etc/nginx/nginx.conf on Debian):


# Load ballancer configuration
upstream backend {
ip_hash;
server 10.0.0.2:80;
server 10.0.0.3:80 down;
server 10.0.0.4:8080;
}
upstream typo3 {
server 10.0.0.2:80      weight=2;
server 10.0.0.3:80;
server 10.0.0.4:8080;
}

We define two very similar configurations: one for backend, one for frontend. First one will be used for access to TYPO3 BE so it uses ip_hash directive to send users to the same server within a certain time frame (note: this is not necessary, but its nice, and could prevent some strange bugs). This also lets us set certain servers as inaccessible using the down directive. Second definition defines a list of servers for the front end, with equal weight distribution, unless specified otherwise.

Next we need to make use of the server clusters. In your site definition (ex: /etc/nginx/sites-enabled/default), add the following:


location /typo3/ {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backend;
}
location /typo3conf/ {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://backend;
}

location / {
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://typo3;
}

Lines to notice are:


proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

Which forward the Host (necessary for multi-domain systems), and the X-Forwarded-For header. We need to make use of the later in our TYPO3 configuration. Add the following to typo3conf/localconf.php:


$TYPO3_CONF_VARS['SYS']['reverseProxyIP'] = '10.0.0.1';
$TYPO3_CONF_VARS['SYS']['reverseProxyHeaderMultiValue'] = 'first';

Change the reverseProxyIP to the Nginx server address – as the Apache servers would see it. You can even set it to different values based on where the server is – for example, if you have an Apache server on the same machine as your Nginx proxy, you can set it to 127.0.0.1.

That’s it! You should now see traffic distributed across the servers. If you pull the plug on one of the servers, the site will still be up with the other servers taking on the load.