/** * Create instance of entity adapter and return it * * @throws \Magento\Framework\Exception\LocalizedException * @return \Magento\ImportExport\Model\Import\Entity\AbstractEntity|\Magento\ImportExport\Model\Import\AbstractEntity */ 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 \Magento\Framework\Exception\LocalizedException(__('Please enter a correct entity model.')); } if (!$this->_entityAdapter instanceof \Magento\ImportExport\Model\Import\Entity\AbstractEntity && !$this->_entityAdapter instanceof \Magento\ImportExport\Model\Import\AbstractEntity) { throw new \Magento\Framework\Exception\LocalizedException(__('The entity adapter object must be an instance of %1 or %2.', 'Magento\\ImportExport\\Model\\Import\\Entity\\AbstractEntity', 'Magento\\ImportExport\\Model\\Import\\AbstractEntity')); } // check for entity codes integrity if ($this->getEntity() != $this->_entityAdapter->getEntityTypeCode()) { throw new \Magento\Framework\Exception\LocalizedException(__('The input entity code is not equal to entity adapter code.')); } } else { throw new \Magento\Framework\Exception\LocalizedException(__('Please enter a correct entity.')); } $this->_entityAdapter->setParameters($this->getData()); } return $this->_entityAdapter; }
/** * Retrieve processed reports entity types * * @param string|null $entity * @return bool * @throws \Magento\Framework\Exception\LocalizedException */ public function isReportEntityType($entity = null) { $result = false; if ($entity !== null && $this->_getEntityAdapter()->getEntityTypeCode() != $entity) { $entities = $this->_importConfig->getEntities(); if (isset($entities[$this->getEntity()])) { try { $adapter = $this->_entityFactory->create($entities[$entity]['model']); $result = $adapter->isNeedToLogInHistory(); } catch (\Exception $e) { throw new \Magento\Framework\Exception\LocalizedException(__('Please enter a correct entity model')); } } else { throw new \Magento\Framework\Exception\LocalizedException(__('Please enter a correct entity model')); } } else { $result = $this->_getEntityAdapter()->isNeedToLogInHistory(); } return $result; }