I have a product object, which I am creating in a PHP script. I need to add a thumbnail and a large image, which I have in a zip file. The file name contains the product ID.
If you have the Product ID ($id_product) and the image URL ($url), you can do the following:
$image = new Image();
$image->id_product = $id_product;
$image->position = Image::getHighestPosition($id_product) + 1;
$image->cover = true; // or false;
if (($image->validateFields(false, true)) === true &&
($image->validateFieldsLang(false, true)) === true && $image->add())
{
$image->associateTo($shops);
if (!self::copyImg($id_product, $image->id, $url, 'products', false))
{
$image->delete();
}
}