Home > Software design >  Prestashop - Add Image in product
Prestashop - Add Image in product

Time:06-09

I try to add an image in my product except that no image appears, if someone could help me!

My code :

$xml = simplexml_load_file('php://input');
$product = new Product($xml->id);
$product->id_category_default = (int)$xml->id_category_default; //categories
$product->name = $xml->name; //nom produit
$product->price = $xml->price; //prix
$product->id_tax_rules_group = (int)$xml->id_tax_rules_group; //1=20%;  2=10%;   3=5.5%;  4=2.1%;  5=EU VAT For Virtual Products
$product->ean13 = $xml->ean13; //code barre
$product->description = $xml->description; //description
$product->description_short = $xml->description_short; //petite description
$product->reference = $xml->reference; //reference
$product->weight = $xml->weight; //poids
$product->height = $xml->height; //hauteur
$product->width = $xml->width; //largeur
$product->depth = $xml->depth; //profondeur

$url = "https://www.google.com/logos/doodles/2014/first-day-of-school-2014-5475863151771648-hp.jpg";
$image = new Image();
$image->id_product = (int)$product->id;
$image->position = Image::getHighestPosition($product->id)   1;
$image->cover = true; // or false;
$image->add();
AdminImportControllerCore::copyImg((int)$product->id, (int)$image->id, $url, 'products', false);

$product->active = true;
$product->save();

Thanks !

CodePudding user response:

AdminImportControllerCore::copyImg() is a protected method and cannot be called outside the AdminImportController scope.

Consider moving the copyImg() method into your script.

  • Related