Prestashop – Error creating image in a product

Issue

I have a problem when I create my image, when I run my code an image is created, but it does not want to display in my homepage but it displays well in my admin page

I don’t understand the problem since it appears well in the admin page, if someone could help me!

My code :

$xml = simplexml_load_file('php://input');
$product = new Product($xml->id);
$product->category = [2, 7];
$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
$product->indexed = 1;
$product->active = true;
$product->save();
$product->updateCategories($product->category);
$e = $product->getDefaultIdProductAttribute();
StockAvailable::setQuantity($product->id, $e, $xml->quantity);

$image = new Image();
$image->id_product = $product->id;
$image->position = Image::getHighestPosition($product->id) + 1;
$image->cover = true;
$image->save();
AdminImportControllerCore::copyImg((int)$product->id, (int)$image->id, $xml->urlImage, 'products', false);

On my home page :

enter image description here

On my admin page :

enter image description here

Thank you!

Solution

You’ll need to regenerate front office thumbnails for products from Design > Image Settings

Answered By – user3256843

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published