Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

mail_open
How to import Attributes, and attribute sets into Magento?
John1

New
October 22, 2013 - 8:02 pm
Member Since: October 22, 2013
Forum Posts: 3
sp_UserOfflineSmall Offline

Hi,

I am trying to figure out a way to mass import attribute sets and attributes into magento, and obviously assign the relevant attributes to the relavant sets.

Does any one know how to do this, without having to manually do this, as my dataset is huge. I have over 1000 attribute sets and about 15000 attributes, all in csv format.

I can assign the attribute sets and attributes reletively easily to products on import but its getting them (attributes) all into magento that is causing me issues at the moment.

Any help would be great, be it a free extension, if that exists, a php script whether it talks to magento or just direct to database, or any reference to what tables, columns etc in the database that i need to populate.

Thanks very much if anyone can help.

John

Avatar
Matthew Ogborne

Founder
October 22, 2013 - 9:02 pm
Member Since: July 18, 2013
Forum Posts: 4565
sp_UserOfflineSmall Offline

Hi John,

An excellent question.

But first I am going to question (twice) why you have 1000 attribute sets and 15,000 attributes.

  1. Do you really need 1,000 different configurable options for customers to select from?
  2. And out of the 15,000 attributes, could they be drilled down to generic options instead or lesser known (that’s me saying useless) ones be culled completely?

For example one of the main purposes of an attribute set, is to allow configurable options, the most I have ever seen ( for marketplaces) is just over 15 or so sets to account for the different options at eBay & Amazon enforce, Size, Color, SizeColour, ShoeSize, ShoeSizeColour,ChestSize, ChestSizeColour etc….

But I do also understand that you may want to group up attributes so that they may be shown on the product details page (although 15,000 / 1,000 = 15) that’s still quite a large number of attributes per page and while I think of it, go careful adding over 300 attributes to one set as you will hit an inherent limit of what MySQL can do in a single table and you’ll get reindexing issues.

However assuming you must have 1,000 attribute sets and you must have 15,000 attributes that are all uniquely different, then the way I would do it is via the Magento SOAP API. To do this you would need the product_attribute.create call found here: http://www.magentocommerce.com…..reate.html

It does look scary to begin with, but it’s quite easy to handle, because if you can create one attribute via the API, creating loads is easy as it’s just a foreach loop to create them all (and a heap of time as this won’t be quick with 15,000).

Using their documentation example, you would want something like the PHP code below which I have borrowed from my personal code stash, however there must be an extension out there that can do this programmatically for you, if not it can’t be that hard to do and I’d suggest “oDesk” for that.

Anyway, this looks right in my editor, so it if it doesn;t work first time it’ll be very close and your csv file just needs to be a list of attribute label names, eg “My Attribute” and it’ll make the “att_my_attribute” internal code for you.

<?php
// Details

$SETTINGS = array(

"apiUser" => "your_api_username",
"apiKey" => "your_api_password",
"apiURL" => "http://magentohost/api/soap/?w…..&quot;,
"default_attr_set_id" => 4, // should always be 4
"api_ignore_errors" => false,

);

$csv_file = "path/to/your/csv_file.csv";

