Magento set base Image Programmatically

By | February 23, 2014

Magento with vast extendable functionality help developer to reach the as per the Client Requirement

Recently need to set the base,thumbnail,small image Pro-grammatically.so after lot of R & D found the solution.Just we need to set the current  in the current code

<?php $setbaseimage=Mage::getModel('catalog/product')->load($objProduct);
$setbaseimage->addImageToMediaGallery($imagepath,array('image','small_image','thumbnail'),true,false);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
$setbaseimage->save();
?>

and once store is set images will get saved

Hope this will help you

2 thoughts on “Magento set base Image Programmatically

  1. Rocky

    where do i put this code please give me the path, as i am new to magneto..
    thanks

    Reply
  2. sandeep gulati Post author

    @rocky as we have added in our custom module …so you can add in product controllers save action! ..but for that you need to over write the controllers

    Reply

Leave a Reply