Automating product creation/updating
Hello,
As I write this I'm trying to chew my way through the API docs, but I'm not having much luck stringing the parts together that I need, so I hope somebody can help a bit.
My intention is to sync products in my DC catalogue from an external data source (so all products are created and modified programmatically based on that data). The code to update the catalogue would run via cron. There will just be one SKU per product display.
Having drilled into it a little, I see I can use commerce_product_new() to create a new instance of a given product type, but a completed product (created through the UI) has many other fields such as price, images, and other fields that have been added to the variation type. Also of course this is just a SKU/Product Variation (just about got my head round the nomenclature now, I think), so a Product Display
has to be created at the same time, which has its own fields (title, body).
Can this realistically be done programmatically, or am I better off just attacking the database directly? (I'd certainly rather just use "blessed" api methods if they're available, but I'll go the hackish route if there's no other option.)
Any advice/tips would be welcome, as this is altogether to wordy to usefully google for!
Comments
In the end I decided against going with Feeds, because it just adds too much bulk to the project and duplicates work I already did. Instead I'm using the entity API to create and modify products and display nodes.
The one part I can't yet manage that way is field_images. I think I need to look into the file API to work out how to create the files I upload as "managed" file objects. If anyone has any pointers for that I'd certainly welcome them.