Friday, January 6, 2012

Many VMs keep it neat

I've been working a lot on Virtual Machines recently so I can keep all the code and settings for each project I'm working on separate. When I need a desktop dev environment or a web server I just create a  new VM!

It sounds overkill to start a new machine for each project but here are several reasons why creating one is a great idea.

  1. Separation - When you have a whole machine for each project it's impossible for one set of tools to get in the way of the other. You can keep the config right for just that project.
  2. Backup - I snapshot each machine before I do something big. The ability to go back to a point in time in one click is incredibly powerful if you use it regularly. I also run an rsync script regularly to copy the VMs to another drive, so you are not relying on one HDD. You just copy one file and you have the whole machine backed up.
  3. Keep your "host" clean and running fast - When you install many apps on one machine they generally slowly get clogged up and confusing. I use OSX as my host and run mostly linux and Win7 in the VMs.
  4. Software versions - I recently needed 2 different versions of the same software for different tasks. Creating a new machine made it so easy. 
I started off using VMware Fusion, as I used to work with VMware ESX and was always impressed with it. However I've recently been using VirtualBox more and more. It's free and I haven't found anything I can't do with it yet.

A few tips:

Run dropbox on the machines and keep any files you want to move between machines on there. It's the perfect backed up, versioned shared directory.

You need lots of Ram. I have a Mac Pro with 2 dual core processors which can cope fine with 3 VMs running simultaneously. RAM you can't really do without. I use 10GB which always leaves plenty for the  Mac too.



Wednesday, August 17, 2011

Finding lost attributes in Magento

We have recently launched our new site www.thistribe.com, a new eCommerce site selling high end equipment to the Military and other members of the security industry.

Using Magento we have been able to very rapidly develop a cutting edge site with the vast array of modules that have been written for it. We already have a good network of developers ready for future projects. with it's recent acquisition by e-bay it looks like it is going to be the e-commerce platform to be reckoned with, so we made a good choice.

Having not worked with Magento before it has been a steep learning curve, but it's very powerful. The database looks incredibly complicated as it uses and EAV pattern. This allows you to extend it easily without schema changes. For example the way the site uses attributes and attribute sets for products is very powerful, all down to EAV.

The Magento database Schema (V1.3)


Since the site went live we have been continually improving things and adding features. One of these tasks was adding a Google Shopping feed. We are using the module from Wyomind This product will generate all sorts of different format feeds from your products in Magento. You can manually edit the templates from within the admin site and even test the output before you generate the files. Pierre, the creator has also been incredibly responsive and helpful in adding features, I can't recommend it highly enough.
We have used several different attributes for product size as obviously all products don't have the same sizing attributes. As each product only uses one of these we just put them all into the template, only the one that has a value will output the tag:



<g:size>{size_head_sealskinz}</g:size>
<g:size>{size_gloves}</g:size>
<g:size>{size_head}</g:size>
<g:size>{size_head_truspec}</g:size>
<g:size>{size_pants}</g:size>
<g:size>{size_jacket}</g:size>
<g:size>{size_shoe}</g:size>
<g:size>{size_socks}</g:size>


This works fine, for most products! We found a few that very strangely had 2 sizes, event stranger was that some hat products had 2 sizes, the correct one for a hat, and another for a jacket.


Obviously something was not right. It all looked fine in the Magento admin site, so it was time to look into the database itself.


We spent a while looking for the relevant records, it's made a little trickier by the fact that all the attributes are stored in attribute sets.


The important tables are:

catalog_product_entity 
This allows you to find the entity_id from your SKU.

catalog_product_entity_int 
For attributes with multiple options this table will have rows for the entity_id you just found.

eav_attribute_option_value
This is where all the options in an attribute set are. So you look for your text of the attribute in here.

You can see a full list of the actions and SQL used here.


Magento is a very powerful but complex product. It takes time to understand the underlying structure but it's time well spent when you run into problems like this.