Magento: Origins

We’ve worked with Magento quite a bit in the past and created some top-notch websites for our clients. The developments we’ve done have mainly been new site builds, meaning we can start from a fresh install and give the admin backend straight to the client, and familiarise them with it really quickly.

Recently, we’ve been working with a couple of existing e-commerce sites that need to be migrated to Magento, so we’ve started putting together some scripts to automate importing categories, product information, attributes, options, cms page etc. I thought I’d put together a series of posts that go into a bit more detail about each of these scripts.

In this series of articles, I’ll be using the best tools available, putting together custom scripts and – to remain flexible – I’ll be looking on the forums to find out if someone’s coded it before!

Magento has a virtualised database relationship model which makes it very extensible, but this can also make it difficult to interact with the data directly (for example, stock levels aren’t kept with product information), so in order to help this data-integration process Magento provides Dataflow and a SOAP API.

So, as Magento stores all the sites information in the database such as content, categories and products, there’s a lot to cover, so in this first post I’ll take a look at CMS pages.

Magento contains some straight-forward CMS page management. It’s fairly basic, but this fact certainly helps – it lets you pretty much get away with anything – you can add any HTML you want and go to town on the layout. However, CMS pages aren’t currently included within the Dataflow / API, so we need another programmatic way to interact with the system.

Looking at the database structure for Magento, CMS controlled pages use only two tables – so it shouldn’t be too difficult to put something together.

The two tables in question, are:

m_cms_page
m_cms_page_store

Looking at the structure of these tables, all the columns should be obvious – the only ones you need to fill in to get a page to show are the following: title, root_template, meta_keywords, meta_description, identifier, content_heading, content, is_active

Knowing this, it’s just a matter of getting all of your data in the right order. In my example below, I’ve stored it all in a tidy CSV as it was the easiest way to extract it from the previous system, but you could easily amend this to read from a plain text file, a serious of form fields or some XML.

I’d recommend clearing out the existing pages that are in the database initially before import so that you don’t create any pages which clash. If you do import your pages, it’s a good idea to take a look over the database after the import so that you can ensure there aren’t any issues.

And there you have it. You should now have all your page data imported into Magento, and off you go!

By Douglas Radburn. at 9:48AM on Monday, 01 Aug 2011

Doug is our Senior Open Source Web Developer since bringing his knowledge and skills to Branded3 in 2009. A founding developer of our Twitition and Competwition platforms, Doug has also been lead in our Open Source Projects on Magento ecommerce solutions and Wordpress CMS platforms. Follow Douglas Radburn on Twitter.

comments

Comments are closed.