andkozinski Posted July 5, 2012 Share Posted July 5, 2012 (edited) 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 August 31, 2012 by andkozinski (see edit history) Link to comment Share on other sites More sharing options...
shacker Posted July 8, 2012 Share Posted July 8, 2012 after this, you can use the image regeneration method. You can check in the images.onc.php file of prestashop to find the function Link to comment Share on other sites More sharing options...
andkozinski Posted August 7, 2012 Author Share Posted August 7, 2012 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 More sharing options...
shacker Posted August 14, 2012 Share Posted August 14, 2012 perfect. Thanks for share (remember to change title to solved) Link to comment Share on other sites More sharing options...
Recommended Posts