The Magento Strikes Back

  • 0
  • August 16, 2011
Douglas Radburn

Douglas Radburn

Head of Technical

After walking you through adding CMS pages in my first post – Magento: First Class – I thought I’d walk you through importing attributes into Magento.

Recently, we’ve been working on a few Magento sites where the client already has an existing e-commerce site. Rather than making the client spend time setting up all the attributes that are required for the products, we can build an import script to easily import the attributes from the existing site.

The input script makes use of the dataflow model by creating new EAV attributes for Magento.

As per the previous script I shared with you, the example below uses a CSV file as its input.

The format of this CSV should be the following:

attribute name, type of attribute

The type of attribute can be one of the following: text, textarea, date, boolean, multiselect, select, price, media_image, weee (fixed product tax) depending on how you want the attribute to behave in the Magento backend.

The main section of code is this:

Saved: ‘ . $label . ‘

‘; } catch (Exception $e) { echo ‘

Sorry, error occured while trying to save the attribute “‘ . $label . ‘” Error: ‘.$e->getMessage().’

‘; } }

Let’s break this down a little.

The $_attribute_data array contains all the information required for the product attribute, and we just throw this at the resource_eav_attribute Mage model.

Any number of these array items could be added to the CSV to create a more rounded import, however, depending on the product, these default values should be acceptable.

Free of charge. Unsubscribe anytime.