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.
Whats the best way to achieve this in code? I'm assuming I need to extract the images to somewhere in file system, but I have no idea how prestashop handles images.
thanks!
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();
}
}