if( is_file( $csv_file ) && is_readable( $csv_file ) ) {

// Create the client
$client = new SoapClient($SETTINGS[‘apiURL’]);

// Login
try {
$session = $client->login($SETTINGS[‘apiUser’], $SETTINGS[‘apiKey’]);
} catch (Exception $e) {
// Something went wrong, either your login details or the API URL, but let’s print them anyway
echo "Something went wrong :(";
print_r($e);
exit;
}

// Now make the attributes from the CSV file;
create_atts_from_csv($csv_file);
echo "complete!";

}
/*
create_atts_from_csv($filename)
create attributes in format:
Internal Name, Display Name
*/
function create_atts_from_csv($filename)
{
$csv = $filename;
$CSV_ATTS = array();

$fp = fopen($csv, ‘r’) or die("can’t open file");
$first = true;
while ($csv_line = fgetcsv($fp, 1024)) {
if (!$first)
$CSV_ATTS[] = $csv_line;
else
$first = FALSE;
}
fclose($fp) or die("can’t close file");

foreach ($CSV_ATTS as $attribute)
{
create_attribute($attribute[0], $attribute[1]);
}
return;
}
/*
create_attribute($atts)
http://www.magentocommerce.com/api/soap/catalog/catalogProductAttribute/product_attribute.create.html
Note: is_html_allowed_on_front is only allowed with text fields
*/
function create_attribute($att_name, $att_label, $storeid=0, $type="text", $scope="global", $default_value="", $ignore_errors=true){

global $SETTINGS;
global $client;
global $session;

$new_att_id = null;

// Create Array
$data = array(
"attribute_code" => generate_attribute_code($att_name),
"frontend_input" => $type,
"scope" => $scope,
"default_value" => $default_value,
"is_unique" => 0,
"is_required" => 0,
"is_configurable" => 0,
"is_searchable" => 0,
"is_visible_in_advanced_search" => 0,
"is_comparable" => 0,
"is_used_for_promo_rules" => 0,
"is_visible_on_front" => 1,
"used_in_product_listing" => 1,
"additional_fields" => array(
"is_html_allowed_on_front" => 1
),
"frontend_label" => array(
array(
"store_id" => $storeid,
"label" => $att_label
)
)
);
//print_r($data);

// Note that if you have the extension SEO Layered Navigation installed, set the comment to "" as they have a bug in their code
// $data[‘comment’] = "";

try {
$new_att_id = $client->call($session, ‘product_attribute.create’, array($data));

}
// product_attribute.list
catch(SoapFault $e){
if( $SETTINGS[‘api_ignore_errors’] != true)
print_r($e);
}
//print_r($new_att_id);

// Now we need to add the attribute to the default group
if($new_att_id)
{
// Now add that to the
try {

$result = $client->call(
$session,
"product_attribute_set.attributeAdd",
array(
(int) $new_att_id,
$SETTINGS[‘default_attr_set_id’]
)
);
}
// product_attribute.list
catch(SoapFault $e){
if($SETTINGS[‘api_ignore_errors’] != true)
print_r($e);
}

} // /if new_att_id valid
}
/*
used for attributes to make internal magento code
*/
function generate_attribute_code($att_name, $att_prefix="att_", $maxLength=100)
{
$result = str_replace("(","_", $att_name);
$result = str_replace(")","_", $result);
$result = strtolower($result);
$result = preg_replace("/[^a-z0-9\s-]/", "", $result);
$result = trim(preg_replace("/[\s-]+/", " ", $result));
$result = trim(substr($result, 0, $maxLength));
$result = preg_replace("/\s/", "_", $result);

$result = $att_prefix . $result;

// there is a limit of 30 chars to attribute names
if (strlen($result) > 30)
$result = substr($result, 0, 30);

return $result;
}

Hope that helps :)

Matt

"Selling an item online is easy, but making living from a business that sells online, well that’s something different entirely!"

Ultimo Magento Theme

Avatar
Matthew Ogborne

Founder
October 22, 2013 - 9:07 pm
Member Since: July 18, 2013
Forum Posts: 4565
sp_UserOfflineSmall Offline
"Selling an item online is easy, but making living from a business that sells online, well that’s something different entirely!"

Ultimo Magento Theme

John1

New
October 23, 2013 - 10:45 am
Member Since: October 22, 2013
Forum Posts: 3
sp_UserOfflineSmall Offline

Hi,

Firstly, thanks very much for your help, i will give this a go shortly, but it looks like just what i was looking for, coupled with the link to magento that actually explains all the options.

Just to clarify my possition. I am selling mainly electricals, such as tvs, dvd players, computers, cameras, and all related sub categories and more. So lets take A TV, the way i see it, an attribute in magento could be used as a specification. So running with my tv it might be say:

Samsung 46″ LED TV

Specifications:

Display
Display Diagonal: 46″
HD type: Full HD
Display Resolution: 1920 x 1080 pixels
Aspect ratio: 16:9
Supported video modes: 1080p
Audio
Built-in speaker(s): Yes
RMS rated power: 20w
Ports & interfaces
HDMI ports quantity: 3
PC in (D-sub): Yes
DVI port: Yes
USB ports: 4
Ethernet LAN ports: 1

etc…..

Now for layered navigation, you would certainly be correct that most of these are not needed. In fact out of the 33 specs for this TV, i really only want to include the following, which i would set to dropdown (so that they can be used in layered navigation):

Display diagonal
HD type
Display resolution
HDMI ports quantity
PC in (D-sub)
Wireless LAN connection

So in magento i would perhaps have an attribute set called “LED TV’s” and within this set i would have groups like “Display”, “Audio” etc, ie each bold heading within the above example would be a group. And each group would contain attributes related to that group.

