Question : Once Registered user upload custom image [custom image is Image which is uploaded by User ] in product view page & click on button "Save design" , we are creating Product Programatically . We want to upload that custom image to newly created product programatically.
Now we are using below code to upload existing image [ already saved image in server ] programatically.
protected function _createProduct($type, $doSave=true, $originalProduct)
{
$product = Mage::getModel('catalog/product');
// finally set custom data
$product->setName($originalProduct->getName());
// add product images
$images = array(
'thumbnail' => 'image.png',
'small_image' => 'image.png',
'image' => 'image.png',
);
$dir = Mage::getBaseDir('media') . DS . 'example/amasty/';
foreach ($images as $imageType => $imageFileName) {
$path = $dir . $imageFileName;
if (file_exists($path)) {
try {
$product->addImageToMediaGallery($path, $imageType, false);
} catch (Exception $e) {
echo $e->getMessage();
}
} else {
echo "Can not find image by path: `{$path}`<br/>";
}
}
if ($doSave)
$product->save();
// To save inside my_designs
$data = array('title'=>fav1_id,'product_id'=>$product->getId(),'customer_id'=> $customerId, 'value'=>image);
$model = Mage::getModel('example/mydesign')->setData($data);
try
{
$fav1_id = $model->save()->getId();
echo "Custom Design saved successfully";
} catch (Exception $e)
{
echo $e->getMessage();
}
// To save inside my_designs end
return $product;
}
Sidenote : Once Registered user upload custom image in product view page & click on Add to cart, we are saving Custom image in Server in path : media/custom_options/quote
and displaying image path in Table : sales_flat_quote_item_options
edit
part in question......