2

One of the things my Ubercart module needs to be able to do is programatically upload or link (this being preferred as it means I don't have to mirror it) an image and attach to Ubercart's product node. The user will give me some information, and my module will fill in the name, description, and product image. The product image is a big hurdle which I have no idea how to conquer.

The core Ubercart module product has a dependency on Drupal's core Image module, which is where I'm assuming is handling all the images. I thought I could learn how to do it by looking at the product module's code, but I'm having trouble wading through and understanding the thousands of lines of code. I'm not even sure of any other module that does something similar to what I'm doing, so I'm out of example code.

Does anyone know of a way to accomplish what I'm wanting to accomplish?

3
  • To which Drupal version are you interested? – kiamlaluno May 11 '11 at 7:06
  • @kia Sorry, Drupal 7. – TheLQ May 11 '11 at 22:10
  • Warning: This is crossposted on Ubercart's forums, although I doubt I will get a response there: ubercart.org/forum/support/21838/… – TheLQ May 22 '11 at 17:13
1

Ubercart already has the option of a predefined cck imagedfield, where do you plan on getting the correct image programatically? I remember using a default imagefield image before in the field settings.

Have a search for creating ubercart products programatically, its a fairly common thing as people import products from other dbs and excel files etc.

Here is a start, it all depends on where your data is coming from;

<?php
function MYMODULE_createnode() {

global $user;
if (isset(

$_POST['values_from_form']))
  {
    $values['nid'] = intval(check_plain($_POST['nid'])); 
    $values['title'] = check_plain($_POST['title']);
    $values['type'] = 'product'; //uc node content type
    $values['body'] = $_POST['body']; 
    $values['name'] = $user->name;
    $values['uid'] = $user->uid;
    $values['field_cck_field'][0]['value'] = $_POST['cck_field']; // Custom CCK field example for whatever it was you were wanting to do
    $values['status'] = 1;


    $node = node_submit($values);

    node_save($node);

    }
}
?>
1
  • Honestly, I dropped the project doing this a while ago. If you have a working solution I'll assume your answer is correct and accept it – TheLQ Dec 27 '11 at 21:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.