Warning: preg_match(): Unknown modifier '4' in /root/Dropbox/paj/www/dev/datalogger/php/Log/Log.php on line 269 Warning: preg_match(): Unknown modifier '2' in /root/Dropbox/paj/www/dev/datalogger/php/Log/Log.php on line 322

Category Magento

Upgrade Magento 1.8 to 1.9

Magento Upgrade

Magento CE 1.9 has been released. It appears to be a relatively small update introducing a new responsive GUI. See the release notes here.

Here are my notes after upgrading my dev store from 1.8.x to 1.9 using the command line.

Backup existing install folder and database

1. Magento source
tar -cvvf /home/backup/magento.tar /home/www/magentoinstallfolder/

2. Magento DB
/usr/bin/mysqldump -h localhost -u USER -pPASS magento | gzip > ~/backup/folder/db-magento.sql.gz

1. Remove cached files and temp files

rm -rf downloader/pearlib/cache/*
rm -rf downloader/pearlib/download/*
rm -rf downloader/var/cache/*
rm -rf downloader/var/report/*
rm -rf downloader/var/tmp/*
rm -rf media/catalog/product/cache/*
rm -rf media/tmp/*
rm -rf var/cache/*
rm -rf var/session/*

2. Restart memcached (if being used)

3. Sync mage

./mage mage-setup

./mage sync

4, Run upgrade

./mage upgrade-all

5. Reset ownership and permissions on all files and folders.

Check Magento is operational, login and refresh caches.

If all is well take a well deserved break and maybe eat a cream cake. If all is not well restore from backup…



Google Universal Analytics Update for Magento Version v.1.3.X Old Versions


Google Universal Analytics went out of BETA recently (May 2014) and is now available for all users. Universal Analytics has “more features, better insights”.

All versions of Magento include the client side analytics code which can be enabled in Magento Admin. When enabled Magento creates the client side html and javascript and appends it to the footer section of each page.

On the checkout completion page additional code is created to track sales.

Google Univeral Analytics Magento

Google Universal Analytics uses new client side javascript code, this means Magento does not yet support Google Universal Analytics by default, however it is relatively easy (if you are using new versions of Magento) to override the base/default Magento code that creates the client side analytics html and javascript.

If you simply turn off the built in Magento analytics feature and add the new Google Universal Analytics code to your page templates (as Google suggests you do) then you will lose all eCommerce tracking.

You can update your Magento core code to support Google Universal Analytics using the information below.

New Versions > 1.4.x

If you are using a newer version of Magento i.e. > 1.4.1.x you can update the core analytics functionality following the guidelines here.

Old Versions < 1.4.x

if you are using an older version of Magento (before 1.4.1) i.e. Magento 1.3.x, I have adapted the Magento v1.3.x google analytics core module code to support Google Universal Analytics. The code can be installed as a local module and will override the core module.

Download the code from my GitHub

To install the module copy the files to your Magento app folder, refresh your Magento configuration and configure the settings under Configuration -> Google API -> Google Analytics.

To view the analytics code look at the source code of any page, scroll to the bottom and look for the code between the Google Universal Analytics Code comment tags. For order tracking information, check the code on the Checkout/Success page.

Magento SEPA Migration Check List

The Single Euro Payments Area (SEPA) is a payment-integration initiative of the European Union for simplification of bank transfers denominated in euro.

If you make or accept payments via direct bank transfers then you will know all about SEPA. As a customer online payment method direct bank transfers are popular in some countries (i.e. Germany) and not so popular in others (i.e the UK).

The deadline for SEPA payments was 1st February 2014 but (as of the time of writing) has been extended 6 months to 1st August 2014.

SEPA standardises bank transfers in Europe, replacing bank specific account and sort code numbers with an IBAN (International Bank Account Number) and BIC (Business Identifier Code).

For most businesses the migration to SEPA involves communicating the new changes to customers and migrating bank account numbers and sort codes to IBAN and BIC.

For Magento stores if you have a payment method that allows customers to pay via a direct bank transfer then you need to ensure that you can capture IBAN and BIC numbers at checkout. Until 1st August 2014 you can decide to give the customer the option of entering either bank account number and sort code or IBAN and BIC. From August 1st you *should* only be accepting IBAN and BIC.

Here is what you need to do to get your Magento Store ready for SEPA payments

  • Make sure you are capturing bank account information in the SEPA format – IBAN and BIC at checkout.
  • Check that your validation rules work for the IBAN and BIC formats.
  • Make a note to remove input fields and validation rules for old account formats, bank account number and sort code.
  • Upgrade your existing debit payment methods to make sure they support SEPA.
  • Implement a validation system for IBAN and BIC

This debit module is perfect for German Magento shops implengint Direc Debit (Lastschrift) payment methods and supports SEPA : https://github.com/therouv/Magento-DebitPayment

To validate IBAN account numbers with PHP take a look at https://code.google.com/p/php-iban/



Javascript only EU Law Cookie Notification Message for WordPress and Magento

You know sometimes you just want a quick solution to a problem and wherever you look there are just complex, overpriced scripts that make your simple problem sound like something that needs a lot of code and money to get to work.

I needed to display a cookie notification message on a wordpress and magento site, to avoid compatibility problems I wanted to avoid using jQuery and just do it as simply as possible in javascript.

After looking around at a lot of $10 jQuery solutions I found a free javascript only solution, modified it for Magento and WordPress and implemented it.

Download the code from Github here

Whatever your opinion of the EU Cookie Law which came into effect in 2012, sooner or later if you are in Europe you may need to show that you are doing something about it. Err actually it’s 2014, so I guess we are already a teeny weeny bit late.

From what I understand the law may differ in various countries (certainly outside Europe), so depending on where your website is, and who visits your site the law may or may not apply to you.

This script will let  you quickly implement a cookie notification banner with a link to your privacy policy. The notification itself uses cookies and will not be show again when closed.

You can implement this solution on any website by copying the install files to your web server and adding the following code to the footer of your site.

<script type=”text/javascript”>

var cookieNotificationURL='/cookies/';
var cookieNotificationLifetime=180;
var cookieNotificationMessage='This website uses cookies. For more information please ';
var cookieNotificationClickMessage='click here';
var cookieNotificationMessageFade=true;
var cookieNotificationPath='/path-to-install-folder/

<script type="text/javascript" src="/js/cookienotification/cookie.notification.min.js"></script>

This sets up some variables used by the script, the URL of the privacy info page, the lifetime of the cookie used by the script in days, messages displayed, the option to fade the message automatically and the path to the install folder – used to display the close image.

For wordpress simply paste this into the footer php file of your theme.

For Magento paste this into the footer.phtml template file of your Magento theme. You can translate the messages, and perhaps a good idea, choose to display the message only on non SSL pages – we don’t want this javascript to somehow screw up a sale!

<?php if (empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] = ‘off’): ?>

<!-- Cookie Notification -->
<script type="text/javascript">
var cookieNotificationURL='/datenschutzerklaerung/';
var cookieNotificationLifetime=180;

<?php if (Mage::app()->getStore()->getId()==2): ?>
var cookieNotificationMessage='This website uses cookies. For more information please ';
var cookieNotificationClickMessage='click here';
<?php else: ?>
var cookieNotificationMessage='Diese Website verwendet Cookies. ';
var cookieNotificationClickMessage='Klicken Sie hier für weitere Informationen.';
<?php endif ?>

<script type="text/javascript" src="/js/cookienotification/cookie.notification.js"></script>
<?php endif ?>

Here I am manually checking the store id and translating the text to German. Remember to refresh your Magento cache after editing and saving the footer template file.

You can see the code working on this WordPress blog below, and also with Magento on my Magento development site.

Tested with Magento 1.8.x, WordPress 3.blah, Chrome, Firefox, IE11. Detects mobile devices and modifies banner size accordingly.

Upgrading Magento 1.7 to

A few notes after upgrading to Magento from

Make sure you backup your Database and Magento source directory first! My first upgrade attempt using Magento connect (via SSH) failed, The following error appeared when trying to load the site

“Call to a member function rewrite() on a non-object”

After googling the error and trying a few suggestions the install was still broken so I restored from backup and tried again. This time I followed the following steps

1. Remove cached files from /var/cache and /var/session

2. Restart memcached (if being used)

3. Sync mage


./mage sync

4, Run upgrade (with force switch)

./mage upgrade-all –force

5. Reset ownership and permissions on all files and folders.

Magento loaded without error.

There are no major database changes between and so you can restore your 1.7 installation and switch between the two versions quite easily if you need to do any debugging etc.


Magento HTML Invoices, Print, Save, PDF

A Magento invoice display and printing system using PHP that can run externally to Magento.

The application displays Magento orders based on a time range in days and lets you display or print them with one click.

You can select a range of orders and preview the invoices, or print them by clicking on each order to select it. and clicking the print button.

Acknowledged orders (printed orders) are recorded and shown with a print symbol next to the order. (requires a configured cache folder writeable by www user.)

Click the time range to change the order time range in days. Some customer data can be edited directly in the app and exported to a text file which can be useful for automatic imports to shipping software etc.

Invoices can be displayed in the language they were placed in – simply create a translation file for your language and configure the application store id’s and languages.

Tested with
Chrome and Firefox – IE9/10 has some issues with printing.
Magento 1.3x – 1.7x (Community Edition)

Source codehttps://github.com/gaiterjones/magento-invoices

Copy the source files to a web accessible folder and configure settings in the configuration files. Point your browser at the installation folder to view orders.

BETA Demo below NOTE - no application security has been included, you should secure the application folder with Apache or implement a PHP login system. Installing the app in a public folder will give public read/write access to your Magento data!

Enable Magento iPhone Theme for Mobile Browsers

Magento Default IPhone theme

Do you know how many of your customers are visiting your site using a mobile device? If you don’t, take a quick look at your Google analytics and check the figures under Audience -> Mobile -> Overview and Devices. If the % of visits from mobile devices is more than 10% of your total site visits then you might want to think about providing specific content for mobile visitors to your Shop otherwise you maybe losing out on sales.

Mobile Device Visitor stats from Google Analytics

Mobile Device Visitor stats from Google Analytics


Since Magento v1.4.x a built in mobile theme called iPhone is included with the source code.but it is not enabled by default. Here is a quick fix to enable the built in Magento iPhone theme for your Magento store to provide a better browsing experience for visitors using mobile devices.

Login to admin and goto System -> Configuration. Click on General in the left hand menu and then DesignExpand the theme section and then configure the following exceptions under Templates, Skin and Layout.

Matched Expression - iPhone|iPad|iPod|Android|IEMobile

Value – iphone

Configure Exceptions for iPhone Theme

Configure Exceptions for iPhone Theme


Click Save to save your settings.

Notice the user agents in the matched expressions, these define which mobile browsers identified by User Agent should use the mobile theme. The iPad has a fairly large screen so you might decide to exclude that for example.

If you visit your store now with a mobile device you will see the default iphone theme in action.

Magento Default IPhone theme

Magento Default IPhone theme


Actually – its not very good is it, but it’s better than nothing and provides a good place to start building your own mobile theme. Alternatively (and I don’t say this very often) invest some $$ in the Aheadworks Mobile theme because it really is excellent.

Whichever mobile theme you decide to use make sure you test it thoroughly on your staging server, especially if you have a lot of extension modules installed. You may need to customise the mobile theme to achieve the same functionality as you have from your desktop version. Remember to include an option switch from desktop to mobile versions on both sites so that visitors can also decide which theme they want to use.

For testing (if you don’t have a mobile device) set the user agent in your browser to a mobile browser i.e. iPhone. This is possible in Safari by enabling Developer Mode and clicking Develop -> User Agent and selecting a mobile version of Safari from the drop down list. If you are a Mac user you can also use Xcode to run up an iPhone simulator as used for the screenshots above.

If your desktop site uses Flash, now is the time to start replacing it with HTML5 :)


Cannot log into Magento Admin? Magento Admin not loading? Magento Cache Refresh Script

It is possible to lock yourself out of the Magento back end admin interface simply by disabling a module which affects html rendering and stops you from logging back into the admin interface – which you need to do to re-enable the module – DOH! Its a real catch 22 situation.

If you are locked out of Magento admin, or your admin pages are not rendering correctly due to an admin change this post may just save your bacon.

If you have disabled an extension and need to re-enable it but the admin interface is not working, load up PHPMyAdmin and browse to your Magento database. Find the core_config_data table and then page through all the config options until you find the advanced/modules_disable_output rows. Find your disabled module – it will have a value of 1, and change the value back to 0 to enable it.

Paste the following code into a new .php file and save it to the root folder of your Magento store and run it in your browser. It will refresh the Magento cache, and re-enable the disabled module. Hopefully you should then be able to access admin again.

Depending on what has gone wrong with your configuration this may not always work, but if you have modified an admin config that for whatever reason has locked you out of admin then this method may work for you. It certainly is less painless than a full DB restore which is perhaps your other option.

Here is the cache refresh code.

require_once 'app/Mage.php';
umask( 0 );
Mage :: app( "default" );
$ver = Mage :: getVersion();
$userModel = Mage :: getModel( 'admin/user' );
$userModel -> setUserId( 0 );
Mage :: getSingleton( 'admin/session' ) -> setUser( $userModel );
echo "Refreshing cache...\n";
Mage :: app() -> cleanCache();
$enable = array();
foreach ( Mage :: helper( 'core' ) -> getCacheTypes() as $type => $label ) {
$enable[$type] = 1;
Mage :: app() -> saveUseCache( $enable );
echo "Cache refreshed";

Automatically Tweet New Magento Products

This is a PHP application I developed to automatically Tweet Magento products set with the New From date attribute.


Magento Product Tweet v0.5x


  1. Introduction
  2. Prerequisites
  3. Installation
  4. Configuration
  5. Usage




Magento Product Tweet is an object oriented PHP script that integrates with a Magento installation to automatically tweet product information for new products set with the New From date attribute in the Magento database.


Magento Product Tweet works with Magento Community Edition version 1.4 or greater and requires PHP 5.3 or greater.




This application requires a configured Twitter Account and configured Twitter application for the account as well as a Bitly API key to generate short urls.


To configure a Twitter App visit https://dev.twitter.com/


To configure a bitly account visit http://bit.ly





Extract the source files to a folder on your system i.e. /home/php/magento


A new folder producttweet will be created.


Make sure the subfolders cache, and log are writeable by your current and crontab users.




Edit the file applicationConfig.php in /producttweet/config.



const PATH_TO_MAGENTO_INSTALLATION = ‘/home/www/dev/magento/’;


With the actual path to your Magento installation.



const FILE_CACHE_FOLDER = ‘/home/php/producttweet/cache/’;


With the full path to the producttweet cache folder.


Edit the Twitter and Bitly api authentication details.


Edit the application configuration settings:


tweetsPerSession – this is the number of products that will be Tweeted each time the script runs.

tweetHeadline – this is the prefix to the Tweet text.

tweetFromHour – Time range to tweet between – from hour between 00 and 23

tweetToHour – Time range to tweet between – to hour between 00 and 23


e.g. to only tweet between 0900 and 2200 set the From hour to 09 and the To hour to 23.


useDecriptionText – set this to short or long to use either the short or long product description for the tweet text.





Save the file.




To run the script for the first time to check functionality change to the scripts working directory and type


php tweetproduct.php notweet


The script will execute normally but with tweeting disabled. If there are errors with your main configuration you will see them reported now. If no errors are reported the script will return a summary of all products in your Magento database with a New From date that matches todays date.


If no products are returned check that you have set the new from date attribute correctly on a product.


If products are found a summary of each products will be shown including an example of the Tweet text and URL e.g.


[Magento Product Tweet v0.56 22.10.2012]

Session started – 2012-10-22 18:12:33


[Search Results]


135 – Anashria Womens Premier Leather Sandal / ana

NEW TODAY! Anashria Womens Premier Leather Sandal, Buckle embellished contrasting straps adorn both the heel and… http://bit.ly/VrhMwA – 136

Cache file /root/Dropbox/paj/www/dev/magento/tweetproducts/cache/2012-10-22-9ac43d1842fd2477f500d028b158b496 created.



132 – SLR Camera Tripod / ac674

NEW TODAY! SLR Camera Tripod, Sturdy, lightweight tripods are designed to meet the needs of amateur and professional… http://bit.ly/VtXzX1 – 140


Session tweet limit (1) reached, ending session.


[Summary for collection type - newfromdate]

2 product/s found.

1 product/s tweeted this session.

1 product/s tweeted today – 2012-10-22.



If the results and Tweet examples are correct run the script again with the flushcache swith to delete the cache files :


php tweetproducts.php flushcache


And then run the script without the notweet switch to test live tweeting.


A tweet success or failure message will be displayed for each product, and the tweets should appear in your twitter feed.


Script activity will be logged in the ./log folder. You can delete the log files with the flushlogs switch.


To automate tweeting completely add the script to your crontab, e.g. to run the script every 5 minutes use


*/5 * * * * /usr/bin/php -f /home/php/magento/tweetproducts.php silent


