Pretashop: Add and Update products Programmatically

I’m working on a project where I need to add products from our ERP System to a Prestashop Catalog, and need to¬†regularly mass update (10,000 products) some information on specific product (Pricing, Stock Information etc…)

Current Situation:

  • I’ve managed to create script to import from a CSV and add the files to the DB using “$object = new Product();

First Problem

Every time I run the script the products get created again. I need to create some sort of IF, that when the product exists it does not create it again.

Here’s my solution:

$reference = $insert[‘reference’] ; #This Reference is the SKU that comes from my ERP
$sql = ‘SELECT id_product FROM `’._DB_PREFIX_.’product` WHERE reference=”‘.$reference.'” ‘;
$res = Db::getInstance()->getValue($sql);

if (!empty($res))

{echo “The product already exist \n\n”};

Else ¬†{echo “Starting to create the product”;


Second Problem

The second problem is that I need to be able to update the items which are already created. I believe I’ll use as script similar as the following:

$productObj = new Product($id);
$productObj->price = “12345”;


The problem here is that I need to get the product_id to Update buy I only have the Reference…

2 thoughts on “Pretashop: Add and Update products Programmatically

  1. Currently, I am in a situation similar to yours. Import products/brands/categories from ERP to prestashop, then Sync prestashop with the ERP at periodic intervals.
    I have created separate Maptables for ERP id to prestashop id ( didn’t knew about `reference` :p ) and will be using prestashop’s webservice for sync-ing.

    1. Dear Piyush,

      Sorry for my late reply. If you want my honest answer, I don’t like prestashop’s webservice. I instead use Talend Studio. You can do all kinds of integrations, super powerful and it has a free edition with very vast functionality.


      Ricardo Malla

Leave a Reply

Your email address will not be published. Required fields are marked *