/** * {@inheritdoc} */ public function toOptionArray() { $options = array(); $options[] = array('label' => __('-- Please Select --'), 'value' => ''); foreach ($this->_importConfig->getEntities() as $entityName => $entityConfig) { $options[] = array('label' => __($entityConfig['label']), 'value' => $entityName); } return $options; }
/** * Cover isReportEntityType(). * * @dataProvider isReportEntityTypeExceptionDataProvider * @expectedException \Magento\Framework\Exception\LocalizedException */ public function testIsReportEntityTypeException($entity, $getEntitiesResult, $getEntityResult, $expectedResult) { $importMock = $this->getMockBuilder('\\Magento\\ImportExport\\Model\\Import')->disableOriginalConstructor()->setMethods(['getEntity', '_getEntityAdapter', 'getEntityTypeCode', 'isNeedToLogInHistory'])->getMock(); $importMock->expects($this->any())->method('_getEntityAdapter')->willReturnSelf(); $importMock->expects($this->any())->method('getEntityTypeCode')->willReturn('catalog_product'); $this->_importConfig->expects($this->any())->method('getEntities')->willReturn($getEntitiesResult); $this->_entityFactory->expects($this->any())->method('create')->willReturn(''); $this->setPropertyValue($importMock, '_importConfig', $this->_importConfig); $this->setPropertyValue($importMock, '_entityFactory', $this->_entityFactory); $importMock->expects($this->any())->method('getEntity')->willReturn($getEntityResult); $actualResult = $importMock->isReportEntityType($entity); $this->assertEquals($expectedResult, $actualResult); }
/** * Gets array of entities and appropriate behaviours * array( * <entity_code> => array( * 'token' => <behavior_class_name>, * 'code' => <behavior_model_code>, * ), * ... * ) * * @return array * @throws \Magento\Framework\Exception\LocalizedException */ public function getEntityBehaviors() { $behaviourData = []; $entities = $this->_importConfig->getEntities(); foreach ($entities as $entityCode => $entityData) { $behaviorClassName = isset($entityData['behaviorModel']) ? $entityData['behaviorModel'] : null; if ($behaviorClassName && class_exists($behaviorClassName)) { /** @var $behavior \Magento\ImportExport\Model\Source\Import\AbstractBehavior */ $behavior = $this->_behaviorFactory->create($behaviorClassName); $behaviourData[$entityCode] = ['token' => $behaviorClassName, 'code' => $behavior->getCode() . '_behavior']; } else { throw new \Magento\Framework\Exception\LocalizedException(__('The behavior token for %1 is invalid.', $entityCode)); } } return $behaviourData; }
/** * 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; }