/** * Create instance of entity adapter and return it * * @throws Mage_Core_Exception * @return Mage_ImportExport_Model_Import_Entity_Abstract|Mage_ImportExport_Model_Import_EntityAbstract */ protected function _getEntityAdapter() { if (!$this->_entityAdapter) { $entityTypes = Mage_ImportExport_Model_Config::getModels(self::CONFIG_KEY_ENTITIES); if (isset($entityTypes[$this->getEntity()])) { try { $this->_entityAdapter = Mage::getModel($entityTypes[$this->getEntity()]['model']); } catch (Exception $e) { Mage::logException($e); Mage::throwException(Mage::helper('Mage_ImportExport_Helper_Data')->__('Invalid entity model')); } if (!$this->_entityAdapter instanceof Mage_ImportExport_Model_Import_Entity_Abstract && !$this->_entityAdapter instanceof Mage_ImportExport_Model_Import_EntityAbstract) { Mage::throwException(Mage::helper('Mage_ImportExport_Helper_Data')->__('Entity adapter object must be an instance of %s or %s', 'Mage_ImportExport_Model_Import_Entity_Abstract', 'Mage_ImportExport_Model_Import_EntityAbstract')); } // check for entity codes integrity if ($this->getEntity() != $this->_entityAdapter->getEntityTypeCode()) { Mage::throwException(Mage::helper('Mage_ImportExport_Helper_Data')->__('Input entity code is not equal to entity adapter code')); } } else { Mage::throwException(Mage::helper('Mage_ImportExport_Helper_Data')->__('Invalid entity')); } $this->_entityAdapter->setParameters($this->getData()); } return $this->_entityAdapter; }
public function getNewWriteInstance($destinationFile, $fileFormat) { $validWriters = Mage_ImportExport_Model_Config::getModels(self::CONFIG_KEY_FORMATS); if (isset($validWriters[$fileFormat])) { try { if (file_exists($destinationFile)) { unlink($destinationFile); } $writer = Mage::getModel($validWriters[$fileFormat]['model'], $destinationFile); } catch (Exception $e) { Mage::logException($e); Mage::throwException(Mage::helper('importexport')->__('Invalid entity model')); } if (!$writer instanceof Mage_ImportExport_Model_Export_Adapter_Abstract) { Mage::throwException(Mage::helper('importexport')->__('Adapter object must be an instance of %s', 'Mage_ImportExport_Model_Export_Adapter_Abstract')); } } else { Mage::throwException(Mage::helper('importexport')->__('Invalid file format')); } return $writer; }
/** * Valdiates and sets the entity type. * * @param string $entityTypeCode * @return Danslo_ApiImport_Model_Resource_Import_Data */ public function setEntityTypeCode($entityTypeCode) { $allowedEntities = array_keys(Mage_ImportExport_Model_Config::getModels(Danslo_ApiImport_Model_Import::CONFIG_KEY_ENTITIES)); if (!in_array($entityTypeCode, $allowedEntities)) { Mage::throwException('Specified entity type (%s) is not in allowed entity types: %s', $entityTypeCode, implode(', ', $allowedEntities)); } $this->_entityTypeCode = $entityTypeCode; return $this; }
/** * Get writer object. * * @throws Mage_Core_Exception * @return Mage_ImportExport_Model_Export_Adapter_Abstract */ protected function _getWriter() { if (!$this->_writer) { $validWriters = Mage_ImportExport_Model_Config::getModels(self::CONFIG_KEY_FORMATS); if (isset($validWriters[$this->getFileFormat()])) { try { $this->_writer = Mage::getModel($validWriters[$this->getFileFormat()]['model']); } catch (Exception $e) { Mage::logException($e); Mage::throwException(Mage::helper('importexport')->__('Invalid entity model')); } if (!$this->_writer instanceof Mage_ImportExport_Model_Export_Adapter_Abstract) { Mage::throwException(Mage::helper('importexport')->__('Adapter object must be an instance of %s', 'Mage_ImportExport_Model_Export_Adapter_Abstract')); } } else { Mage::throwException(Mage::helper('importexport')->__('Invalid file format')); } } return $this->_writer; }
/** * Import products * * @param array $data * @param string|null $behavior * * @return AvS_FastSimpleImport_Model_Import */ public function dryrunCategoryImport($data, $behavior = NULL) { $transport = new Varien_Object(array('import_data' => $data)); Mage::dispatchEvent('fastsimpleimport_dryrun_categories_before', array('import_data' => $transport)); $data = $transport->getImportData(); if (!is_null($behavior)) { $this->setBehavior($behavior); } $this->setUseNestedArrays(false); $this->setEntity(Mage_Catalog_Model_Category::ENTITY); /** @var $entityAdapter AvS_FastSimpleImport_Model_Import_Entity_Category */ $validTypes = Mage_ImportExport_Model_Config::getModels(Mage_ImportExport_Model_Import::CONFIG_KEY_ENTITIES); $entityAdapter = Mage::getModel($validTypes[$this->getEntity()]['model']); $entityAdapter->setBehavior($this->getBehavior()); $entityAdapter->setErrorLimit($this->getErrorLimit()); $entityAdapter->setIgnoreDuplicates($this->getIgnoreDuplicates()); $entityAdapter->setUnsetEmptyFields($this->getUnsetEmptyFields()); $entityAdapter->setSymbolEmptyFields($this->getSymbolEmptyFields()); $entityAdapter->setSymbolIgnoreFields($this->getSymbolIgnoreFields()); $this->setEntityAdapter($entityAdapter); $validationResult = $this->validateSource($data); return $validationResult; }