Recently I needed to import 200 new products. The products all had between 3 and 4 options. The default Magento import does not allow you to import custom options for products so I customized the import to allow imporing of options.
To add this customization to your magento store first copy app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php to app/code/local/Mage/Catalog/Model/Convert/Adapter/Product.php. This will prevent upgrades from overwriting your changes.
Next you need to add some code to "local" version of Product.php (code/local/Mage/Catalog/Model/Convert/Adapter/Product.php). The line numbers below correspond to version 1.3 they may be a bit different in older versions.
At about line 566 you will see:
foreach ($importData as $field => $value) {
Just above that add:
$custom_options = array();
At about line 575 you will see:
$attribute = $this->getAttribute($field);
if (!$attribute) {
continue;
}
You will need to add some code above the continue statement.
/* CUSTOM OPTION CODE */
if(strpos($field,':')!==FALSE && strlen($value)) {
$values=explode('|',$value);
if(count($values)>0) {
@list($title,$type,$is_required,$sort_order) = explode(':',$field);
$title = ucfirst(str_replace('_',' ',$title));
$custom_options[] = array(
'is_delete'=>0,
'title'=>$title,
'previous_group'=>'',
'previous_type'=>'',
'type'=>$type,
'is_require'=>$is_required,
'sort_order'=>$sort_order,
'values'=>array()
);
foreach($values as $v) {
$parts = explode(':',$v);
$title = $parts[0];
if(count($parts)>1) {
$price_type = $parts[1];
} else {
$price_type = 'fixed';
}
if(count($parts)>2) {
$price = $parts[2];
} else {
$price =0;
}
if(count($parts)>3) {
$sku = $parts[3];
} else {
$sku='';
}
if(count($parts)>4) {
$sort_order = $parts[4];
} else {
$sort_order = 0;
}
switch($type) {
case 'file':
/* TODO */
break;
case 'field':
case 'area':
$custom_options[count($custom_options) - 1]['max_characters'] = $sort_order;
/* NO BREAK */
case 'date':
case 'date_time':
case 'time':
$custom_options[count($custom_options) - 1]['price_type'] = $price_type;
$custom_options[count($custom_options) - 1]['price'] = $price;
$custom_options[count($custom_options) - 1]['sku'] = $sku;
break;
case 'drop_down':
case 'radio':
case 'checkbox':
case 'multiple':
default:
$custom_options[count($custom_options) - 1]['values'][]=array(
'is_delete'=>0,
'title'=>$title,
'option_type_id'=>-1,
'price_type'=>$price_type,
'price'=>$price,
'sku'=>$sku,
'sort_order'=>$sort_order,
);
break;
}
}
}
}
/* END CUSTOM OPTION CODE */
Now further on in the code (about line 710) you'll see $product->save(); Just after this add the following code:
/* Remove existing custom options attached to the product */
foreach ($product->getOptions() as $o) {
$o->getValueInstance()->deleteValue($o->getId());
$o->deletePrices($o->getId());
$o->deleteTitles($o->getId());
$o->delete();
}
/* Add the custom options specified in the CSV import file */
if(count($custom_options)) {
foreach($custom_options as $option) {
try {
$opt = Mage::getModel('catalog/product_option');
$opt->setProduct($product);
$opt->addOption($option);
$opt->saveOptions();
}
catch (Exception $e) {}
}
}
That's it, you should be all set to import custom product options.
To import a custom option you need to add a new column to your CSV import file. The name of the column determines the name and type of the option. The format is: Name:Type:Is Required. For example, to create a required drop down option called "Size" your column header should be: Size:drop_down:1 (1 for required, 0 for optional). Here is a list of the Types, these are taken from the "Custom Options" screen in the Magento admin area.
- field: Field
- area: Area
- file: File
- drop_down: Drop-down
- radio: Radio Buttons
- checkbox: Checkbox
- multiple: Multiple Select
- date: Date
- date_time: Date & Time
- time: Time
Here's paired down example of the import format:
sku,name,description,price,Size:drop_down:1
T-Shirt1,T-Shirt,A T-Shirt,5.00,Small|Medium|Large
T-Shirt2,T-Shirt2,Another T-Shirt,6.00,XS|S|M|L|XL
In addition you can specify an addition price and SKU modifier for each option value. The syntax for this is Value:[fixed|percent]:price_modifier. For example if you have a product which costs $5 more for a Medium and $10 more for a large you would the following as the option value.
Small|Medium:fixed:5|Large:fixed:10
Here's the first example with additional price/sku modifiers.
sku,name,description,price,Size:drop_down:1
T-Shirt1,T-Shirt,A T-Shirt,5.00,Small:fixed:0:-SM|Medium:percent:2:-MED|Large:percent:3:-LRG
T-Shirt2,T-Shirt2,Another T-Shirt,6.00,XS:fixed:0:-XS|S:fixed:0:-S|M:fixed:1:-M|L:fixed:1:-L|XL:fixed:2:-XL
UPDATE: 5/12
Here's a sample CSV file I used to test code additions by @gancheff and @Brendan.
I hope this modification helps others who need to import product options.
Hello, Great Post. Is there a method of exporting custom options?
ReplyDeleteI haven't yet had a need to export the custom options. I'll take a look and see what it would take to do this.
ReplyDeleteThe only reason I have to export options would be to get the data format to import them in the first place.
ReplyDeleteIs the format you have above, the correct format for custom options?
Yes, the examples in the post show how to include custom options in your import file, just add the custom options column(s) to your existing CSV import file.
ReplyDeleteHi,
ReplyDeleteis it possible to have more than one custom options for each product?
Yes, specify each custom option as an additional column in your CSV file.
ReplyDeleteHello,
ReplyDeletethank you for your post. It was really helpful.
Is it possible when importing options to remove the existing ones so to avoid duplicates? If your example is imported twice all custom options will be repeated. Can you please suggest a way to first delete the stored in the database custom options and then write the ones in the CSV import file. Perhaps this should be done just before the saving of the imported options but I don't have idea how to code that.
Thank you.
Greetings!
With a little research I figured it out. In case anyone needs it here's the code:
ReplyDeleteforeach ($product->getOptions() as $o) {
$o->getValueInstance()->deleteValue($o->getId());
$o->deletePrices($o->getId());
$o->deleteTitles($o->getId());
$o->delete();
}
@gancheff, thanks for the code to remove existing options before adding the ones specified in the import files. I've added it to the code in the post.
ReplyDeletegreat work,
ReplyDeletejust some comments
1. When i run the import and look at my items there do not have a sort Order. How Can i set this for
a. The Custom Option Title/Group
b. for the Sub Items
2. If i have a large spreadsheet of products with some having one type of custom-option an another not using that custom-option. The Program still will create that option even if i have not set any data in that field.
Is there a way you can do a pre-check to see if the field has data then create the custom option group. Else skip over creating the custom-option group?
other than the above comments, great work!
brendan
ok,
ReplyDeleteso ive modified brians code to now accept a sort order. In both the header and details elements. But I still cant work out how to ignore fields where there is no record. The code will still create the header custom option
this: @list($title,$type,$is_required) = explode(':',$field);
is now @list($title,$type,$is_required,$sortHeader) = explode(':',$field);
This:
'sort_order'=>0,
is now
'sort_order'=>$sortOrder,
for the detail section see below:
$iSortDetail=1; foreach($values as $v)
{$parts = explode(':',$v);
$title = $parts[0];
if(count($parts)>1) {
$price_type = $parts[1];
} else {
$price_type = 'fixed';
}
if(count($parts)>2) {
$price = $parts[2];
} else {
$price =0;
}
if(count($parts)>3) {
$sku = $parts[3];
} else {
$sku='';
}
if(count($parts)>4) {
$sortOrder = $parts[4];
} else {
$sortOrder=$iSortDetail;
}
$custom_options[count($custom_options) - 1]['values'][]=array(
'is_delete'=>0,
'title'=>$title,
'option_type_id'=>-1,
'price_type'=>$price_type,
'price'=>$price,
'sku'=>$sku,
'sort_order'=>$iSortDetail,
);
$iSortDetail++;
}
so any ideas would be great
brendan
Brian,
ReplyDeleteI have tried out everything you have listed here. I am willing to pay you respectfully for your time, if you can just take a glance at my CSV file and my Product.php file.
Please contact me @ muaadlamen@gmail.com
Thanks
@Brendan, thanks for the suggestion for sort order. I'll take a look at your code and see if I can get it working.
ReplyDeleteBrian,
ReplyDeleteCan this be used to add brand attributes to the products? I have over one thousand brands and need to add the brands to the import file.
Thanks,
Shawn
hey brian,
ReplyDeletethanks. the sort order stuff is cool, as the code above works (abliet not quite so elegant!).
my main issue is where you have a large product file where some fields dont have values. The code still creates the Custom Option Header, but because there is no data in that field the line items are left blank.
So im really just stuck as to how i can first check the field contents has data if yes then create the Custom Option Header and then the line items
anyway, thanks again
brendan
Shawn,
ReplyDeleteWhat do you mean by brand attributes? Do you mean the images or something else?
brendan
@Brendan thanks for the contribution. I've added your code for including ordering. I also fixed the issue of blank option values (line 1: if(strpos($field,':')!==FALSE && strlen($value)) { )
ReplyDeletehey brian,
ReplyDeleteive just tested this out and it works.
thank you for the update,
Brian,
ReplyDeleteWhat I mean is adding the brand name to products and not creating an extra category. ie Sony TVs or LG TVs. Sony or LG would be a brand that I would attach to a certain group of products in the TV category.
Hi thanks for the post, Im not sure if Im missing something simple. I have inserted the custom code in to the product.php file, and added your sample custom data in the csv file, but I keep getting the "Notice: Undefined variable: custom_options in /homepages/17/d282805926/htdocs/theultimatedress6/app/code/core/Mage/Catalog/Model/Convert/Adapter/Product.php on line 732" error. Ps I had nothing in the app/code/local/ folder so I change the product.php in the app/code/core/Mage/Catalog/Model/Convert/Adapter/ folder and when that didnt work, I created all the additional folders in the local folder, and put the product.php in there. It must be reading the new code, but Im not getting any success. Any suggestions?
ReplyDeleteAlso I did manage to get it to import a couple of times without any errors, but the custom options didn't appear on the front end. PS I had some other custom code in the product.php adding additional gallery images, but I removed it hoping that it would work without with no success
ReplyDeleteOk I found out that I hadnt put a 1 in the hasoptions field. Another question, I can get the radio and dropdown buttons, but I just want to ad a text field, I need to have people input a colour number, this is the heading (Colour Number:field:1) I tried putting a 0 and a 1 in the field, but it doesn't show> Have you had success with text fields?
ReplyDeleteShawn,
ReplyDeleteYou can create an attribute called "brand" (Catalog->Attributes->Manage Attributes). Then just add a "brand" column to your import. My install had a "manufacturer" attribute already setup, it's a "drop-down" type so you have to predefine the list of values.
Online Wedding Planner,
ReplyDeleteThanks you found a couple of issues.
First, I forgot to put the code to initialize the $custom_options array in the post, I've added it above.
Second, I never tested with text fields as I don't have product with text input options. The code was not handling them properly. I've updated the code to properly handler field and area types. Your column name will work properly. The input options have slightly different parameters than radio, select, etc.
You have to specify a value for the option to be created, to create an input option with default values use: ":" as the vale you just have to put something in the row so it's not ignored. Here's the format:
"Title(not used):price_type:price:sku:max_characters"
Example: :fixed:5:MONGRM:25
This would create an input field with a fixed price of $5, a SKU modifier of "MONGRM" and a max of 25 characters.
Hope this helps!
Is it possible to add additional custom options without deleting the existing ones?
ReplyDeleteYes, you can comment out (or remove) the code block that removes the existing options. There's a comment marking it's placement in the code above.
ReplyDeleteHi brian
ReplyDeletei have added the code you provided its working perfect but when i import my file having one product only it adds one extra product itself and also process all product at the time of importing but it should process only those product which are specified in csv file . Is there any idea ?
Don't works for me and I dont know why :\
ReplyDeleteI did what you write, than I ran Import all products profile and nothing happens. All is importing as usual, no error message but i can't see any options set.
I'm lame, forgot "has_options"
ReplyDeleteHow much more is involved in getting the file upload custom option working. I noticed the comment in the section is just "TODO". I'm trying to code it in myself but any advice you have would be appreciated.
ReplyDeleteYou saved me a lot of time to do it myself. Thank you very much.
ReplyDeleteDoes thsi work on version 1.3.2?
ReplyDeleteI just found a fix for mass importing configurable products before I found your post. It seems your solution is much simpler. Could this solution be used to add more custom options to the configurable products already loaded into magento? Or would your fix overwrite the current configurable products and options?
ReplyDeleteHi can you explain what you mean by "existing csv file"? or where it is located. Do I have to make a new profile and export a new csv file?
ReplyDeleteIf I am not mistaken the locations of the files are var/export and var/import
ReplyDeleteI am building a store in Spanish and English. The Custom Options load properly and the only trouble that I am having with it's that the English custom options are being loaded as default(admin) and the values that I have assigned in the spreadsheet for the Spanish store do not get loaded.
ReplyDeleteI have already specified to which store I want to load the CSV file in the import profile. But this does not seem to work as well. Anyone has any idea or has experienced loading custom options in multiple languages?
Brian ,
ReplyDeleteI did all above you said , and when i run my CSV file, i got these words:
Invalid method Mage_Catalog_Model_Product_Option_Value::deletue(Array( [0] => 1))
Invalid method Mage_Catalog_Model_Product_Option_Value::deletue(Array( [0] => 2))
can you give some advice?
Hello Brian !! Thanks so much for your post. I was looking for something like that for a long time!
ReplyDeleteWell, I'm starting to do all modifications and I realize that I do not have this folders app/code/local/Mage/Catalog/Model/Convert/Adapter/Product.php. Can I create that to work on it? I'm working on 1.2.1.2 version.
I'll wait your repply!
Aninhabahr, You have to create the path yourself. Create the folder you mention and follow Brian's instructions and you will be fine.
ReplyDeleteHey this is really great work and really helpful since Magento doesn't have this option implemented yet. Has anyone come up with a way to export CSV with the custom options?
ReplyDeleteCan I use this in XML as well?
ReplyDeleteAmazing post Brian. Import worked flawless. I'd like to thank you for sharing this script.
ReplyDeletethanks for this but indeed, any chance to get this working for imported xml? would really need it, tried to do it like it is instructed but to xml, can't see attributes :( Please someone help if you just can
ReplyDeletethanks for the great post!
ReplyDeleteHey All,
ReplyDeleteThanks for the post Brian this was great with helping us create a module. Here is a link to more information: http://jc-websolutions.com/mag-customops.html
It is a module for custom options, tier pricing, and associated products import and export using the CSV option
This comment has been removed by the author.
ReplyDeleteI freaking love this post. Like seriously, thank you so much for this.
ReplyDeleteWorks like a charm!!
ReplyDeleteHey, Brian.you write this post yourself?
ReplyDeleteNow I have a problem.
Well, I've added the custom options successfully as I followed what you said above.
And the qustion is ,
I can add them ,but can't change them or delete them.
have you any idea?
Waiting for your answer . Thanks! Indeed!
My email is alivenk@gmail.com
I am having someone develop an online store using magento software.
ReplyDeleteIt is a distributor who is loading about 2000 of their products. I have found another distributor with about 20,000 items that I would like to add to the store.
The new dist supplied me with an excel database (without images). The items are grouped in columns with appropriate categories,subcategories, manufacturer, product id, description, upc, list price, my disc price, etc.
Some of the categories and subs are not in magento from the original dist. Do I need to set up these cat and subs first?
I am also interested in adding more items from a 3rd distributor.
All orders will be sent to me and in turn I will order from the appropriate dist.There may be instances when I will need to order from 2 different dist.
Is there a way to see this on the order? Does the dist field need to be in the database before importing?
I am not familiar with website programing but eventually want to learn how to do all this on my own.
Do you offer any service or have any solutions to my requests?
--
ThankYou,
Craig
702-521-5247
craigcriv@gmail.com
Hey Brian, can this work with importing grouped products?
ReplyDeleteThanks,
Shawn
Hello, this is a great modification, thanks for it! I'm having a problem getting the custom options to show for configurable products. When I run an import of a configurable product, the custom options do not show. They are entered into the database, but the main entity record in the database for the configurable product sets the "has_options" field to 0. I do have it set to 1 in my spreadsheet though. I've added some debug code into the import script and before $product->save() is called "has_options" is set to 1 but after $product->save() it is set to 0. It looks like $product->save() is resetting the "has_options" field. Can anyone help? I can't seem to find out why. :(
ReplyDeleteAfter integrating the code into magento version 1.3.2.2, I am having trouble adding options in certain circumstances.
ReplyDeleteIf the product is an existing product with an option set, when I import the csv file, it updates the options correctly with the values in the csv file.
If the product is a new product, or the product is already setup in the admin with no options setup, when I import the csv file, it doesnt seem to import the options.
Any tips of a possible solution?
-Matt
im having the same issues with my magento installation. the product options get imported but they dont show up in the frontend (are visible in the backend). once i save the product in the administration the options also show up in the frontend. any clues?
ReplyDeleteRun in 1.1.8?
ReplyDeleteIs it possible to have images in custom option? I mean a user gets product image changed if he selects a custom option from dropdown? If yes please let me know how?
ReplyDeleteThanks
Hey Brian,
ReplyDeletethanks for your hard work here! This just solved a lot of our problems.
However, I still can't figure out how to get sorting for details element. For example, for a shirt sizes, this...
S|M|L|XL|2XL:fixed:2.0
...will be displayed in alphabetical order. 2XL will be on top, then L, M, S, XL. Could you please help me on that ? Thank much.
Wonderful job Brian, You are more than a star!!!!! Thank you very much for this. It saves me a lot of time and effort.
ReplyDeleteCheers
S
It broke after upgrading Magento from 1.3.2.2 to 1.3.2.4, because the original Products.php is changed.
ReplyDeleteJust copy it again and re-apply the changes. Then it works again.
I've followed each step to the letter and this is not working for me. Import succeeds but ignored the custom options in the csv. Ive tried both with my own csv and with the sample one provided here.
ReplyDeleteAs Ronald's post above says it works fine in the latest version so I'm baffled as to why its not working for me! Any pointers??
My problem appears to be similar to what a few people have encountered. The import sort of works but requires you to go into admin, edit each item and add a custom option then clicking save. only now does the imported options show.
ReplyDeletealso when not following the process ive mentioned, customers cannot purchase the products what should have custom options, when they add to basket it says something along the lines of 'custom options required' but these options aren't visible to the user!
Any suggestion??
ignore me Im an idiot! I had missed putting the 'has_options' column into the csv so thats why it wasn't showing up on the products.
ReplyDeleteAnyway, thanks Brian, this is a fantastic contribution and its saved me a lot of stress!
Hi, at first thank you for this modification which really should be a core feature..
ReplyDeleteI just have one problem. It doesn't work for me and i dont know why :)
I am using Magento v1.3.2.4 and i want to have a custom option field for my products.
In my CSV file i have a column:
Gravurzeile_1:fixed:0:gr-zeile1:25
(this is my column head, has there something to be in the rows?)
which should, refering to your example show a custom option field.
The import process is running fine, no errors. But the custom option does not show up. I am trying to add the custom option to a simple product and have has_options set to 1.
Even the simple example
Size:drop_down:1
XS|S|M|L|XL
did not work for me.
I'd like to use this hack together with a great script that CSV-imports configurable products (see http://www.magentocommerce.com/boards/viewthread/49620/). I merged the code from this page into my product.php but didn't succed. No errors but no custom options either.
ReplyDeleteThere are a couple people in these comments that report this problem importing custom options for configurable products - so it might be not related to CSV-import hack for configurables.
I am using 1.3.2.4 btw.
Hi Brian,
ReplyDeleteI'm so in need of being able to add thumbnail images to my custom options.Ex if a custom option is set to color I would like to be able to add a color swatch images for black,white etc this feature should have been worked up along with a contribute like yours in a magento release I dont know why its not. I to also would like to be able to export the file once I create a simple product to get a feel on all the columns. I would greatly appriciate your help on accomplishing this I'm so in need.
Brian
email:rocket3609@gmail.com
Anyone find a way to save custom options on import and have them show up....rather then resave every product to have them show up?
ReplyDeletever 1.3.2.4
Import works great but custom options do not show up on front end after import.
How to import custom options in two languages for two store views? it doesn't work when I put store instead of default - english for example. All custom options are replaced by the latest file uploaded and visible just in one language for both stores. When the overwriting code in product.php is not commented out then I see both languages in the same time. Any solution?
ReplyDelete@Sarah - make sure you have 'has_options' set to 1 in your csv file for the products that have options.
ReplyDeleteWhat about multilingual stores? how to import custom options for non-default store view?
ReplyDeleteAmazing, it worked for me in my very first try.
ReplyDeleteThanks for sharing your knowledge on magento your blog is very helpful to our magento developer.
ReplyDeleteHI there,
ReplyDeleteim having problems, when i click an option the price main doenst change.
if i chose A2 + £45
the main price should change to £60
any help that would be great
cheers
josh
Hi
ReplyDeletethanks for share this information.
magento developers
I had an issue updating our product catalogue with new prices - Magento accepted the new prices (CSV containing SKU and Price), but also cleared all custom options.
ReplyDeleteTo resolve this, I restored the database backup I took before updating the prices, renamed app/code/local/Mage/Catalog/Model/Convert/Adapter/Product.php to app/code/local/Mage/Catalog/Model/Convert/Adapter/_Product.php so it would use the original import script, then did the import again and it worked.
Is there a bug in this code that could be removed, in case anyone else experiences the same issue?
Oh, thanks for the script by the way, saved a lot of time when I first imported all the products!
I have 2 custom options, they are uploading geat but 1t duplicates them, so i always have 2 of each, but if i upload a third or forth time it stays at just 2 duplicates. so i think the code you added to delete current option before upload works but not just right, any ideas?
ReplyDeleteThanks
any luck with 1.4.0.1? it seems incompatible...
ReplyDeleteHi, i cant seem to get this to work.
ReplyDeleteIm using 1.3.2.4 and when i upload the whole Buy box is missing. I have checked and there is a has_options = 1 in my CSV and also it written i DB.
Any help is more than welcome
Thanks
THANK YOU FOR THIS PAGE!!!
ReplyDeleteI can't get the file upload option to work. I tried "Upload Artwork:file:0:9" in the column header and "Upload Artwork" in the row. I also tried "1" in the row. Any thoughts?
Hi, Can you modify this Great code for V1.4.1 ?
ReplyDeleteI tried for V 1.4.1. It doesn't seem to work.
It works in 1.4.1, but as I said above, I didn't get the input type "file" to work. There are a couple of things left out above, but nothing that keeps it from working. Like, it's not obvious (to me) exactly how to enter the data in the csv for sort order to work. Through just trying stuff, I figured out that for sort order of the different custom options, in the csv header, type name:input-type:required:sort-order. e.g. Color:drop_down:1:6 (which is required and the 6th custom option down). While almost the same is true for the product row. name:price-type:price:sku-modifier:sort-order. e.g. Blue:fixed:2:_blue:2 which means blue is 2 dollars extra, adds _blue to the end of the products sku and is the 2nd option within the custom options for Color.
ReplyDeleteOh, use a pipe to separate different options. e.g. White:::_white:1|Blue:fixed:2:_blue:2|Red:fixed:3_red:3 means white doesn't cost extra (neither fixed nor a price is needed but the colon separators are needed if you want sku modifiers and/or sort orders). If you just type White|Blue|Red, then they will not cost extra, they will not modify the sku and they will sort alphabetically.
ReplyDeletethx for ur post.
ReplyDeleteI have another problem here.
Before importing the csv file, we have to map the fields in admin to their respective fields so that the data will go in correct columns.
So, in the case of custom options, to which field we will need to map the newly created custom option column?
Has anyone been able to get this to work with Magento 1.4.0.1?
ReplyDeleteThank you so much!
ReplyDeleteIt works fine in 1.4.1 too.
Nice... Importing custom options is great but how could we combine tier pricing along with categories?. I've seen quite a few attempt it within the forms. This would create the most AWESOME import available!...
ReplyDeleteI love the work you have done here. Thank you SO MUCH.
ReplyDeleteHi, This is exactly what I need, I tested it on my test site and it worked fine, but I have now put the code into the live site and it is not working. The import works without any errors, I have got the 'has_options' set to 1, but there is no custom options on the admin side or front end side.
ReplyDeleteAny Ideas. If you want to have a look at my product.php file go to:
http://rapidshare.com/files/358974614/Product.php
Thanks
I still can't get the "file" option to work. Everything else worked as expected. I really need file uploads as a custom option. Please help if you can. Feel free to pm me at magento's site to gw468 if you need to.
ReplyDeletehttp://rapidshare.com/files/359598420/Product.php.html
Hi,
ReplyDeleteWhen i add the fields for 2 drop down options in csv file lets for example
Size:drop_down:1 Type:drop_down:1 Small|Large Extra|Good
Then it only adds last option that is "Type" size custom options is not adding in the database.
Please help me what is wrong
Thnks
Hi Brian,
ReplyDeleteThank you very much for your code.
I was wondering if you could consider writing a small extension to enable products eraseby importing a line in the CSV
example : Put a SKU and write "DELETE" in a specific field would mean that you want this product to be erased.
It would be necessary to look for the product options and attribute so as to delete them properly.
I'm not familiar enough with Magento to do so but I'd be glad to donate for your time.
Thank you in advance.
Sorcy
I've tried everything I can, but cannot get this to work. I can tell Magento that I have options, but it doesn't import them, add them into the database or show in the BE.
ReplyDeleteI've downloaded the files above, added the comments manually, added the code into the Mage folder and the local one but nothing seems to work.
I'm using 1.3.2.4
Any help gratefully received.
Cheers
G
I really impressed this post. you are getting more comments about this post. keep it up. magento ecommerce is really one of the best shopping cart.Magento eCommerce
ReplyDeleteThank you! Very helpful.
ReplyDeleteThanks VERY much. Saved me hours. You rock.
ReplyDeleteThank you so much. You are amazingly awesome. I was always searching for such a simple solution. I've implemented it on my site and it's working on National Furniture Supply
ReplyDeleteThanks Brian for the post, and everyone for the helpful comments. Here's a couple of things I discovered implementing this on Magento 1.4.
ReplyDelete1. Missing custom options/buy box/add to cart button on the product page after import.
Not having the 'options_container' column populated (try "Product Info Column" or "Block after Info Column") could cause the entire 'buy box' to disappear from the product page after import.
2. The 'required_options' column in the 'catalog_product_entity' table does not get set when one of the custom options is a required option.
I found a very minor impact when you don't have this column set: adding a product directly to the cart from the product list generates a red error message instead of a green "notice" message. I don't know what else could be impacted by not having this column set so I fixed it anyway.
Here are the few lines I added to Brian's code:
SNIPPET #1:
$hasRequiredOptions = false;
WHERE:
Just after the custom_options declaration,
$custom_options = array();
// PUT SNIPPET #1 HERE
SNIPPET #2:
if (!$hasRequiredOptions && $is_required == '1') {
$hasRequiredOptions = true;
}
WHERE:
Right after the following,
/* CUSTOM OPTION CODE */
if(strpos($field,':')!==FALSE && strlen($value)) {
$values=explode('|',$value);
if(count($values)>0) {
@list($title,$type,$is_required,$sort_order) = explode(':',$field);
$title = ucfirst(str_replace('_',' ',$title));
$custom_options[] = array(
'is_delete'=>0,
'title'=>$title,
'previous_group'=>'',
'previous_type'=>'',
'type'=>$type,
'is_require'=>$is_required,
'sort_order'=>$sort_order,
'values'=>array()
);
// PUT SNIPPET #2 HERE
SNIPPET #3:
$product->setRequiredOptions($hasRequiredOptions);
WHERE:
Just before saving the product,
// PUT SNIPPET #3 HERE
$product->save();
Hi Brian
ReplyDeleteThis is fantastic. I can't believe it's not in the core Magento product yet.
Can I ask - did you get anywhere with the export function? I'm going to be giving this to shop data administrators ... and to ask them to maintain a spreadsheet as well as export/import is probably beyond them - and too risky.
Would be great if I could export with one click, and import with one click, with no spreadsheet step :-)
Thanks in advance :-)
Mark
My problem appears to be similar to what a few people have encountered. The import works great but requires you to go into admin, edit each item and add a custom option then clicking save. only now does the imported options show.
ReplyDeletealso when not following the process ive mentioned, customers cannot purchase the products what should have custom options, when they add to basket it says something along the lines of 'custom options required' but these options aren't visible to the user!
Does anyone solved this problem?
Thanks Peter
Peter, I had the same problem. Are you including the 'has_options' field with a value of "1" for the records that have a custom option?
ReplyDeleteJust implementing Magento myself. Very important subject. This and simply having Categories be defined in a starting upload. The problem w/ Magento is there are 1000 addons to this and that but then you get a mash up instead of a working system.
ReplyDeleteGlad to see you doing this work. Hopefully Magento (or someone here) will get this integrated in future versions of the software.
I will explore implementation next.
This comment has been removed by the author.
ReplyDeleteGareth - just got this to work with 1.4.1.0
ReplyDeletenoticed that in this version there is one difference in the for loop.
default has this:
foreach ($this->_requiredFields as $field) {
what is shown in the example is this:
foreach ($importData as $field => $value) {
this may have been an update in the new version. works like a charm.
thanks buddy.i searched entire google but your blog is best.thanks and keep it up dear.this code is working fine
ReplyDeleteThanks for this! Works perfect, very nice.
ReplyDeleteSome people (including me) were looking for a possibility to define the file-option. So I wanted to share my solution - it's quite simple.
Insert this block:
if(count($parts) > 5) {
$filetypes = $parts[5];
} else {
$filetypes = "";
}
after this part:
if(count($parts)>4) {
$sort_order = $parts[4];
} else {
$sort_order = 0;
}
Then, in the TODO-Section:
switch($type) {
case 'file':
/* TODO */
$custom_options[count($custom_options) - 1]['file_extension'] = $filetypes;
// no break!
Worked for me - just add the filetypes as the fifth part like this:
:fixed:35.00:some_sku:1:tif,jpg,pdf
I don't need the image-size, as I'm not dealing with images, but it would be easy to add that as well.
Just add two more parts, image-size-x and image-size-y and parse them like the filetypes-part. The corresponding fields in the database are called image_size_x and image_size_y.
To everyone that had the problem for re-save the product in order to see the custom options in the fornt page, just do the followings:
ReplyDeletein your CSV file under options_container
write down : Block after Info Column
This solve the problem for me
Hope that it help averyone (my version 1.4.1.1)
By the way, it's about time to add this to the core of Magento!
Hi Brian,
ReplyDeletevery interesting post, i'm also on Magento product import, if you can take a look a this :
http://www.magentocommerce.com/boards/viewthread/201210
i was just asked to add support of your custom options syntax.
Just wanted to say, this post is gold. Just finished importing a bunch of items with over 400 options (value:price:sku:sort) each. no problem at all 1.4.1.0. We'll see how well it handles the next set with 1,700 options each. Imagine having to create the options manually... Thanks Brian
ReplyDeleteHello,
ReplyDeletei have tried several things, but I could not get a good import. Nothing shows up in the frontend and nothing in the backend.
I have version 1.4.1.0. Can that be the problem. And how up-to-date is the above code?
Thanks in advance.
Just used this successfully on 1.4.1.?. I'd love to be able to export too, but it's super helpful already.
ReplyDeleteHello,
ReplyDeletethis good idea has been integrated in the extension Import_Products_categories__multiple_images_and_custom_options
and also in the magmi project as plugin.
But, as some people here, I don't understand how to customize a custom option for each store views.
In fact, more generally, I see nothing in the syntax to be able to change texts of a custom option for different store views corresponding to different langages. Is there no other solution than doing it manually ?
Hi Brian,
ReplyDeleteCan you please help me where I make wrong in adding the following data as custom options
psize:drop_down:1:1
Virgin of the Rocks (16x20):fixed:149:-SM|Virgin of the Rocks (20x24):fixed:171:-MED|Virgin of the Rocks (24x36:fixed:218:-LG|Virgin of the Rocks (36x48):fixed:299:-XL
Hi,
ReplyDeleteI have read so much about the has_options in this blog and I know, that I have to set the has options to 1. Otherwise, like it is in my case and many other cases in this blog, i only can see my imported custom options, when i first activate the custom option direcly in the product. And here is my question:
WHERE AND HOW CAN I SET THE CUSTOM OPTIONS TO 1?
Thank you; Tobi from Germany (i have the German Language Version of Magento 1.4.1.1
Oh YES! now I found it myself after 3 days of searching...
ReplyDeleteso here it is:
if you do an csv import there must me the colum has_options also in this csv file!!!
example:
"sku","name","description","price","Size:drop_down:1","has_options"
"T-Shirt1","T-Shirt","A T-Shirt","5.00","Small|Medium|Large","1"
in former times, i didn't need the colum "has_options" for csv imports, so i cancelled this colum. But when you start with importing custum options, you also need the colum "has_options" in your csv import.
Hope, to help others with this
Tobi
Internet Marketing Company
ReplyDeletehttp://www.sunbizar-technologies.com
A Leading Internet Marketing Company providing SEO Services over the globe with Affordable price, Sunbizar Technologies have 6 years experience in search engine optimization industry, web development, software development, and online marketing. Search engine optimization increase web traffic on your website,
Plumber
ReplyDeletehttp://www.europlumbing.co.nz
Hi guys,
ReplyDeleteThank you Brian for this work.
Here the missing /*TODO*/ code :
case 'file':
$custom_options[count($custom_options) - 1]['sku'] = $your_custom_sku;
$custom_options[count($custom_options) - 1]['file_extension'] = $your_custom_file_extension;
$custom_options[count($custom_options) - 1]['image_size_x'] = $your_custom_X_size;
$custom_options[count($custom_options) - 1]['image_size_y'] = $your_custom_Y_size;
$custom_options[count($custom_options) - 1]['price'] = $your_custom_price;
$custom_options[count($custom_options) - 1]['price_type'] = $your_custom_price_type;
break;
Don't forget to replace "your_custom_something" by your own code.
AMAZING, it took me days of searching to find your solution but 10 mins to implement it and your code saved me weeks of time. I cant thank you enough for your efforts.
ReplyDeleteI am having a problem with duplicate entries for the custom options on subsequent uploads of the product list...
ReplyDeleteI have the code in there which is supposed to get rid of old data, but apparently it's not working.
Any thoughts?
Forgot to mention I'm on 1.4.2...
ReplyDeletethank you, thank you, thank you! I also searched for days for this solution - i can't tell you how grateful i am to you for posting it, it worked perfectly!
ReplyDeleteThanks a ton mate... You saved my time..
ReplyDeleteHi Is there any method by which i can delete/update custom option in mass.. Because I found couple of attribute got duplicated. which is a big issue for me as of now. Please help.
ReplyDeleteI realize that 1.5 now supports Custom Options however the way they have set up the input in the CSV is far more complicated than your method. They require a separate column and row for each of the option titles. Your way is what I have been using for the past year and prefer it. Is there any chance you will modify your code to work with 1.5? Me developer tried copying over your existing code into 1.5 and came up with the following:
ReplyDelete(I copied the code into the proper place in the latest version. However there is a new problem. The latest version of Magento is checking your file for errors before allowing it to be imported. Strictly speaking this is a good thing. It however is a bad thing in regards to our custom options dealio.)
thank you.worked perfect.from your blog inspritation i also started myblog http://magentoforum.blogspot.com hope you suggest me to improve the content of blog
ReplyDeleteHi Brian,
ReplyDeletegreat work. is there any possibility for Magento 1.5? its displaying
Column names: Warranty:radio:0:2", "Second Option:radio:0:1", "Color_Number:field:1" are invalid
for above example. thanks
PLEASE: Ver 1.5.0.1
ReplyDeleteand... will any kind soul be willing to contact me by phone and walk me through this hack? Thanks!
nicedayvince@gmail.com
Hi Brian,
ReplyDeletePlease take a look at posted link (http://www.magentocommerce.com/boards/viewthread/225014/) and let me know if you have a solution. Seems like you know how to handle these configurations on products.
Thank you so much for this easy to use walk though! I had no troubles inserting it in to my website at all
ReplyDeleteIts really so nice of you for sharing this.I was facing lot of coding problems.This is one of them.Now its solved.I got better idea due to this.Thanks again.
ReplyDeleteMagento Themes
Hey, thanks for this script, custom options are imported, but not shown in frontend.. I have to save the product. I have set has_option to 1, but this doesnt solve the problem. Please advice.
ReplyDeleteIm using magento 1.5.
ReplyDeletefor magento beginnners this forum is useful see this magentoforum.blogspot.com
ReplyDeleteIt looks very informative.So i get some aided information.I bookmarked your site for further updates.web design oman
ReplyDeleteIt was such a help. My friend's e-commerce website is also run by magento and he had been searching for this option for quite a while now. Thanks for the share.
ReplyDeleteAlice
Liposuction Chicago
This comment has been removed by the author.
ReplyDeleteThis really helps.I guess all you have to do is to specify a value for the option to be created, to create an input option with default values use: ":" as the vale you just have to put something in the row so it's not ignored.
ReplyDeleteMiamii Buick Dealer
Hundreds of ecommerce systems exist, but very few can match the power of Magento. Just like reading to instructions online but nothing beats to the one you provided which is detailed and accurate. And like looking for a good e-commerce site is like looking for
ReplyDeleteDouble Roller Blinds that fits your needs and lifestyle.
Great Boss! Your code and way of explining things need salutation.............It helped me a lot and worked at first trial.
ReplyDeleteThanks a lot
Worked on Magento ver. 1.4.1.1
ReplyDeleteNice post. This post is different from what I read on most blog. And it have so many valuable things to learn.Thank you for your sharing!
ReplyDeleteWebsite Design Company
tried to import on magento 1.5.1.0 it imported as normal, and the custom options did not show.
ReplyDeleteHey Brian,
ReplyDeleteThanks for such a useful post, it helps but i got stuck while importing configurable products with custom attributes and if you can provide any dummy csv file that import configurable products, that will be really a great help. Please help me!!
Thanks in advance !!
Sorry , but i'm having trouble with this, I think I have put the code in correctly, but when i go to import the csv it still doesn't recognise the Size:drop_down:1 field. Can I send someone my products.php file to check for me? I would be very grateful.
ReplyDeleteThanks in advance!
HI
ReplyDeleteI also cannot get this to work. then I found this thread, but I have absolutely no idea what to enter in the TODO section (I only want to import "size" custom options, such as "35", "44", etc...)
Someone please help.
Thanks
case 'file':
$custom_options[count($custom_options) - 1]['sku'] = $your_custom_sku;
$custom_options[count($custom_options) - 1]['file_extension'] = $your_custom_file_extension;
$custom_options[count($custom_options) - 1]['image_size_x'] = $your_custom_X_size;
$custom_options[count($custom_options) - 1]['image_size_y'] = $your_custom_Y_size;
$custom_options[count($custom_options) - 1]['price'] = $your_custom_price;
$custom_options[count($custom_options) - 1]['price_type'] = $your_custom_price_type;
break;
Don't forget to replace "your_custom_something" by your own code.
Hi,
ReplyDeletedidn't work for me as well, however I'm not such computer guy. Found another way to import products along with options, categories and other things like that - it is a software program, something like "magento store manager" or so (don't remember exactly) - as for me it was working perfectly when I tried it. There's one big disadvantage - it is not free and my trial period expired... Guess this might be useful for someone anyway
Thanks
Magmi (http://sourceforge.net/apps/mediawiki/magmi/index.php?title=Main_Page) can import product with custom options using the custom options plugin based on the syntax described in this blog (with some enhancements).
ReplyDeleteIt can do this fast and it's free.
This comment has been removed by the author.
ReplyDeletei've got this error when trying to run import profile script within another maegnto website:
DeleteFatal error: Call to undefined method Mage_Catalog_Model_Product_Attribute_Backend_Media::addImagesWithDifferentMediaAttributes() in /home/arredpit/public_html/app/code/local/Mage/Catalog/Model/Convert/Adapter/Product.php on line 810
This is working on Magento 1.5 too. Just you need to add a column in csv 'has_options' & set the value to '1' for the products which are having custom options.
ReplyDeleteThanks for post btw.
Thanks for taking the time to share your thoughts.Your post is truly informative for me and i am so grateful to you for sharing this informative post here.
ReplyDeleteEcommerce developer
really need full information thanks for sharing
ReplyDeletefreelance web designer hyderabad
murthy full info about what in specific? this article may be considered as pure enlightment on this matter of massive importing. Everything is so well explained. i've found that the author has made wven corrections to the original
ReplyDeletepost so that everyone can attain to the perfection of this script, if we can call it that way. Post or write bout uour need. Help someone
and you'll get help.
Great article magneto developer..really an interesting and useful information is provided with a nice ideas here.
ReplyDeleteweb designing company
working with magento 1.6? :(
ReplyDeleteworks great... just remember to upload csv file with the "has_options" column with "1" value....!
DeleteHi, were you able to get this working with 1.6. Please email me kevin@kevinw.me
Deletehi
Deletewould you be able to help me i followed the instructions to the letter and also made sure has_options colomn has 1 in it, but it isnt showing the options im using magento community 1.6.1. email me a getitonfancydress@hotmail.co.uk
Dont worry i have managed works beautifully, forgot to put spaces between the separator and the next option.
DeleteIs there anyone can tell me where I can find the files I exported? yoursite.com/public_html/var/export, this seems do not work...
ReplyDeleteThanks,
Website design Services
Magento 1.6.2
ReplyDeleteI get error on import.
Column names: "Boxed Chocolates:drop_down:0", "Bouquet_Size:radio:1", "Mylar_Balloons:drop_down:0", "Stuffed_Animal:drop_down:0" are invalid
I got the same error, I'm runing Magento 1.7, does anyone know the fix for this?
DeleteBy reading this only I came to know that we can import products.
ReplyDeleteiPhone Application Development | Android Application Development | Mobile Application Development
This comment has been removed by the author.
ReplyDeleteHello,
ReplyDeleteA very Very Very good tutorial Post by you.
I was searching this from last week.
But really this found me today and I am feeling too glad n enjoying this code.
Still i facing one little problem..would you like to help me?
I have set custom options "STICHING" with 5 option "CHECKBOX".
Blouse stitching:fixed:300|Blouse stitching and fall beding:fixed:25|Patticoat:fixed:1000|Fancy blouse stitching:fixed:300|Pre-stitched saree:fixed:400
it set only main title "STITCHING OPTIONS" and next nothing do anything..
please help little bit...hope..
thanks
Praful
Great work! i tested it, worked nicely for me.
ReplyDeleteit works fine. It has its consequences though.
ReplyDeleteIt happened to me that i started working for http://www.arredo-shop.it.
- The used to input every single product and customize options manually as magento wants. They had about 2300 products.
- I made the configuration to the file and started importing greatly some 1500 new products.
- Then they asked me change prices of all products using the same "batch" strategy (formerly they used to change them prices manually, and that is one by one...argghh)
So they prepared the new prices using my 2 columns "comma separated" open office file and was just ready to import them. (one column for the "sku" and one for the "price")
WHAT HAPPENED?
All "new" products (imported by me with my script) where flawlessly updated.
...All 2300 "old products" (the ones they customized manually so patiently..)
simply L O S T THEIR CUSTOM OPTIONS!
so just b e aware.... awful issue. Learn from this story to avoid losing your job.. help others understand..
Excellent information and nice to see you, Thanks
ReplyDeleteMagento Development
Works perfect on Magento ver. 1.7.0.2. Thanks!
ReplyDeleteHi, How you make it works in ver 1.7.0.2?
DeleteI get this error:
"Column names: "Packaging:drop_down:1" are invalid"
Magento cannot detected the column
Hi All,
ReplyDeleteI need to change order the configurable product dropdown in front end. There is a option in admin panel but client requires that order is default or we have to give the option in csv import file. I tried lot but not yet get done. So I planned to update the position field directly in "catalog_product_super_attribute" table when importing product. Anyone can you tell where is insert query..?
Advance Thanks!!!
i just want to thank u for ure work, really helpful
ReplyDeleteHello,
ReplyDeleteFor Add Product Options Value Using Magento API and Excel Sheet great help at folllowing url :
http://www.webslike.com/Thread-How-To-Add-Product-Options-Value-Using-Magento-API-and-Excel-Sheet
Hi,
ReplyDeleteI'm having a problem with Magento 1.7.0.2:
I can't get it working.
I had to create new folders for the local PHP file and I changed the file like you wrote.
Now, when importing the products, there's only one product that gets the curstom values. All the others don't. Please help me!
Greetz
I got it working!
DeleteThe Has_options field was zero...
But now, with some products, I'm getting the same option three times...
Deleted and added all products again,... It seems to work now :)
DeleteE-commerce now a days is really helpful in expanding business.And your blog has also provided very good information,it's useful to every one.
ReplyDeleteWeb development Bangalore
thanks for nice tutorial for me its a different thought
ReplyDeleteI want to set the first value in a dropdown is default value in product page.
web development company in oman
ReplyDeleteThanks for sharing these wonderful designs, its helpful to all.
Magento developer should keep the daily update in website development and make a great ideas to build a unique style the website.That is the good responsibility for being expert in magento development field.
ReplyDeleteMagento Development bangalore
Column names: "Tyre Size:drop_down:1" are invalid
ReplyDeletehow to fix?
Hi Brain
ReplyDeleteI have a color-swatches-for-custom-options extension with me. I can upload the custom option details with MAGMI (Color:drop_down...etc), but I don't know how to upload the custom option images with MAGMI. if you know way to do it. Please let me know. this one is TOP URGENT!!!!
E-commerce now a days is really helpful in expanding business.And your blog has also provided very good information,it's useful to every one.
ReplyDeleteResponsive web design company | Responsive web design services
I just want to know weather it supports with Magneto CE 1.7 as i tried and it's not working.
ReplyDeleteMagento Integration is explained very discreetly and effectively . thanks
ReplyDeleteHi
ReplyDeleteit doesn't working
I agree to Esha. Even this helped me for my magento development company website : Parsys Media
ReplyDeleteHi All,
ReplyDeleteProgrammatically Update Custom Option Store Wise while any product Add / Edit Using observer.php after save product event
i.e.
I have two store in my magento project
1/ Wholesaler
2/ Retailer
Now, i want to add single product and display it in both store with different price. So, i have used Simple Product with Custom Option.
Product Name : T-Shirt
Wholesaler Store
------------------------
Red : 50
Green : 60
Blue : 70
Retailer Store
-------------------
Red : 150
Green : 160
Blue : 170
Now, if i want to add 10Rs in Wholesaler Store and 20Rs. in Retailer store then how can we proceed on it.
Thanks,
Snehal
Thank you for sharing with us these magento beginner's guide
ReplyDeleteyou can check at here http://magentomaster.in/import-product-option-from-csv/
ReplyDeleteMe too! I just want to know weather it supports with Magneto CE 1.7 as i tried and it's not working.
ReplyDeleteShip Products to the Philippines
Fully appreciate the value you are providing here.
ReplyDeletethanks for posting this blog. its really very helpful for us.
Magento Custom Stock Status
Many thanks for that information. Aided us all to help encourage nearly all how this works and also exactly what they may achieve by using these types of suggestions.Customer Support Page
ReplyDeleteMagento Product Data Entry Services provide to Get Customize Ecommerce Website and Increase your online Sales, Increase revenue while reducing time with end-to-end e-commerce solutions
ReplyDeleteNice Blog, thank you for sharing the useful information. Visit our magento development company india
ReplyDeleteNice blog. Thanks for sharing the information. visit our magento development company india
ReplyDeleteThanks for such a knowledgeable post.
ReplyDeleteVisit our website:
IEC code online
www.indianwesterlies.blogspot.com
Thanks for such a knowledgeable post.
ReplyDeleteVisit our website:
www.indianwesterlies.blogspot.com
IEC code status
It was such a help. My friend's e-commerce website is also run by Magento expert in dubai and he had been searching for this option for quite a while now. Thanks for the share.
ReplyDeleteHi All,
ReplyDeleteYou can use one more option and try the third party extension to import or export magento 2 custom options
<a href="https://seoexperts.ae/>Seoexperts.ae</a> : great blog post
ReplyDelete