00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 class Mage_Dataflow_Model_Convert_Mapper_Column extends Mage_Dataflow_Model_Convert_Mapper_Abstract
00036 {
00037
00038
00039
00040
00041
00042 protected $_batch;
00043
00044
00045
00046
00047
00048
00049 protected $_batchExport;
00050
00051
00052
00053
00054
00055
00056 protected $_batchImport;
00057
00058
00059
00060
00061
00062
00063 public function getBatchModel()
00064 {
00065 if (is_null($this->_batch)) {
00066 $this->_batch = Mage::getSingleton('dataflow/batch');
00067 }
00068 return $this->_batch;
00069 }
00070
00071
00072
00073
00074
00075
00076 public function getBatchExportModel()
00077 {
00078 if (is_null($this->_batchExport)) {
00079 $object = Mage::getModel('dataflow/batch_export');
00080 $this->_batchExport = Varien_Object_Cache::singleton()->save($object);
00081 }
00082 return Varien_Object_Cache::singleton()->load($this->_batchExport);
00083 }
00084
00085
00086
00087
00088
00089
00090 public function getBatchImportModel()
00091 {
00092 if (is_null($this->_batchImport)) {
00093 $object = Mage::getModel('dataflow/batch_import');
00094 $this->_batchImport = Varien_Object_Cache::singleton()->save($object);
00095 }
00096 return Varien_Object_Cache::singleton()->load($this->_batchImport);
00097 }
00098
00099 public function map()
00100 {
00101 $batchModel = $this->getBatchModel();
00102 $batchExport = $this->getBatchExportModel();
00103
00104 $batchExportIds = $batchExport
00105 ->setBatchId($this->getBatchModel()->getId())
00106 ->getIdCollection();
00107
00108 $onlySpecified = (bool)$this->getVar('_only_specified') === true;
00109
00110 if (!$onlySpecified) {
00111 foreach ($batchExportIds as $batchExportId) {
00112 $batchExport->load($batchExportId);
00113 $batchModel->parseFieldList($batchExport->getBatchData());
00114 }
00115
00116 return $this;
00117 }
00118
00119 if ($this->getVar('map') && is_array($this->getVar('map'))) {
00120 $attributesToSelect = $this->getVar('map');
00121 }
00122 else {
00123 $attributesToSelect = array();
00124 }
00125
00126 if (!$attributesToSelect) {
00127 $this->getBatchExportModel()
00128 ->setBatchId($this->getBatchModel()->getId())
00129 ->deleteCollection();
00130
00131 throw new Exception(Mage::helper('dataflow')->__('Error field mapping! Fields list for mapping is not defined'));
00132 }
00133
00134 foreach ($batchExportIds as $batchExportId) {
00135 $batchExport = $this->getBatchExportModel()->load($batchExportId);
00136 $row = $batchExport->getBatchData();
00137
00138 $newRow = array();
00139 foreach ($attributesToSelect as $field => $mapField) {
00140 $newRow[$mapField] = isset($row[$field]) ? $row[$field] : null;
00141 }
00142
00143 $batchExport->setBatchData($newRow)
00144 ->setStatus(2)
00145 ->save();
00146 $this->getBatchModel()->parseFieldList($batchExport->getBatchData());
00147 }
00148
00149 return $this;
00150 }
00151 }