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!
Store Manager for PrestaShop is empowered with the useful ability to add images using drag&drop. Basically, all you need to do is to press “Add image” button, browse through the folders of your local computer, click on the necessary image(s) and move them to the place where product images can be previewed.
there are all product images, especially in subdirectories /img/p/1/ img/p/2/ img/p/3/ etc.
To change the image, click the Browse button under the Image field. Select your new image from your local computer. Once you have selected the new image, click on the Save button to activate it.
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();
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With