Note the silent switch disables all script output.


If the script detects errors use the showtrace switch for more information and email the log file to extensions@gaiterjones.com for assistance.







PAJ 22.10.2012




Facebook Magento Store Front Shop Tab Application

I saw an email last week from a company offering a Facebook store front tab application service for Magento that imports your Magento products and creates a basic Magento store front presence in a Facebook tab application. I thought this was a pretty neat idea especially if you are using Facebook as a marketing tool for your Magento e-commerce site. What I did not find so neat was the price, they want upwards of $1000.00 per year for a fully dynamic storefront with up to date products and support.

Having recently done some work both with Facebook tab apps and exporting Magento product collections in PHP I thought that this is actually a pretty easy task to achieve and coded up an example Facebook Magento Store Front running in a Facebook tab that presents a simple view of your products, product information and a direct link to the product on your Magento web for customers to place orders.

The app talks directly to your Magento database so it will always be up to date. It supports multi language stores and will detect the customers browser language and switch languages accordingly.

This is really a quick win app, integrating quickly with your Magento installation and takes about 30mins to setup and get up and running in Facebook.

Check out my demo Facebook storefront / shop tab app here.


Download the latest version of the application source code here.

Basic installation and usage instructions below.

12.11.2012 – v0.97 – bug fixes and changes to user configuration setup, user config now held in .ini file.
22.11.2012 – v1.0.1 – first public release


