Manipulate VirtueMart data before Vm2Mage migration

When migrating product data from VirtueMart to Magento, there might be some things that you need to change: Some attributes change name when migrating to Magento, or some attribute names are simply wrong. Vm2Mage allows for a custom plugin to change the migration specifically for your project.

Changing data

Whenever an item (user, product, category) is migrated from VirtueMart to Magento, the following 2 events are triggered by Vm2Mage:

  • onVm2MageItemConvertBefore($item, $type)
  • onVm2MageItemConvertAfter($item, $type)

These events allow you to write a plugin that changes the data before they are sent to Magento. The $item variable is a PHP reference: If you change the variable within your own plugin method, you will change it in the original data-set as well. It is an array containing all relevant data. The $type variable is a string, being either user, product or category.

The onVm2MageItemConvertBefore event allows you to manipulate the raw VirtueMart data as they are loaded from the database. Fields often contain a VM prefix. With the onVm2MageItemConvertAfter event, those raw VirtueMart data have already been manipulated a bit by Vm2Mage.

Changing attribute names

One other useful event is the event onVm2MageAttributeLoadName:

  • onVm2MageAttributeLoadName(&$attributeName)

Within VirtueMart, the requirements for attribute-names are really loose: Attributes can be lengthy. They can use normal western characters or non-western characters (like Arab, Sanskrit or Thai). WIth Magento, the requirements are very strict: Attributes can only have a name with alphanumeric characters or underscores. Vm2Mage normally already applies a few tricks to remove all illegal characters, but this might cripple your attribute-name. This event allows you to change attributes before they are being migrated by Vm2Mage. Vm2Mage also removes the com_virtuemart_ prefix from attributes.

Example plugin

An example plugin can be found here:

https://gist.github.com/yireo/d937cb17126d542a69c2

Debugging

To debug the resulting data, open up a product within the Vm2Mage backend in Joomla and hit the Debug link. This will show you a dump of all the data contained within a product. It will allow you to see whether your plugin had any effect or not.