Public Member Functions | |
getEntity () | |
load () | |
save () | |
Protected Attributes | |
$_entity |
Definition at line 28 of file Grid.php.
getEntity | ( | ) |
Definition at line 33 of file Grid.php.
00034 { 00035 if (!$this->_entityType) { 00036 if (!($entityType = $this->getVar('entity_type')) 00037 || !(($entity = Mage::getResourceSingleton($entityType)) instanceof Mage_Eav_Model_Entity_Interface)) { 00038 $this->addException(Mage::helper('eav')->__('Invalid entity specified'), Varien_Convert_Exception::FATAL); 00039 } 00040 $this->_entity = $entity; 00041 } 00042 return $this->_entity; 00043 }
load | ( | ) |
Implements Mage_Dataflow_Model_Convert_Adapter_Interface.
Definition at line 45 of file Grid.php.
00046 { 00047 try { 00048 $collection = Mage::getResourceModel($this->getEntity().'_collection'); 00049 $collection->load(); 00050 } catch (Exception $e) { 00051 $this->addException(Mage::helper('eav')->__('Problem loading the collection, aborting. Error: %s', $e->getMessage()), Varien_Convert_Exception::FATAL); 00052 } 00053 00054 $data = array(); 00055 foreach ($collection->getIterator() as $entity) { 00056 $data[] = $entity->getData(); 00057 } 00058 $this->setData($data); 00059 return $this; 00060 }
save | ( | ) |
Implements Mage_Dataflow_Model_Convert_Adapter_Interface.
Definition at line 62 of file Grid.php.
00063 { 00064 foreach ($this->getData() as $i=>$row) { 00065 $this->setExceptionLocation('Line: '.$i); 00066 $entity = Mage::getResourceModel($this->getEntity()); 00067 if (!empty($row['entity_id'])) { 00068 try { 00069 $entity->load($row['entity_id']); 00070 $this->setPosition('Line: '.$i.(isset($row['entity_id']) ? ', entity_id: '.$row['entity_id'] : '')); 00071 } catch (Exception $e) { 00072 $this->addException(Mage::helper('eav')->__('Problem loading a record, aborting. Error: %s', $e->getMessage()), Varien_Convert_Exception::FATAL); 00073 } 00074 if (!$entity->getId()) { 00075 $this->addException(Mage::helper('eav')->__('Invalid entity_id, skipping the record'), Varien_Convert_Exception::ERROR); 00076 continue; 00077 } 00078 } 00079 try { 00080 $entity->addData($row)->save(); 00081 } catch (Exception $e) { 00082 $this->addException(Mage::helper('eav')->__('Problem saving a record, aborting. Error: ', $e->getMessage()), Varien_Convert_Exception::FATAL); 00083 } 00084 } 00085 return $this; 00086 }