I am building a small system which will pull products from an API and put each product into drupal db as nodes when the script is run. I am new to Drupal so I hope you will forgive any stupidness. So here is a very simple break down of what I have done so far.
- Used php simplexml to extract products using API.
2.Stored product name description,url etc in php variables.
-
At this point I need to add them to Drupal as nodes. I got this code from web which is exactly what I require (I think )
$node = new stdClass(); $node->type = "page"; $node->title = "Title"; $node->language = LANGUAGE_NONE; $node->path = array('alias' => 'your node path'); // Setting a node path node_object_prepare($node); // Set some default values. $node->uid = 1;
So simply putting my PHP variable in each of the above variable will do the trick. But I am stuck at where to put all this and my code? I mean do I create new php file in the drupal root or what? What files to include into it .How to do this.
Any help will be appreciated.
Regards,
Ahmar.
The way Ghommey said does work, however if you don’t want to have to do it by creating a module and then going to a page you can use
drupal_bootstrap()to allow you to include drupal into a .php file. Link to Documentation Here is a code sample: