Jump to content

Importing attachment files (pdf)


Recommended Posts

  • 8 months later...
  • 1 year later...
  • 1 year later...

As rocky pointed out, there's no importer to do this currently.

 

If like me however you're now forced to roll your own, I googled for the relevant code and this was the first result. As such, I want to leave some notes for anyone else who's looking to do the same thing.

 

This code is taken from sections of controllers/admin/AdminProductsController.php from AdminProductsController::processAddAttachments().

 

   $filename = 'myfile.pdf';
   $id_product = 123;

	// Generate unique filename
	do $uniqid = sha1(microtime());
	while (file_exists(_PS_DOWNLOAD_DIR_.$uniqid));

	// Copy file to target
    copy($_FILES['attachment_file']['tmp_name'], _PS_DOWNLOAD_DIR_.$uniqid);

	// Create file attachment
	$attachment = new Attachment();
	$attachment->file = $uniqid;
	$attachment->mime = 'application/pdf';
	$attachment->file_name = $filename;

	// Create name and description for each language
	$languages = Language::getLanguages(false);
	foreach ($languages as $language)
	{
		    $attachment->name[(int)$language['id_lang']] = substr($filename, 0, 32);
		    $attachment->description[(int)$language['id_lang']] = '';
	}

	// Put to DB
	$attachment->add();

	// Attach to product
	$attachment->attachProduct($id_product);

 

Hope this sets someone in the right direction, until a good importer comes along.

Edited by 4mdev (see edit history)
  • Like 1
Link to comment
Share on other sites

  • 8 months later...

Well, I recently created a module for importing massive attachments to the product page (Prestashop 1.5.x), starting from a folder on the server where you previously uploaded your attachments.

You can import PDF, ZIP, JPG, PNG, GIF, DOC, XLS, PPT files.

There are some rules to follow for let the import works correctl (you can choose if use the ProductID or the Reference, and if the file name has 2 variables with a separator).

Actually it's in italian but I'm planning to improve it as soon as possible with multilanguage and more options.

As soon as I can I'll post a page on my site with all the specs and the price.

But if someone is interested, please PM me.

 

Of course the module works, as I did it for one of my customers.

If you have a lot of attachments, this module could save you a lot of time. ;)

  • Like 1
Link to comment
Share on other sites

Well, I recently created a module for importing massive attachments to the product page (Prestashop 1.5.x), starting from a folder on the server where you previously uploaded your attachments.

You can import PDF, ZIP, JPG, PNG, GIF, DOC, XLS, PPT files.

There are some rules to follow for let the import works correctl (you can choose if use the ProductID or the Reference, and if the file name has 2 variables with a separator).

Actually it's in italian but I'm planning to improve it as soon as possible with multilanguage and more options.

As soon as I can I'll post a page on my site with all the specs and the price.

But if someone is interested, please PM me.

 

Of course the module works, as I did it for one of my customers.

If you have a lot of attachments, this module could save you a lot of time. ;)

Hello, can you please let me know whitch module this is?

i need it quite urgently :-)!

Link to comment
Share on other sites

  • 1 month later...
  • 4 months later...
×
×
  • Create New...