Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Customising the CMS /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Swipestripe Save CSV File then import rows as pages - CSVBulkUploader


Go to End


1172 Views

Avatar
Vix

Community Member, 60 Posts

15 December 2015 at 4:44pm

Edited: 15/12/2015 4:46pm

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?