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..
1)commerce_product_new($producttype);
2)commerce_product_save($newproduct);
Where $newproduct is a object array of commerce_product table heading such as sku, title .
3)field_attach_submit
My doubt is, i am not able to understand how to create the product attributes from my XML.
After going through the this link
http://drupal.stackexchange.com/questions/7271/how-do-i-programmatically...
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.
Comments
If your attributes are added
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
e.g
$new_product->field_brand_name['und'][0]['tid']
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.