The Magento Strikes Back

  • 0
  • August 16, 2011

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:

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.

Douglas Radburn

About Douglas Radburn

As our Head of Technical Doug has played a key role within the Development team since 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.

Like what you see? Talk to an Expert