Skip to content

Commit

Permalink
Get the file directory from the configuration if it's set.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulpartington-cti committed Apr 27, 2017
1 parent 5c6d7e2 commit a1ba8f2
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions Model/Component/Products.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,26 @@ class Products extends CsvComponentAbstract
*/
protected $httpClientFactory;

/**
* @var \FireGento\FastSimpleImport\Helper\Config
*/
protected $importerConfig;

public function __construct(
LoggingInterface $log,
ObjectManagerInterface $objectManager,
ImporterFactory $importerFactory,
ProductFactory $productFactory,
\Magento\Framework\HTTP\ZendClientFactory $httpClientFactory,
Filesystem $filesystem
Filesystem $filesystem,
\FireGento\FastSimpleImport\Helper\Config $importerConfig
) {
parent::__construct($log, $objectManager);
$this->productFactory= $productFactory;
$this->importerFactory = $importerFactory;
$this->httpClientFactory = $httpClientFactory;
$this->filesystem = $filesystem;
$this->importerConfig = $importerConfig;
}

protected function processData($data = null)
Expand Down Expand Up @@ -271,11 +278,9 @@ public function saveFile($fileName, $value)
{
$name = pathinfo($fileName, PATHINFO_FILENAME);
$ext = pathinfo($fileName, PATHINFO_EXTENSION);
/**
* @var Filesystem $file
*/

$writeDirectory = $this->filesystem->getDirectoryWrite(DirectoryList::MEDIA);
$importDirectory = $writeDirectory->getRelativePath('import');
$importDirectory = $this->getFileDirectory($writeDirectory);
$counter = 0;
do {
$file = $name . '_' . $counter . '.' . $ext;
Expand Down Expand Up @@ -310,4 +315,19 @@ public function getImage($value)
}
return $value;
}

/**
* Get the file directory from the configuration if set
*
* @param Filesystem\Directory\WriteInterface $file
* @return string
*/
public function getFileDirectory(\Magento\Framework\Filesystem\Directory\WriteInterface $file)
{
$configurationValue = $this->importerConfig->getImportFileDir();
if (!empty($configurationValue)) {
return $file->getRelativePath($configurationValue);
}
return $file->getRelativePath('import');
}
}

0 comments on commit a1ba8f2

Please sign in to comment.