my code is the next:

$file_temp = file_get_contents(file_directory_path().'/productos/imagenes/prepro/'.$product->imagenes);
$file_temp = file_save_data($file_temp, file_directory_path() .'/productos/imagenes/'.$product->imagenes, FILE_EXISTS_RENAME);
$values['field_image_cache'][0] = array(
'fid' => 'upload',
'title' => basename($file_temp),
'filename' => basename($file_temp),
'filepath' => $file_temp,
'filesize' => filesize($file_temp),
'filemime' => mime_content_type($file_temp),
'data' => array(
'description' => basename($file_temp),
),
'list' => 1,
);

But it doesnt work!, what is the problem?, the product is created but no image.

Comments

longwave’s picture

Category: bug » support
Status: Active » Closed (won't fix)

Where is the rest of your code? You do not show a call to drupal_execute() or node_save(). You should look at http://drupal.org/node/330421 and post there if you have further questions, as this is not specific to Ubercart.

soylomass’s picture

Status: Closed (won't fix) » Active

Sorry but i have to reopen it, as it is related to ubercart and i have searched but the code for adding ckk images to not-ubercart nodes that i found in different forums/drupal issues wont work here.

The complete code is this:

$values['title'] = $product->nombre;
$values['type'] = 'product';
$values['body'] = $product->descripcion;
$values['uid'] = 0;
$values['model'] = $sku;
$values['list_price'] = $product->preciolista;
$values['cost'] = $product->costo;
$values['sell_price'] = $product->precioventa;
$values['default_qty'] = 1;
$values['shippable'] = 1;

$file_temp = file_get_contents(file_directory_path().'/productos/imagenes/prepro/'.$product->imagenes); //TODO andar
$file_temp = file_save_data($file_temp, file_directory_path() .'/productos/imagenes/'.$product->imagenes, FILE_EXISTS_RENAME);
$values['field_image_cache'][0] = array(
'fid' => 'upload',
'title' => basename($file_temp),
'filename' => basename($file_temp),
'filepath' => $file_temp,
'filesize' => filesize($file_temp),
'filemime' => mime_content_type($file_temp),
'data' => array(
'description' => basename($file_temp),
),
'list' => 1,
);
$rubro = obtener_rubro($taxonomies, $product->rubro);
$subrubro = obtener_subrubro($taxonomies, $product->subrubro, $rubro);
$values['field_product_taxonomy'][0]['value'] = $subrubro;
$marca = obtener_marca($taxonomies_marcas, $product->marca);
$values['taxonomy'] = array($marca);
$values['status'] = 1;
$node = node_submit($values);
node_save_noclearcache($node);

longwave’s picture

Status: Active » Postponed (maintainer needs more info)

But Ubercart product images are just standard CCK imagefields, so there should be no difference. Have you tried adding the same imagefield to a standard node type? Does the same code work there?

The full code is still missing; where does $product come from? Are you sure the file exists - does $file_temp get set correctly? Finally, node_save_noclearcache() is not a standard Drupal function.

soylomass’s picture

$product is a variable i get from a DB, and node_save_noclearcache() is just a copy of node_save function without clearing the cache to be more fast, but ive tried with normal node_save and it wont work.

The code works, because the only thing that wont get saved is the image.

$file_temp gets set correctly. Does anyone have done it?, if so, can you post your code?

soylomass’s picture

Priority: Normal » Major
Status: Postponed (maintainer needs more info) » Active

forgot to active it, read above post

longwave’s picture

Project: Ubercart » ImageField
Version: 6.x-2.4 » 6.x-3.x-dev
Component: Products » Code
Priority: Major » Normal

Ubercart images are just standard CCK imagefields. This is an imagefield question, not an Ubercart one.

soylomass’s picture

Well, can someone please help me?, you are all acting like mods, NOONE in this forum did something like this before?, noone can post his code or at least tell me WHATS WRONG with mine?...

longwave’s picture

I don't know the answer to your question, so I've moved it to somewhere it might get a better response.

quicksketch’s picture

Status: Active » Closed (won't fix)

I don't provide support on custom coding questions. I'd suggest looking at the existing FileField handbooks on this topic. http://drupal.org/documentation/modules/filefield