Before Product Add form load, I want an image to be attached to that product.

Image is being copied properly into files folder. But when add product form load, image is not being attached to image field.

$imgName = 'Image name';
$image = file_get_contents('Image name'); // string
$extImgName = explode('/', $imgName);
$file = file_save_data($image, 'public://'.$extImgName[count($extImgName)-1]);
$file = (array)$file;
$form['field_image'][LANGUAGE_NONE][0]['#default_value']['value'] = $file;

How can I resolve this ?

Comments

joachim’s picture

Status: Active » Closed (won't fix)
Issue tags: -Commerce product, -product image

This is probably to do with Image module that's part of D7 core, not this one.