Skip to content

Lindab How to import data from CSV file

IuliaFlorinaDuma edited this page Sep 8, 2021 · 2 revisions

How to import data from CSV file

Observations!

  • The CSV file must contain columns from "mappings" and vice versa, and as a delimiter we use ";".
  • On the server the import time lasts, we have to wait until all the data is imported.
  • Locally only part of the CSV file is imported.

Files for import in Lindab are:

In this example we import / update the product groups

  1. The function for import in the object:

public function importProductGroupData($data, $mappings = []) { \Application\Controller\Log::getInstance()->AddRow('mappings importCsv'); // import into parent with mapped parent via external relations $this->importParentCsv(0, "Productgroup", $data, $mappings); }

  1. The function for import in Workspace:

    public function importProductGroupData($data) { $log = \Application\Controller\Log::getInstance(); $log->AddRow('ImportProductGroup >-on parent --> ' . json_encode($data)); $dataNew = json_decode($data, true); $log->AddRow('ImportProductGroup >-on parent --> ' . json_encode($dataNew)); \Application\Controller\Log::getInstance()->AddRow('mappings importCsv'); $mappings = array( "category" => "category", "gama" => "gama" ); // import into parent with mapped parent via external relations $this->importParentCsv($this->getIdAsString(), "Productgroup", $dataNew[0], $mappings); return "Product group DATA IMPORTED"; }

3.The function in workspace(This is an exmple):

$data = array( "name" => "adminimport_csv_Productgroup", "actionExecution" => "inputform", "actionResponse" => 'refreshAll();', "viewId" => "viewId", "link" => "Importa din fisier CSV/Excel", "type" => "list", "parentType" => "Workspace", "objectType" => "Productgroup", "method" => "importDialogProductgroup", "serviceName" => "", "serviceMethod" => "", "template" => "", "scope" => "user" );

`$mongoObjectFactory->createAndAdd($typeComponent, (string)$returnAdminComponentGridProductgroup, $typeContextMenu, $data);`
`$workspaceD->createField($viewId, "importDialogProductgroup", \Application\Document\Field::TYPE_FILE, "", "fileName", "Fisier CSV/EXCEL", true, "", "");`
`$workspaceD->createField($viewId, "importDialogProductgroup", \Application\Document\Field::TYPE_BUTTON, "", "save", "Importă/actualizează productgroup", true, "method", "", "importProductGroupData(@fileName@);", "", "showMessage(\"@name@\");");`

tes

Clone this wiki locally