1. Go to this page and download the library: Download dia-nz/importexport library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dia-nz / importexport example snippets
$importer = new GridFieldImporter('before');
$gridConfig->addComponent($importer);
$source = new CsvBulkLoaderSource();
$source->setFilePath("files/myfile.csv")
->setHasHeader(true)
->setFieldDelimiter(",")
->setFieldEnclosure("'");
foreach($source->getIterator() as $record){
//do stuff
}
$source = new CsvBulkLoaderSource();
$source->setFilePath("files/myfile.csv");
$loader = new BetterBulkLoader("Product");
$loader->setSource($source);
$loader->addNewRecords = false; // an option to skip new records
$result = $loader->load();
$category = ProductCategory::get()->first();
$source = new CsvBulkLoaderSource();
$source->setFilePath("productlist.csv");
$loader = new ListBulkLoader($category->Products());
$loader->setSource($source);
$result = $loader->load();