Skip to content

Commit 3a9f050

Browse files
committed
ACPT-493: Upload csv with request parameter
1 parent c0c7f9d commit 3a9f050

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

app/code/Magento/ImportExport/Model/Import.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ class Import extends AbstractModel
193193
*/
194194
private $messageManager;
195195

196+
/**
197+
* @var SourceFactory
198+
*/
199+
private $sourceFactory;
200+
196201
/**
197202
* @var Upload
198203
*/
@@ -215,6 +220,7 @@ class Import extends AbstractModel
215220
* @param DateTime $localeDate
216221
* @param array $data
217222
* @param ManagerInterface|null $messageManager
223+
* @param SourceFactory|null $sourceFactory
218224
* @param Upload|null $upload
219225
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
220226
*/
@@ -235,6 +241,7 @@ public function __construct(
235241
DateTime $localeDate,
236242
array $data = [],
237243
ManagerInterface $messageManager = null,
244+
SourceFactory $sourceFactory = null,
238245
Upload $upload = null
239246
) {
240247
$this->_importExportData = $importExportData;
@@ -252,6 +259,8 @@ public function __construct(
252259
$this->localeDate = $localeDate;
253260
$this->messageManager = $messageManager ?: ObjectManager::getInstance()
254261
->get(ManagerInterface::class);
262+
$this->sourceFactory = $sourceFactory?? ObjectManager::getInstance()
263+
->get(SourceFactory::class);
255264
$this->upload = $upload ?: ObjectManager::getInstance()
256265
->get(Upload::class);
257266
parent::__construct($logger, $filesystem, $data);
@@ -304,7 +313,6 @@ protected function _getEntityAdapter()
304313

305314
/**
306315
* Returns source adapter object.
307-
*
308316
* @Deprecated
309317
* @see \Magento\ImportExport\Model\Import\Source\Factory::create()
310318
* @param string $sourceFile Full path to source file
@@ -576,7 +584,11 @@ public function uploadFileAndGetSource()
576584
{
577585
$sourceFile = $this->uploadSource();
578586
try {
579-
$source = $this->_getSourceAdapter($sourceFile);
587+
$source = $this->sourceFactory->create(
588+
$sourceFile,
589+
$this->_filesystem->getDirectoryWrite(DirectoryList::ROOT),
590+
$this->getData(self::FIELD_FIELD_SEPARATOR)
591+
);
580592
} catch (\Exception $e) {
581593
$this->_varDirectory->delete($this->_varDirectory->getRelativePath($sourceFile));
582594
throw new LocalizedException(__($e->getMessage()));

app/code/Magento/ImportExport/Model/Import/Source/Factory.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,17 @@ public function create($source, $directory = null, $options = null): AbstractSou
5959
__('\'%1\' file extension is not supported', $type)
6060
);
6161
}
62+
$data = [];
63+
$data['file'] = $source;
64+
$data['directory'] = $directory;
65+
if ($type === 'Csv') {
66+
$data['delimiter'] = $options;
67+
} else {
68+
$data['options'] = $options;
69+
}
6270
return $this->objectManager->create(
6371
$adapterClass,
64-
[
65-
'file' => $source,
66-
'directory' => $directory,
67-
'options' => $options
68-
]
72+
$data
6973
);
7074
}
7175
}

0 commit comments

Comments
 (0)