/**
  * Create instance of entity adapter and returns it.
  *
  * @throws Exception
  * @return Mage_ImportExport_Model_Export_Entity_Abstract
  */
 protected function _getEntityAdapter()
 {
     if (!$this->_entityAdapter) {
         $validTypes = Mage_ImportExport_Model_Config::getModels(self::CONFIG_KEY_ENTITIES);
         if (isset($validTypes[$this->getEntity()])) {
             try {
                 $this->_entityAdapter = Mage::getModel($validTypes[$this->getEntity()]['model']);
             } catch (Exception $e) {
                 Mage::logException($e);
                 Mage::throwException(Mage::helper('importexport')->__('Invalid entity model'));
             }
             if (!$this->_entityAdapter instanceof Mage_ImportExport_Model_Export_Entity_Abstract) {
                 Mage::throwException(Mage::helper('importexport')->__('Entity adapter obejct must be an instance of Mage_ImportExport_Model_Export_Entity_Abstract'));
             }
         } else {
             Mage::throwException(Mage::helper('importexport')->__('Invalid entity'));
         }
         // check for entity codes integrity
         if ($this->getEntity() != $this->_entityAdapter->getEntityTypeCode()) {
             Mage::throwException(Mage::helper('importexport')->__('Input entity code is not equal to entity adapter code'));
         }
         $this->_entityAdapter->setParameters($this->getData());
     }
     return $this->_entityAdapter;
 }
Example #2
0
 /**
  * Get attributes codes which are appropriate for export.
  *
  * @return array
  */
 protected function _getExportAttrCodes()
 {
     if (null === self::$attrCodes) {
         if (!empty($this->_parameters[Mage_ImportExport_Model_Export::FILTER_ELEMENT_SKIP]) && is_array($this->_parameters[Mage_ImportExport_Model_Export::FILTER_ELEMENT_SKIP])) {
             $skipAttr = array_flip($this->_parameters[Mage_ImportExport_Model_Export::FILTER_ELEMENT_SKIP]);
         } else {
             $skipAttr = array();
         }
         $attrCodes = array();
         foreach ($this->filterAttributeCollection($this->getAttributeCollection()) as $attribute) {
             if (!isset($skipAttr[$attribute->getAttributeId()]) || in_array($attribute->getAttributeCode(), $this->_permanentAttributes)) {
                 $attrCodes[] = $attribute->getAttributeCode();
             }
         }
         self::$attrCodes = $attrCodes;
     }
     return self::$attrCodes;
 }
Example #3
0
 /**
  * Clean up already loaded attribute collection.
  *
  * @param Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection
  * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection
  */
 public function filterAttributeCollection(Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection)
 {
     $validTypes = array_keys($this->_productTypeModels);
     foreach (parent::filterAttributeCollection($collection) as $attribute) {
         $attrApplyTo = $attribute->getApplyTo();
         $attrApplyTo = $attrApplyTo ? array_intersect($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;
 }
Example #4
0
 /**
  * Clean up already loaded attribute collection.
  *
  * @param Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection
  * @return Mage_Eav_Model_Resource_Entity_Attribute_Collection
  */
 public function filterAttributeCollection(Mage_Eav_Model_Resource_Entity_Attribute_Collection $collection)
 {
     foreach (parent::filterAttributeCollection($collection) as $attribute) {
         if (!empty($this->_attributeOverrides[$attribute->getAttributeCode()])) {
             $data = $this->_attributeOverrides[$attribute->getAttributeCode()];
             if (isset($data['options_method']) && method_exists($this, $data['options_method'])) {
                 $data['filter_options'] = $this->{$data}['options_method']();
             }
             $attribute->addData($data);
         }
     }
     return $collection;
 }