Jump to content

Custom Product Importer


manoj_malviya

Recommended Posts

Hi all,

As my effort to give back to this great prestashop community, I want to share prestashop product importer.

I have developed some php classes, that can be used to push product data in prestashop from any source.

So far I have tested it with csv and xml, by virtually it can be used to import data from any source. Since It is developed
in OOP way, you can customize/ extend it to suit your need.

Note that I haven't developed them as a module but rather it will work as an standalone tool, and can be invoke via command line or url.

If anybody need/want to review. please let me know.

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Here you go.

Should be straight forward to understand

BaseClass : ProductImporter

Child Class : AccessoryImporter (an example import class)(work for xml data source)

AccessoryImporter Can be invoked via command line.

ini_set('max_execution_time', 600); //600 seconds = 10 minutes

require(dirname(__FILE__).'/../../config/config.inc.php');
require_once('ProductImport.php');
require_once('AccessoryImporter.php');
require_once('Logger.php');

$accessories = Simple_XML_Load('path to xml');

foreach($accessories ->accessory as $acc){
       $accessroyImport = new AccessoryImporter();
       $accessroyImport ->SetProductSource($acc);
       $accessroyImport ->Save();
   }

ProductImporter.php

AccessoryImporter.php

  • Like 4
Link to comment
Share on other sites

  • 7 months later...

Ok, this sounds very exciting. I will try to use it for 1.4.5.1 and see if it works. I have a db of 1000 products to import from a csv and need to update it periodically.

 

Well, I Am assuming that require_once('ProductImport.php'); actually means ProductImporter.php

Link to comment
Share on other sites

  • 6 months later...
  • 3 weeks later...

Hi! Thank you for the scripts, I do have few questions.

How can I use your script to bulk insert 1000 products with random attributes? I want to test Prestashop stability and performance and I can't find any code to help me import a single product from an external script uploaded to server.

 

If you help a bit, I can share the tests results. Thank you!

Link to comment
Share on other sites

Little bit like his example, but then:

for($i=0;$i<1000;$i++){
$accessroyImport = new AccessoryImporter();
$accessroyImport ->SetProductSource(array());
$accessroyImport ->Save();
}

And then edit AccessoryImporter.php to make some random values. Like:

protected function GetName(){
return "this is a random title ".rand(100000,999999);
}

You have to change almost every function in there to return something.

 

For features you could use:

protected function GetFeatures(){
return array('test'=>'bla','sfdsfd'=>'fsfd');
}

Attributes is currently not supported, but shouldn't be too complicated to make if you look at the function AddFeature in ProductImporter.php.

 

Good luck.

Link to comment
Share on other sites

  • 1 year later...
  • 1 month later...

A little contribution.

 

ProductImporter.php line 452 uses a deprecated function:

imageResize($newimage, $path.'-'.stripslashes($imageType['name']).'.jpg', $imageType['width'], $imageType['height']);

 

can be replaced with:

ImageManager::resize($newimage, $path.'-'.stripslashes($imageType['name']).'.jpg', $imageType['width'], $imageType['height']);

 

So you can also remove line 3 that is no more necessary:

 

include_once(PS_ADMIN_DIR.'/../images.inc.php');

Edited by giancarlo.spadini (see edit history)
Link to comment
Share on other sites

  • 1 month later...

Very interesting.

 

But you have a schema for XML file with products to import?

Where I can find an XML file as example?

 

When you write this:

$accessories = Simple_XML_Load('path to xml');

Hi Giancarlo,

 

Did you fint the xml schema for this script? Can you share it please?

 

Thank you.

Link to comment
Share on other sites

Hi Giancarlo,

 

Did you fint the xml schema for this script? Can you share it please?

 

Thank you.

 

No, i haven't found a valid xml for this script.

I have solved creating an array (the product) with the fields needed by the calls in function AddUpdated().

 

If your shop is in Italy, Portugal or Spain we have completed a module to start selling over 10.000 products from our dropshipping wholesales.

  • Like 1
Link to comment
Share on other sites

  • 8 months later...

Hi,

 

Someone know how to integrat this class in a script in order to import csv containing product ? I need to use a comand line way to import my base product and the only way to do it on my server is commande line as i dont have time out issue with command line environement. ( while if i use the built in csv function it fails)

 

cheers

Link to comment
Share on other sites

  • 5 months later...

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...