Jump to content

Import bulk images into Prestashop


Recommended Posts

Hello. 

I' developing a module to synchronize a management program with Prestashop online store. 

At the momment I have all the products and categories synchronized but I don't know exactely how to do it about the images. 

My idea is to have a folder on the prestashop server synchronized with the Management program with filenames like reference_X.jpg

My question is how to transform this files into prestashop files (I looked at the images folder and it goes into /img/P/x/y/z where x, y and z are the first, second and third number of the image id. 

Can you give me some hints about how to do it?

 

Kind regards, 

Link to comment
Share on other sites

Hello:

$image = new Image();
$image->id_product = (int)$id_product;
$image->legend = $product_name;
$image->position = Image::getHighestPosition($id_product) + 1;
$image->cover = Image::getImagesTotal((int)$id_product) ? false : true;
$image->add();

if (!self::copyImg($id_product, $image->id, $product_image_url)) {
	$image->delete();
}

You can copy the function copyImg from AdminImportController class and do your own modification if neccesary.

Regards

Link to comment
Share on other sites

18 minutes ago, Rolige said:

Hello:


$image = new Image();
$image->id_product = (int)$id_product;
$image->legend = $product_name;
$image->position = Image::getHighestPosition($id_product) + 1;
$image->cover = Image::getImagesTotal((int)$id_product) ? false : true;
$image->add();

if (!self::copyImg($id_product, $image->id, $product_image_url)) {
	$image->delete();
}

You can copy the function copyImg from AdminImportController class and do your own modification if neccesary.

Regards

Can you make an example with real data? 

I'm also struggling inserting categories because I was inserting directly on the database and then I read that is not recommended to do that!

i'm getting this error:

Fatal error: Class 'Controller' not found in C:\xampp\htdocs\viriatinhos\classes\controller\AdminController.php on line 33

Link to comment
Share on other sites

another thing

when i insert products with this code i don't get any quantities into the database! 

 

$product = new Product();
		$product->ean13 = $row['CODBARRAS'];
		$product->reference = $row['REF']; 
		$product->name = array((int)Configuration::get('PS_LANG_DEFAULT') => $row['PRODUTO']);
		$product->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') =>  $link_rewrite);
		$product->id_manufacturer = $row['MARCA']; 
		$product->id_category = $row['SECCAO'];
		$product->id_tax_rules_group = $tax_rule; 
		$product->id_category_default = $row['SECCAO'];
		$product->quantity = $row['STOCK']; 
 		$product->redirect_type = '404';
 		$product->quantity = 200; 
		$product->price = $price;
		$product->delivery_in_stock = '1-2 dias úteis após confirmação da encomenda';
		$product->delivery_out_stock = 'Entre em contacto connosco!';
		$product->out_of_stock = 2;
		$product->description =  $row['DESCRICAO'];
		$product->description_short = $row['RESUMO']; 
		$product->show_price = 1;
		$product->on_sale = 0;
		$product->online_only = 0;
		$product->meta_keywords = $row['PALAVRAS_CHAVE'];
		$product->date_upd = $data_tratada;
		$product->is_virtual=0;
		$product->add();
		

Does anyone knows why?

 

Link to comment
Share on other sites

20 hours ago, António Sousa i9 said:

another thing

when i insert products with this code i don't get any quantities into the database! 

 


$product = new Product();
		$product->ean13 = $row['CODBARRAS'];
		$product->reference = $row['REF']; 
		$product->name = array((int)Configuration::get('PS_LANG_DEFAULT') => $row['PRODUTO']);
		$product->link_rewrite = array((int)Configuration::get('PS_LANG_DEFAULT') =>  $link_rewrite);
		$product->id_manufacturer = $row['MARCA']; 
		$product->id_category = $row['SECCAO'];
		$product->id_tax_rules_group = $tax_rule; 
		$product->id_category_default = $row['SECCAO'];
		$product->quantity = $row['STOCK']; 
 		$product->redirect_type = '404';
 		$product->quantity = 200; 
		$product->price = $price;
		$product->delivery_in_stock = '1-2 dias úteis após confirmação da encomenda';
		$product->delivery_out_stock = 'Entre em contacto connosco!';
		$product->out_of_stock = 2;
		$product->description =  $row['DESCRICAO'];
		$product->description_short = $row['RESUMO']; 
		$product->show_price = 1;
		$product->on_sale = 0;
		$product->online_only = 0;
		$product->meta_keywords = $row['PALAVRAS_CHAVE'];
		$product->date_upd = $data_tratada;
		$product->is_virtual=0;
		$product->add();
		

Does anyone knows why?

 

You must know Prestashop best practices. What I provide is a real example, you just replace variables with real data. To update stock you must use StockAvailable::updateQuantity function. Regards

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...