/** * Create instance of entity adapter and return it * * @return \Magento\ImportExport\Model\Export\Entity\AbstractEntity|\Magento\ImportExport\Model\Export\AbstractEntity * @throws \Magento\Framework\Exception\LocalizedException */ protected function _getEntityAdapter() { if (!$this->_entityAdapter) { $entities = $this->_exportConfig->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\Export\Entity\AbstractEntity && !$this->_entityAdapter instanceof \Magento\ImportExport\Model\Export\AbstractEntity) { throw new \Magento\Framework\Exception\LocalizedException(__('Entity adapter object must be an instance of %1 or %2', 'Magento\\ImportExport\\Model\\Export\\Entity\\AbstractEntity', 'Magento\\ImportExport\\Model\\Export\\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; }
/** * Clean up already loaded attribute collection. * * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $collection * @return \Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection */ public function filterAttributeCollection(\Magento\Eav\Model\ResourceModel\Entity\Attribute\Collection $collection) { $validTypes = array_keys($this->_productTypeModels); $validTypes = array_combine($validTypes, $validTypes); foreach (parent::filterAttributeCollection($collection) as $attribute) { if (in_array($attribute->getAttributeCode(), $this->_bannedAttributes)) { $collection->removeItemByKey($attribute->getId()); continue; } $attrApplyTo = $attribute->getApplyTo(); $attrApplyTo = array_combine($attrApplyTo, $attrApplyTo); $attrApplyTo = $attrApplyTo ? array_intersect_key($attrApplyTo, $validTypes) : $validTypes; if ($attrApplyTo) { foreach ($attrApplyTo as $productType) { // override attributes by its product type model if ($this->_productTypeModels[$productType]->overrideAttribute($attribute)) { break; } } } else { // remove attributes of not-supported product types $collection->removeItemByKey($attribute->getId()); } } return $collection; }