Creating product programmatically

i have a several XML where the product information is stored. It is a xml feed that my module gets through an API call. I have parsed the xml and got the product information. After i made some research here and there i understood that i need to use these API call..

Where $newproduct is a object array of commerce_product table heading such as sku, title .


My doubt is, i am not able to understand how to create the product attributes from my XML.

After going through the this link


In that link a post from rfay (also a member here) i guess that the product attributes are created with field_attach_submit function and its parameters. But if some one guide me fully then that would be great.

Please note, i am new to drupal 7.

Posted: Jun 18, 2012


aksdax on August 29, 2012

If your attributes are added fields then instead of using field_attach_submit u can just add the field values to the new product object
where und is the language and 0 is delta value and tid the value column.
you can insert all the values by adding the values to the product object then save using the commerce_product_save function.