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
Comment #1
longwaveWhere 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.
Comment #2
soylomass commentedSorry 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);
Comment #3
longwaveBut 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.
Comment #4
soylomass commented$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?
Comment #5
soylomass commentedforgot to active it, read above post
Comment #6
longwaveUbercart images are just standard CCK imagefields. This is an imagefield question, not an Ubercart one.
Comment #7
soylomass commentedWell, 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?...
Comment #8
longwaveI don't know the answer to your question, so I've moved it to somewhere it might get a better response.
Comment #9
quicksketchI 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