I am working on creating a custom extension for import export in magento2. For that I was going through magento2 import-export module. I found a function in file
/vendor/magento/module-import-export/Model/Import.php
protected function _getEntityAdapter()
{
if (!$this->_entityAdapter) {
$entities = $this->_importConfig->getEntities();
if (isset($entities[$this->getEntity()])) {
try {
$this->_entityAdapter = $this->_entityFactory->create($entities[$this->getEntity()]['model']);
} catch (Exception $e) {
$this->_logger->critical($e);
throw new LocalizedException(
__('Please enter a correct entity model.')
);
}
if (!$this->_entityAdapter instanceof AbstractEntity &&
!$this->_entityAdapter instanceof ImportAbstractEntity
) {
throw new LocalizedException(
__(
'The entity adapter object must be an instance of %1 or %2.',
AbstractEntity::class,
ImportAbstractEntity::class
)
);
}
// check for entity codes integrity
if ($this->getEntity() != $this->_entityAdapter->getEntityTypeCode()) {
throw new LocalizedException(
__('The input entity code is not equal to entity adapter code.')
);
}
} else {
throw new LocalizedException(__('Please enter a correct entity.'));
}
$this->_entityAdapter->setParameters($this->getData());
}
return $this->_entityAdapter;
}
In the second line of the function ie
$entities = $this->_importConfig->getEntities();
By reading it I understood getEntities function() is fetching entities that are meant to be imported like products, customers.
I want to know where these values like products and customers are created so that magento treats them as importable or exportable entities.
To find out this I tried to locate _importConfig in the above line.
It was passed in construct like
use MagentoImportExportModelImportConfigInterface;
public function __construct(
LoggerInterface $logger,
Filesystem $filesystem,
DataHelper $importExportData,
ScopeConfigInterface $coreConfig,
ConfigInterface $importConfig,
Factory $entityFactory,
Data $importData,
CsvFactory $csvFactory,
FileTransferFactory $httpFactory,
UploaderFactory $uploaderFactory,
BehaviorFactory $behaviorFactory,
IndexerRegistry $indexerRegistry,
History $importHistoryModel,
DateTime $localeDate,
array $data = [],
ManagerInterface $messageManager = null,
Random $random = null
) {
$this->_importExportData = $importExportData;
$this->_coreConfig = $coreConfig;
$this->_importConfig = $importConfig;
$this->_entityFactory = $entityFactory;
$this->_importData = $importData;
$this->_csvFactory = $csvFactory;
$this->_httpFactory = $httpFactory;
$this->_uploaderFactory = $uploaderFactory;
$this->indexerRegistry = $indexerRegistry;
$this->_behaviorFactory = $behaviorFactory;
$this->_filesystem = $filesystem;
$this->importHistoryModel = $importHistoryModel;
$this->localeDate = $localeDate;
$this->messageManager = $messageManager ?: ObjectManager::getInstance()
->get(ManagerInterface::class);
$this->random = $random ?: ObjectManager::getInstance()
->get(Random::class);
parent::__construct($logger, $filesystem, $data);
}
Now in the file
/vendor/magento/module-import-export/Model/Import/ConfigInterface.php
I found the function
/**
* Retrieve import entities configuration
*
* @return array
*/
public function getEntities();
But this function was empty, it may be because of interface. I need to read more to understand about interface what it actually does. But for now I found where this interface was used and in this file I think it might be
/vendor/magento/module-import-export/Model/Import/Config.php
class Config extends MagentoFrameworkConfigData implements MagentoImportExportModelImportConfigInterface
{
public function getEntities()
{
return $this->get('entities');
}
}
Here also I could not locate where entities are defined. I looked for get function in the above class parent class
/vendor/magento/framework/Config/Data.php
/**
* Get config value by key
*
* @param string $path
* @param mixed $default
* @return array|mixed|null
*/
public function get($path = null, $default = null)
{
if ($path === null) {
return $this->_data;
}
$keys = explode('/', $path);
$data = $this->_data;
foreach ($keys as $key) {
if (is_array($data) && array_key_exists($key, $data)) {
$data = $data[$key];
} else {
return $default;
}
}
return $data;
}
In this get function comments it was written get config value by key. By that I understood these config values are defined somewhere and entities is the key.
I am having problem in finding how and where these entities are defined and how I can make a custom entity to import.