By 3 years ago in Development Magento

The Magento Strikes Back

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.

By Douglas Radburn. at 1:17PM on Tuesday, 16 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.