Skip to content

Commit

Permalink
Updates. Version 1.0.3.
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolaevas committed Jan 7, 2017
1 parent 3379ce0 commit 1cd6233
Show file tree
Hide file tree
Showing 18 changed files with 1,087 additions and 132 deletions.
2 changes: 1 addition & 1 deletion Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function getSourceModelByType($sourceType)
return $source;
} else {
throw new \Magento\Framework\Exception\LocalizedException(
__("Import source type class for '%s' is not exist.", $sourceType)
__("Import source type class for '" . $sourceType . "' is not exist.")
);
}
}
Expand Down
94 changes: 94 additions & 0 deletions Model/Import/Product/Type/Downloadable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php
/**
* Copyright © 2016 Firebear Studio. All rights reserved.
*/
namespace Firebear\ImportExport\Model\Import\Product\Type;

/**
* Class Downloadable
*/
class Downloadable extends \Magento\DownloadableImportExport\Model\Import\Product\Type\Downloadable
{
/**
* Get fill data options with key link
*
* @param array $options
* @return array
*/
protected function fillDataTitleLink(array $options)
{
$result = [];
$select = $this->connection->select();
$select->from(
['dl' => $this->_resource->getTableName('downloadable_link')],
[
'link_id',
'product_id',
'sort_order',
'number_of_downloads',
'is_shareable',
'link_url',
'link_file',
'link_type',
'sample_url',
'sample_file',
'sample_type'
]
);
$select->joinLeft(
['dlp' => $this->_resource->getTableName('downloadable_link_price')],
'dl.link_id = dlp.link_id AND dlp.website_id=' . self::DEFAULT_WEBSITE_ID,
['price_id']
);
$select->where(
'product_id in (?)',
$this->productIds
);
$existingOptions = $this->connection->fetchAll($select);
foreach ($options as $option) {
$existOption = $this->downloadableHelper->fillExistOptions(
$this->dataLinkTitle,
$option,
$existingOptions
);
if (!empty($existOption)) {
$result['title'][] = $existOption;
}
$existOption = $this->downloadableHelper->fillExistOptions(
$this->dataLinkPrice,
$option,
$existingOptions
);
if (!empty($existOption)) {
$result['price'][] = $existOption;
}
}
return $result;
}

/**
* Uploading files into the "downloadable/files" media folder.
* Return a new file name if the same file is already exists.
*
* @param string $fileName
* @param string $type
* @param bool $renameFileOff
* @return string
*/
protected function uploadDownloadableFiles($fileName, $type = 'links', $renameFileOff = false)
{
try {
$res = $this->uploaderHelper->getUploader(
$type,
$this->_entityModel->getParameters()
)->move($fileName, $renameFileOff);
return $res['file'];
} catch (\Exception $e) {
$this->_entityModel->addRowError(
$this->_messageTemplates[self::ERROR_MOVE_FILE] . '. ' . $e->getMessage(),
$this->rowNum
);
return '';
}
}
}
15 changes: 15 additions & 0 deletions Model/Source/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@

namespace Firebear\ImportExport\Model\Source;

/**
* Class Config
* @package Firebear\ImportExport\Model\Source
*/
class Config extends \Magento\Framework\Config\Data implements \Firebear\ImportExport\Model\Source\ConfigInterface {

/**
* @param Config\Reader $reader
* @param \Magento\Framework\Config\CacheInterface $cache
* @param string $cacheId
*/
public function __construct(
\Firebear\ImportExport\Model\Source\Config\Reader $reader,
\Magento\Framework\Config\CacheInterface $cache,
Expand All @@ -16,6 +25,12 @@ public function __construct(
parent::__construct($reader, $cache, $cacheId);
}

/**
* Get system configuration of source type by name
*
* @param string $name
* @return array|mixed|null
*/
public function getType($name) {
return $this->get('type/' . $name);
}
Expand Down
7 changes: 4 additions & 3 deletions Model/Source/Config/Converter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ public function convert($source)
continue;
}

$result[$typeName]['fields'][$childNode->attributes->getNamedItem('name')->nodeValue] = array(
$result[$typeName]['fields'][$childNode->attributes->getNamedItem('name')->nodeValue] = [
'id' => $childNode->attributes->getNamedItem('id')->nodeValue,
'label' => $childNode->attributes->getNamedItem('label')->nodeValue,
'type' => $childNode->attributes->getNamedItem('type')->nodeValue,
'required' => ($childNode->attributes->getNamedItem('required')) ? $childNode->attributes->getNamedItem('required')->nodeValue : false,
);
'required' => ($childNode->attributes->getNamedItem('required'))
? $childNode->attributes->getNamedItem('required')->nodeValue : false,
];
}
}

Expand Down
102 changes: 97 additions & 5 deletions Model/Source/Type/AbstractType.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,154 @@

use Magento\Framework\App\Filesystem\DirectoryList;

/**
* Abstract class for import source types
* @package Firebear\ImportExport\Model\Source\Type
*/
abstract class AbstractType extends \Magento\Framework\DataObject {

const IMPORT_DIR = 'var/import';
/**
* Temp directory for downloaded files
*/
const IMPORT_DIR = 'import';

/**
* Temp directory for downloaded images
*/
const MEDIA_IMPORT_DIR = 'pub/media/import';

/**
* Source type code
* @var string
*/
protected $_code;

/**
* @var \Magento\Framework\App\Config\ScopeConfigInterface
*/
protected $_scopeConfig;

/**
* @var \Magento\Framework\Filesystem\Directory\WriteInterface
*/
protected $_directory;

protected $_client;

/**
* @var \Magento\Framework\Filesystem
*/
protected $_filesystem;

/**
* @var \Magento\Framework\Filesystem\File\ReadFactory
*/
protected $_readFactory;

/**
* @var array
*/
protected $_metadata = [];

protected $_client;

/**
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Framework\Filesystem $filesystem
* @param \Magento\Framework\Filesystem\File\ReadFactory $readFactory
*/
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\Filesystem $filesystem,
\Magento\Framework\Filesystem\File\ReadFactory $readFactory
){
) {
$this->_scopeConfig = $scopeConfig;
$this->_filesystem = $filesystem;
$this->_directory = $filesystem->getDirectoryWrite(DirectoryList::ROOT);
$this->_readFactory = $readFactory;
}

/**
* Prepare temp dir for import files
*
* @return string
*/
protected function getImportPath()
{
return self::IMPORT_DIR . '/' . $this->_code;
}

/**
* @return string
*/
protected function getImportVarPath()
{
return DirectoryList::VAR_DIR . '/' . $this->getImportPath();
}

/**
* Prepare temp dir for import images
*
* @return string
*/
protected function getMediaImportPath()
{
return self::MEDIA_IMPORT_DIR . '/' . $this->_code;
}

/**
* Get file path
*
* @return bool|string
*/
public function getImportFilePath() {
if($sourceType = $this->getImportSource()) {
if ($sourceType = $this->getImportSource()) {
$filePath = $this->getData($sourceType . '_file_path');
return $filePath;
}

return false;
}

/**
* Get source type code
*
* @return string
*/
public function getCode()
{
return $this->_code;
}

/**
* @return mixed
*/
public function getClient()
{
return $this->_client;
}

/**
* @param $client
*/
public function setClient($client)
{
$this->_client = $client;
}

/**
* @return mixed
*/
abstract function uploadSource();

/**
* @param $importImage
* @param $imageSting
*
* @return mixed
*/
abstract function importImage($importImage, $imageSting);

/**
* @return mixed
*/
abstract protected function _getSourceClient();
}
Loading

0 comments on commit 1cd6233

Please sign in to comment.