Jump to content

How to add a photo of the product "class Image" with thumbnails?


Recommended Posts

Hi everyone.

 

I write a module that integrates my warehouse program with the prestashop ver. 1.4.8.2.

I have a problem with pictures of products exactly thumbnails.

 

The following code is added image but thumbnails I have to generate manually. How do I do to generate automatically?

 

 

$imageNew = new Image();

$imageNew->id_product = (int)(id_product);

$imageNew->legend = array((int)(Configuration::get('PS_LANG_DEFAULT')) => $this->tow_arr[ $i ][ 'nazwa' ]);

 

if ($imageNew->add()) {

 

$new_path = $imageNew->getPathForCreation();

 

if (file_exists(_PS_MODULE_DIR_.'programer/sklep/images/'.$this->zdj_arr[ $i ][ 'filename' ]))

{

if (!Configuration::get('PS_LEGACY_IMAGES'))

$imageNew->createImgFolder();

 

copy(_PS_MODULE_DIR_.'programer/sklep/images/'.$this->zdj_arr[ $i ][ 'filename' ], $new_path.'.jpg');

}

}

 

 

Andrew thx www.2smoki.pl

Edited by andkozinski (see edit history)
Link to comment
Share on other sites

  • 5 weeks later...

Thanks for the reply but I did differently::

 

$imagesTypes = ImageType::getImagesTypes('products');

 

$imageNew = new Image();

$imageNew->id_product = (int)($id_prod);

$imageNew->legend = array((int)(Configuration::get('PS_LANG_DEFAULT')) => $text);

$imageNew->position = $NRP; // OR Image::getHighestPosition($id_pr) + 1;

if($NR==0)$imageNew->cover = TRUE;

else $imageNew->cover = FALSE;

$imageNew->image_format ='jpg';

$subdir =_PS_MODULE_DIR_.'programer/sklep/images/';

 

 

 

 

if ($imageNew->add()){

$new_path = $imageNew->getPathForCreation();

foreach ($imagesTypes AS $imageType){

if (file_exists($subdir.$file)){

if (!Configuration::get('PS_LEGACY_IMAGES'))

$imageNew->createImgFolder();

if (!imageResize($subdir.$file, $new_path.'-'.stripslashes($imageType['name']).'.jpg', $imageType['width'], $imageType['height']))

$this->_errors[] = Tools::displayError('An error occurred while copying image:').' '.stripslashes($imageType['name']);

}

}

if (file_exists($subdir.$file))

copy(_PS_MODULE_DIR_.'programer/sklep/images/'.$file, $new_path.'.jpg');

}

 

If someone wanted to add images to products with thumbnails.

 

Regards www.2smoki.pl

Link to comment
Share on other sites

×
×
  • Create New...