Magento Facebook Store Front Tab


Conversions From the Tab


Magento Facebook Store Front Tab Application


  1. Introduction
  2. Prerequisites
  3. Installation
  4. Configuration
  5. Usage
  6. Languages




Magento Facebook Store Front Tab is an object oriented PHP script that integrates with a Magento installation to render product HTML designed to be displayed within a Facebook Tab. The application is able to render various product views, all products, new products, categories etc. with a simple product description and link to your actual Magento web store for purchases.


The application supports normal desktop clients.




This application requires a configured Facebook Account, Facebook Page and a configured Facebook application. A good knowledge of your Magento installation and Operating System is assumed as well as some experience with Facebook applications and PHP.




Extract the source files ideally to a sub folder of your Magento installation. e.g. /home/www/magento/facebook


A new folder ‘magentotab’ will be created. Feel free to rename this folder if required.


The application will then be accessible from your browser via the following url




Where www.YOURSHOP.com is the url to your Magento shop frontend. If you install the application somewhere other than your Magento installation folder then you will need to browse to the application via your configured web server path.




Edit the file applicationConfig.php in /magentotab/config.



const PATH_TO_MAGENTO_INSTALLATION = ‘/home/www/dev/magento/’;


With the actual path to your Magento installation.


Edit fbAppID, fbAppSecret and fbUrl with the App ID, Secret and URL from your configured Facebook app.


