Jump to content

Supply Order Csv Import By Supplier Reference


Recommended Posts

Hi all,

 

I was wondering if someone knows a fix/improvement for the following issue.

 

The normal way Prestashop handles a supply order import via csv is by identifying products by ID_product.

My issue is that it would be much easier to identify products by supplier_reference, since I always get a list from my supplier.

To deal with this issue I always spend a lot of time to match the supplier_reference to the product ID in Excel.

 

Does anyone know how to identify products by supplier_reference (or even reference) for the supply order detail csv import?

 

I've been fiddling around in the AdminImportController.php, but couldn't find a solution.

 

Hope someone can help.

 

Thanks,

 

Christiaan

Link to comment
Share on other sites

Do you mean importing products using a csv file from your supplier through BO > Advanced Parameters > CSV Import?

If so, there is an option called Use product reference as key that you could use if your products reference matches the ones from your supplier.

Link to comment
Share on other sites

Sorry if I don't understand your question.

Are you using a module to import supply order details through CSV?

In a default installation of 1.6 I don't see this option, there is only import for Categories, Products, Combinations, Customers, Addresses, Manufacturers, Suppliers and Alias.

Link to comment
Share on other sites

I've found it. I will try to help you with this but it will require some code editing and some tests on your behalf.

The main idea is to use the field Product ID as product reference and also maintain the current functionality with product id.

So if you put in column Product ID one row with product reference and the next with product id, both should work.

Before you start editing and testing you should make a backup!

 

On file YOUR_PRESTA/controllers/admin/AdminImportController.php add this function somewhere:

public function getProductInfoByReference($product_reference)
{
  $query = new DbQuery();
  $query->select('p.id_product, pa.id_product_attribute');
  $query->from('product', 'p');
  $query->leftJoin('product_attribute', 'pa', 'pa.id_product = p.id_product');
  $query->where('(p.reference = \'' . pSQL($product_reference) . '\' AND pa.default_on = 1) OR pa.reference = \'' . pSQL($product_reference) . '\'');

  return Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow($query);
}

Then edit the lines 3223-3227 into:

if (is_numeric($info['id_product'])) { // is product id
  $id_product = (int) $info['id_product'];
  $id_product_attribute = isset($info['id_product_attribute']) ? (int) $info['id_product_attribute'] : 0;
} else { // is product reference
  $prod_info = $this->getProductInfoByReference($info['id_product']);
  $id_product = (int) $prod_info['id_product'];
  $id_product_attribute = (int) $prod_info['id_product_attribute'];
}

Now test your Supply Order Details import with product reference instead of id.

 

Note

These changes should be done into an override, otherwise at an update you could loose them.

But for starters I think is more important for you to see it working, then you could move the changes into an override.

Link to comment
Share on other sites

Hi Gabdara,

 

Thank you very much for your effort. Unfortunately I get this error:

867. 
868. $message = $this->validateField($field, $this->$field);
869. if ($message !== true)
870. {
871. if ($die)
872. throw new PrestaShopException($message);
873. return $error_return ? $message : false;
874. }
875. }
876. 
877. return true;
 ObjectModelCore->validateFields - [line 278 - classes/ObjectModel.php]
 ObjectModelCore->getFields - [line 486 - classes/ObjectModel.php]
 ObjectModelCore->add - [line 210 - classes/stock/SupplyOrderDetail.php] - [2 Arguments]
 SupplyOrderDetailCore->add - [line 3162 - controllers/admin/AdminImportController.php]
 AdminImportControllerCore->supplyOrdersDetailsImport - [line 3392 - controllers/admin/AdminImportController.php]
 AdminImportControllerCore->postProcess - [line 171 - classes/controller/Controller.php]
 ControllerCore->run - [line 390 - override/classes/Dispatcher.php]
 Dispatcher->dispatch_16 - [line 122 - override/classes/Dispatcher.php]
 Dispatcher->dispatch - [line 54 - admin/index.php]
Link to comment
Share on other sites

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