I am beginner in Magento, I want to add csv file for attributes, as we have 500 attributes, so we can not upload it 1 by 1 because it takes time. Please suggest me simple way to upload attributes by using csv file?
Here is how I would do it.
Write a simple php script that transforms your csv into an installer script for adding attributes.
Let's say your csv looks like this:
code |label |type |input|required|global attr_code|some label|varchar|text |1 |1
You need to turn this csv into something like this:
$this->addAttribute('catalog_product', 'attr_code', array( 'group' => 'General', 'type' => 'varchar', // the type column 'input' => 'text', //the input column 'backend' => '', 'frontend' => '', 'label' => 'some label', 'class' => '', 'source' => '', 'global' => 1, //the global column 'visible' => true, 'required' => 1, //the required column 'user_defined' => true, 'default' => '', 'searchable' => false, 'filterable' => false, 'comparable' => false, 'visible_on_front' => false, 'visible_in_advanced_search' => false, 'unique' => false, 'is_configurable' => false, ));
All other attribute properties can come from the csv. I just added a few as a proof of concept.
Now use the result as an upgrade script in one of the custom modules. Read this article from Inchoo explaining how to add attributes through code to get a clear view.
The advantages of this approach is that once you create the upgrade script it is portable to all the site instances you have, and you don't have to import attributes each time.
Another way is to add the the Attributes with the soap api. You can write a script that reads your csv and connects it to the soap api.
You have to add a soap role and user in magento Backend
Role: System->WebServices->SOAP/XML-RPC - Roles
Give it the rights it needs in this case all Product Attributes
User: System->WebServices->SOAP/XML-RPC - Users
Add the user to the role.
Connect to soap api
$proxy = new SoapClient('http://magentohost/api/soap/?wsdl'); $sessionId = $proxy->login('apiUser', 'apiKey'); # to proof the connection you can var_dump($sessionID) # when its correct you get something like string '75168529b046d...
// Create new attribute $attributeToCreate = array( "attribute_code" => "new_attribute", "scope" => "store", "frontend_input" => "select", "is_unique" => 0, "is_required" => 0, "is_configurable" => 0, "is_searchable" => 0, "is_visible_in_advanced_search" => 0, "used_in_product_listing" => 0, "additional_fields" => array( "is_filterable" => 1, "is_filterable_in_search" => 1, "position" => 1, "used_for_sort_by" => 1 ), "frontend_label" => array( array( "store_id" => 0, "label" => "A new attribute" ) ) );
Call the soap Api
$attributeId = $proxy->call( $sessionId, "product_attribute.create", array( $attributeToCreate ) ); var_dump($attributeId);
This is an example from http://www.magentocommerce.com/api/soap/catalog/catalogProductAttribute/catalogProductAttribute.html
There are a lot of more examples for the operations you can do with the api.