To display a menu on the product page set the showMenu constant to true. Depending on traffic and your hosting etc. the application may run faster when the menu is disabled.


To exclude categories from being shown in the product menu, configure the excludedProductCategories constant with a list of category id’s separated by a comma, e.g.


const excludedProductCategories=’4,5,16,17,18,19,22,23,25,27,28,29,30,31,32,33,34,35,37′;

For google UTM tagging configure the googleUTMTag constant with a valid Google UTM URI.


The bannerImage constant holds the name of the graphic file used as the banner at the top of the Facebook Tab page.


Set the productLimit constant to define the number of products that will appear per page. This should be divisible by 9.


Set the defaultCollectionType constant. This defines the default product view that will be shown. Options are


newfromdate – Products set with the NEW FROM attribute – i.e. New Products.

allproducts – All Products

categoryproducts – Products from a category.


Determine which product description will be shown for the product

useShortDescription=true – Use short description

useLongDescription=true – Use long description


Configure language options


const storesConfigured=’1,2,3′;

const storesLanguage=’de,en,fr’;

const storeDefaultLanguage=’en’;


In this example there are three stores configured with the id’s 1, 2 and 3. The store languages for store 1,2,3 are de, en, fr – German, English, French. And the default language is ‘en’ – English.


The showContact and showAbout constants enable a Contact and About button on the menu when set to true. This is currently in development.


