Magento Forum

   
Grouped Products / and or Custom Options via the API
 
TylerE
Jr. Member
 
Total Posts:  6
Joined:  2008-08-19
 

Hi, I’m writing some Import code against the XML-RPC, coming from a proprietary cart. I need, on some products, a way to do provide a color drop down with several choices. I don’t want to go the full Configurable product route, and custom options seems to be the way to go. However, I can’t find anything in the API to set up the options. Any suggestions? A grouped product might work also, although it’d be a bit tedious, for maintenance. Pricing / description / image on the variants will always be the same. Even there, I can’t find an API for doing the actual association.

 
Magento Community Magento Community
Magento Community
Magento Community
 
nikefido
Guru
 
Avatar
Total Posts:  481
Joined:  2008-07-11
New Haven, CT
 

If I am understanding correctly, I believe what you are after is a “configurable product”

 
Magento Community Magento Community
Magento Community
Magento Community
 
TylerE
Jr. Member
 
Total Posts:  6
Joined:  2008-08-19
 

Even if I went that way, I still don’t see a way to do it via the API. I’m working with several hunder products here...I really don’t want to do these by hand.

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 

I tried to get the same effect using csv import, not the API.
I added one product manually, setting up the custom option. I then exported it and the options-related fields were included in the data. (not the actual values, but container name and whether it’s required)
I then copied these for my other products and imported them.
The options fields got set, but the options don’t show up on the product, and when I look at the product detail page in the store, the Add to Cart button is missing.

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 

I found out why my custom options using import wasn’t working. The options database tables are set up for each option to be tied to a product, instead of a product having an option and other products having the same option. It’s not very object-oriented.
So the product ID is in the option table and the option ID is in the other option tables.

To do-it-yourself add your options, you have to populate catalog_product_option, catalog_product_option_price, catalog_product_option_title, catalog_product_option_type_price, catalog_product_option_type_title, catalog_product_option_type_value tables. It’s pretty straight-forward, but tedious and a really bad design.

 
Magento Community Magento Community
Magento Community
Magento Community
 
languagelover
Jr. Member
 
Total Posts:  2
Joined:  2008-08-15
 

I found the solution. This doesn’t use the csv import function though. I did custom php scripting to migrate osCommerce to Magento.
I had all the catalog_product_option tables etc populated correctly comparing them to fields that were created by Magento.

The options I created wouldn’t display though. After a lot of file hunting, I discovered that the options method was returning true. I believe the method was $this->_hasOptions();

Anyway, I did detailed file comparing with winmerge with two versions of my db backup sql.

I discoverd that magento also adds rows to the catalog_product_entity_varchar table for custom options.
Without this extra row in catalog_product_entity_varchar, your custom options will not display.

You need to add the following row. Here is an example. I’m not sure if the attribute id’s will be different for you though.

entity_type_id,attribute_id,store_id,entity_id,value
4,90,0,271,container1

4 is the product type
90 is the attribute id that corresponds to a row one of the eav_attribute table on regards to displaying the attribute. If anyone needs an exact table name, I’ll look it up.
store_id for me is 0
271 was one of my products its the entity_id column
Value is the last column. you can set this to container1, or container2.
container1 holds the options higher on the page than container2.

I hope this helps.

Let me know if any of you would need my services to accomplish this.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Web Man Walking
Jr. Member
 
Total Posts:  18
Joined:  2008-07-23
 

Hey

I am also trying to do something similar.  I am constructing a pharmacy website and the law requires that certain questions are answered for each product.  This can easilly be done using Custom Options (although had to increase the size of title in catalog_product_option_title from 50 to 150).

I have this working brilliantly for 1 product but of course to do hundreds will take ages.  All of my products that need these custom options are marked with an attribute p_product (1 or 0).

So really in pseudo-theory all I have to do is setup a cron job which will:

1. Get a set of all p_products (items with the p_product attribute set to 1)
2. Remove all custom options for all these items
3. Programatically add the appropriate records into the correct tables to allow this to work

As you can probably guess its 3. I am struggling with, does anyone have a diagram, or explanation as to what tables will need populated to do this?  Would really appreciate some help.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
joyously
Guru
 
Total Posts:  447
Joined:  2008-08-21
 

@Web Man Walking:  Don’t try to force the data into the database. Use the provided functions to make it work right and upgradeable.
The product class has a “duplicate” function that is used when you hit the Duplicate button in the back end under Edit Product. It will duplicate your options too.
So get one product set up right, then programatically hit the Duplicate button and modify the parts that are different, then save.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Web Man Walking
Jr. Member
 
Total Posts:  18
Joined:  2008-07-23
 

Thanks dude, great idea.  Can use this for future products, but right now I have 300+ products with a p_product attribute set waiting to have their questions added!  Any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top