The only way round the issue of creating too many attributes in magento, is to only create the ones i require for layered navigation, set them to not used on the product page, and then create an attribute called something like “specifications” in the default attribute set, and somehow parse each product so that it can produce an html table containing all the specs.

In my mind however, it seems this is just as, if not more difficult to acheive.

What do you think?

Thanks again for your help
John

Avatar
Matthew Ogborne

Founder
October 23, 2013 - 11:05 am
Member Since: July 18, 2013
Forum Posts: 4565
sp_UserOfflineSmall Offline

Hi John,

I’m having flashbacks of an implementation at eSellerPro that I caught too late with a similar scenario and have been thinking of viable options for you.

This is what I have come up with so far:

  1. Break your product data down into categories of products that match eBay & Amazon (eg TV’s, Cameras, DVD players etc…)
  2. Use the eBay Sell Your Item form, the Amazon import sheets & what you feel would work for layered navigation for the Magento site to work out the required/delicious fields that you must or should enter
  3. Create attributes just for these fields (thus trimming down 15,000 to say 400 tops)
  4. Then with the attributes that you want to show with each product but we didn’t create attributes you add an additional description to each product (the short description is ideal for this) and make a UL bullet point list if the values are set

We then would have the key attributes that we need to populate item specifics on eBay, Amazon import sheets if the product needs to be created on Amazon (this maybe very few as their tech categories are very well populated) and have the key attributes to be able to make a decent layered navigation menu, but not overwhelmed the system and the user with a squillion selectable features.

With the attributes that were not included and the attributes we did include, we make a bullet pointed HTML list that we enter into the short description, then we can dump this short description on the website where ever we want, on eBay in a “Technical Specifications” block.

Todo this in excel wouldn’t be that hard as we would write a formula that sums up each attribute to make the LI bullet point and then add them all together at the end.

Right now that feels like a more manageable solution, what do you think?

Matt

"Selling an item online is easy, but making living from a business that sells online, well that’s something different entirely!"

Ultimo Magento Theme

Avatar
Dhawal Choksi

Excellent
April 23, 2014 - 12:51 pm
Member Since: January 21, 2014
Forum Posts: 24
sp_UserOfflineSmall Offline

Hi,

I am wanting to do something similar and on Magento Extension site I found a free extension. I am considering to give it a try.

I will udpate you once I have tried it out.

http://www.magentocommerce.com…..tions.html

Avatar
artur
Spain
Member
February 22, 2016 - 12:46 pm
Member Since: October 22, 2013
Forum Posts: 103

I used this and it worked like a charm.

https://www.magentocommerce.com/magento-connect/import-export-product-attributes.html

Hope it helps to someone, because I’ve found this threat via google :)

Good job guys :)

Buuu... Are you scared? Shouldn't be.
eBay store and eCommerce design.

Badeth - UE
Member
February 25, 2016 - 5:30 am
Member Since: October 23, 2015
Forum Posts: 513
sp_UserOfflineSmall Offline

Arthur,

Thanks a lot for sharing

Cheers,
Badeth

Avatar
artur
Spain
Member
February 25, 2016 - 4:52 pm
Member Since: October 22, 2013
Forum Posts: 103

No problem.

Always happy to help when I can.

Trying to stay active and be a part of your great community.

Best wishes,

Buuu... Are you scared? Shouldn't be.
eBay store and eCommerce design.

Wasiq Shahrukh

New
May 11, 2016 - 12:59 pm
Member Since: May 11, 2016
Forum Posts: 1
sp_UserOfflineSmall Offline

hi there,

i want to use your code but dont know where to keep this code in which directory and how to use it… i am a newbie… please help

 

Why Should You Join UnderstandingE?

 
  • Access to over 500 step-by-step video tutorials
  • +20 video courses available
  • Magento, M2E Pro, Magmi, eBay, Amazon & Design all covered
  • Everything is in 100% Plain English
  • Learn how to build your own multi-channel software for eBay & Amazon
  • Access to the community forums, meet fellow business owners like yourself

Join Now with 2 Clicks

 

Join now for less that £1 per day you can gain access to over 400 step-by-step video tutorials & learn how to build your very own multi-channel software.

 

Forum Timezone: Europe/London

Most Users Ever Online: 1012

Currently Online:
15 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Jim @ Moogento: 688

Steve Froggatt: 514

Badeth - UE: 513

Jimbob: 453

Paul Cartwright: 414

Forum Stats:

Groups: 6

Forums: 37

Topics: 5223

Posts: 27502

Administrators: Matthew Ogborne: 4565, Dave Furness: 4606