I am creating a simple product via code but struggling adding the images correctly.
The product uploads fine and also the images too, which show ok on the frontend. But the radio buttons for base, small image and thumbnail are not ticked for the default value of the product. So the products image does not show up on the front end.
The code i am using to add the image is
$product->addImageToMediaGallery($filePath, array ('image','small_image','thumbnail'), false, false);
This is a multisite store. How can i get the default values of the image to tick when the image upload is done?
Thanks for the help!!
Best Answer
Here's the code I used recently for creating a product. It's based on having an array of image urls (
$imgArray
) rather than a single image url. It adds the first image in the array as the thumb/base/small and the rest as additional images.It was based on MagePsycho's blog post here;
http://www.blog.magepsycho.com/how-to-import-product-images-from-external-url-in-magento/
And the
_save_image
method;If you are using similar and it isn't working you might want to look at filepaths, permissions and also reindexing as potential issues that could fix your problem.