Cron to Download Backups via FTP
May 22, 2016
Synology: Restart Cron after Update
May 25, 2016

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->setFieldsToUpdate(array(‘price’));
$productObj->price = “12345”;
$productObj->save();

 

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

2 Comments

  1. Piyush says:

    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.

    • Ricardo Malla says:

      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.

      Cheers,

      Ricardo Malla

Leave a Reply

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