Advertisement
TheBiagio1996

Add image to product

Nov 7th, 2016
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.10 KB | None | 0 0
  1.     private function aggiungiImmagine($id_product = 0, $url = "", $isCover = false){
  2.  
  3.         // check the extension of image
  4.         $currentExtension = end(explode('.', $url));
  5.         $urlTemp = $url;
  6.         echo $currentExtension ."; ";
  7.         if ($currentExtension == "png"){
  8.             $this->png2jpg($urlTemp, _PS_MODULE_DIR_.'cmtCatalogImporter/tempDir/img/'.nomeImgTemp, qualitaImg);
  9.             $urlTemp = tempDirImgUrl .nomeImgTemp;
  10.         }
  11.  
  12.         $shops = Shop::getShops(true, null, true);
  13.         $image = new Image();
  14.         $image->id_product = $id_product;
  15.         $image->position = Image::getHighestPosition($id_product) + 1;
  16.         $image->cover = $isCover; // true or false;
  17.         if (($image->validateFields(false, true)) === true &&
  18.             ($image->validateFieldsLang(false, true)) === true && $image->add())
  19.         {
  20.             $image->associateTo($shops);
  21.             if (!AdminImportControllerCustom::caricaImmagine($id_product, $image->id, $urlTemp))
  22.             {
  23.                 //echo $url;
  24.                 //$image->delete();
  25.             }
  26.         }
  27.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement