It seems like I am the only one who cannot make use of
addImageToGallery(), as I found many solutions of importing images to/with a product through this function.
First of all, I cannot use directly
$product->addImageToGallery() as I found in all the examples, because I get error to call it on a non-object. Maybe because my
$product is a
SimpleXMLElement object. Therefore I went to this solution:
$model = Mage::getModel('catalog/product'); $product->$model->addImageToMediaGallery($filePath, array('image', 'small_image', 'thumbnail'), false, false);
I don't know if that is correct and if it is working, because my overall solution is not working. That was first.
Second, for a new product, the image gallery is null, so it has to be set. As I found in many examples, people use
$product->setMediaGallery(). That's cool and easy. Too bad that there is NO such function in the API. What is going on around here?!
Third, I am lost and have no idea how to proceed. I also tried the old goodie way: here go down to the end of Page 3, where he talks about Product Image.
That is my overall code, that I have, and that doesn't work:
$model = Mage::getModel('catalog/product'); $product->$model->setMediaGallery(array('images'=>array (), 'values'=>array ())); $filePath = $importImagesDirectory.$this->_getPresentationAttributeValue($product, '@Art="Bild" and @Rang="1"'); //this gives me full path of the image. It's correct, no worries. $product->$model->addImageToMediaGallery($filePath, array('image', 'small_image', 'thumbnail'), false, false);