Jump to content

Importing only ,,Quantities" of products via CSV


Recommended Posts

Good Evening all :)

 

Is there anywhere tutorial for importing that specify data?

If there is no tutorial, could i ask you for advice.

 

How it should be done in 1.5 , by showing example?

 

Thank you very much in advance.

And keep the good work :)

 

Greetings

Adey

Link to comment
Share on other sites

Hi, i ve did file same as you told and when i finally clicking import data by selecting. id and qty , it gives me an errors:

 

2 errors

  • (ID: id) cannot be saved
  • Property Product->name is empty

 

How can i solve it?
Link to comment
Share on other sites

  • 2 weeks later...
  • 2 weeks later...
  • 2 weeks later...
  • 3 months later...
  • 3 months later...
  • 1 month later...

Yes an easy solution is to go to <admin_folder>/tabs/AdminImport.php and at the very top change:

 

public static $required_fields = array('name');

 

to:

 

public static $required_fields = array();

 

This will no longer require the name field. However I'm having trouble updating the quantities that way.

 

EDIT: Having looked in prestashops code, I found the issue of quantities not updating.

 

/* If match ref is specified AND ref product AND ref product already in base, trying to update */
/* Else If id product AND id product already in base, trying to update */
if ((Tools::getValue('match_ref') == 1 && $product->reference) || ($product->id &&
$datas = Db::getInstance()->getRow('SELECT `date_add`, `quantity` FROM `'._DB_PREFIX_.'product` WHERE `id_product` = '.(int)$product->id)))
{
if (isset($datas['date_add']))
{
$product->date_add = pSQL($datas['date_add']);
if($product->quantity <= 0)
$product->quantity = pSQL($datas['quantity']);
}
$res = $product->update();
}

 

In the above example, I simply added this code:

 

if($product->quantity <= 0)

 

Prestashop would update the quantity if reference ID matching was set during the import. If the quantity was 0 in the database, it would replace the actual quantity with 0. Now it will now longer do that.

 

PS: I'm using Prestashop 1.4.9 but it cant be that different in newer versions.

Edited by m33ts4k0z (see edit history)
Link to comment
Share on other sites

  • 11 months later...
×
×
  • Create New...