The allowStandAlone constant lets the application run in a standalone browser when set to true. When set to false the application will redirect to the Facebook URL of the app. Set to true for debugging the app standalone outside of Facebook.


Set the pageLikeRequired constant to true if visitors must first Like the Facebook page the tab is running in before they can access the application.


Set the URIToApp value to the URI path of the app on your server.



Save the configuration file.




To run the script for the first time browse to the URL of the script as defined above


i.e. http://www.YOURSHOP.com/facebook/magentotab


If the Magento configuration path is correct you should see a list of products displayed, with or without menu options as specified in the configuration.


If the application works correctly standalone then you are ready to integrate it with Facebook.


To install the application as a Facebook Tab ensure that your Facebook application has been created and configured with the correct canvas URL’s to the application and then goto the following link




This will return a link that will start the Tab installation process via Facebook. Select the Facebook page to install the Tab on.


When the Tab is installed goto your Facebook page to confirm that the app is working.




To translate some of the interface text used in the application to your language, simply create a new language file in the php/locale folder named XX.txt where XX is your two letter language code. Use an existing language file as a template and add your translations to the file in the format




Make sure your language settings are configured correctly in the application. You can force the application to the language you want using the storeid variable in the url


i.e. http://www.YOURSHOP/facebook/magentotab/?storeid=2


Will force the application to the language configured for store id 2.