Exemple #1
0
 public function doPreview(ProductImportOptions $pio)
 {
     $data = [];
     $path = $pio->getUuid() . '/' . $pio->getFileName();
     $fileContents = \Storage::disk('imports')->get($path);
     $csv = Reader::createFromString($fileContents);
     $csv->setDelimiter(',');
     if ($pio->isIncludeHeaders()) {
         $headers = $csv->fetchOne();
         $data['headers'] = $headers;
         $csv->setOffset(1);
     }
     $previewRows = $csv->setLimit(25)->fetchAll();
     $data['rows'] = $previewRows;
     return $data;
 }
Exemple #2
0
 public function doImport(Request $request)
 {
     /*===============================================================================*/
     // Adjust these upload  / script execution time settings just for CSV uploads
     /*===============================================================================*/
     ini_set('upload_max_filesize', config('app.product_import_upload_max_filesize'));
     ini_set('post_max_size', config('app.product_import_post_max_size'));
     ini_set('max_input_time', config('app.product_import_max_input_time'));
     ini_set('max_execution_time', config('app.product_import_max_execution_time'));
     if ($request->hasFile('importfile')) {
         $filename = $request->file('importfile')->getClientOriginalName();
         $directory = Uuid::uuid4()->toString();
         $uploader = new UploadHandler();
         $result = $uploader->uploadCsv($request->file('importfile'), $directory, $filename);
         if ($result) {
             $importInfo = new ProductImportOptions();
             $importInfo->setVendorId($request->input('vendor'));
             $importInfo->setUuid($directory);
             $importInfo->setFileName($filename);
             $importInfo->setIncludeHeaders($request->input('includesheaders') ? true : false);
             $importInfo->setAddAsActive($request->input('addasactive') ? true : false);
             $importInfo->setIgnoreExisting($request->input('ignoreexisting') ? true : false);
             $importInfo->setSimulate($request->input('simulate') ? true : false);
             $importInfo->setDownloadImages($request->input('downloadimages') ? true : false);
             $importInfo->setResizeImages($request->input('resizeimages') ? true : false);
             $importInfo->setResizeImageWidth($request->input('imagewidth'));
             $importInfo->setResizeImageHeight($request->input('imageheight'));
             $action = $request->input('action');
             if ($action === 'PROCESS') {
                 if ($result) {
                     $this->dispatch(new ParseProductImport($importInfo));
                     echo "Done!";
                 }
             } else {
                 if ($action === 'PREVIEW') {
                     $previewData = $this->productImporter->doPreview($importInfo);
                     return view('admin.importpreview')->with('previewData', $previewData);
                 }
             }
         }
     }
 }