I have been trying to get the CSVBulkUploader to work by uploading a file then in the onAfterWrite function importing the data as a Page (Product in Swipestripe).
Custom CSV BulkLoader file:
class ProductCsvBulkLoader extends CsvBulkLoader {
public $columnMap = array(
'Title' => 'Title',
'URL' => 'URLSegment',
'Description' => 'Content',
'Subtitle' => 'Subtitle',
'ProductType' => 'ProductType',
'Price' => 'Price',
'ProductCode' => 'ProductCode'
);
public $duplicateChecks = array(
'ProductCode' => 'ProductCode'
);
}
Upload
class ProductUploader extends DataObject {
private static $db = array();
private static $has_one = array(
'CSVFile' => 'File'
);
public function onAfterWrite(){
parent::onAfterWrite();
$file_id = $this->CSVFileID;
$file = File::get()->byID($file_id);
$loader = new ProductCsvBulkLoader('Product');
$results = $loader->load($file->Filename);
}
}
if I use $file->Filename it gets an error of the file can't be found. If I hard code the full url I don't get any errors, but it also does not import anything.
Can anyone point me in the right direction of how I can get a CSV file of products to import into Swipestripe Products?