00001 <?php
00002
00003
00004 $aNonDemoModules = array();
00005
00006 require_once( 'oxerpbase.php');
00007
00012 class oxErpCsv extends oxERPBase {
00013
00014 public static $EXCEPTION_FILE_EXIST = "File does allready exist!";
00015 public static $EXCEPTION_FAIL_CREATE_FILE = "Unable to create file!";
00016 public static $EXCEPTION_FAIL_WRITE_FILE = "Failed writing data to file!";
00017
00018 public static $ERROR_DURING_IMPORT = "ERROR during import";
00019 public static $ERROR_WRONG_VERSION = "ERROR: File Version mismatch or no Version information!";
00020 public static $ERROR_WRONG_FILE = "ERROR: no file";
00021 public static $IMPORT_DONE = "IMPORT DONE";
00022
00023 protected $_aSupportedVersions = array("0.1", "1.0", "1.1", "2.0");
00024 protected $_aCsv2BaseVersionsMap = array("0.1" => "1", "1.0" => "1", "1.1"=>"1.1", "2.0" => "2");
00025
00026 protected $_sErpVersion = "1.0";
00027
00028
00029 protected $_sCurrVersion = "";
00030
00031 protected $_currFileId = "";
00032
00033 protected $_sCurrImportType;
00034 protected $_blVersionSkip = false;
00035
00036 protected $_aObjects = array (
00037 'A' => 'article',
00038 'L' => 'article',
00039 'K' => 'category',
00040 'H' => 'vendor',
00041 'C' => 'crossselling',
00042 'Z' => 'accessoire',
00043 'T' => 'article2category',
00044 'I' => 'article2action',
00045 'S' => 'orderstatus',
00046 'P' => 'scaleprice',
00047 'U' => 'user',
00048 'O' => 'order',
00049 'R' => 'orderarticle',
00050 'E' => 'articlestock',
00051 'N' => 'country',
00052 'D' => 'article2vendor',
00053 'M' => 'mainarticle2categroy',
00054 'Y' => 'artextends',
00055 );
00056
00057
00058 protected $_aNewCommands = array(
00059
00060 );
00061
00062 protected $_aData = array();
00063
00064 protected $_iRetryRows = 0;
00065
00066 protected $_sReturn;
00067
00068 protected $_sPath;
00069
00070
00071 protected $_sBuffer;
00072
00073 protected $_iBufferRecCounter = 0;
00074
00075 var $_aImportedActions2Article = array();
00076 var $_aImportedObject2Category = array();
00077 var $_aImportedAccessoire2Article = array();
00078
00079 public function setFileId($sId)
00080 {
00081 $this->_currFileId = $sId;
00082 }
00083
00089 public function loadSessionData( $sSessionID )
00090 {
00091 $_COOKIE = array('admin_sid' => $sSessionID);
00092
00093 $myConfig = oxConfig::getInstance();
00094 $myConfig->setConfigParam( 'blAdmin', 1 );
00095 $myConfig->setAdminMode( true );
00096 $mySession = oxSession::getInstance();
00097
00098
00099 if ($sSessionID != session_id()) {
00100 if (session_id()) {
00101 session_write_close();
00102 }
00103 session_id($sSessionID);
00104 session_start();
00105 }
00106
00107 $aSessionData = $_SESSION;
00108
00109 if(!isset($aSessionData['auth']) || !$aSessionData['auth']) {
00110 throw new Exception( "ERROR: Session ID not valid!");
00111 }
00112
00113 $this->_iLanguage = $aSessionData['lang'];
00114
00115 $this->_sUserID = $aSessionData['auth'];
00116
00117 oxConfig::getInstance()->setShopId($aSessionData['actshop']);
00118
00119 $this->_blInit = true;
00120
00121
00122
00123
00124
00125
00126 }
00127
00136 public function ERPWriteOrderFile( $oOrder)
00137 {
00138 $mySession = oxSession::getInstance();
00139
00140
00141 try{
00142 $this->loadSessionData($mySession->getId());
00143 }catch(Exception $ex){
00144 return false;
00145 }
00146 $this->checkVersion();
00147 return $this->_exportFullOrder($oOrder);
00148 }
00149
00158 public function DoImport($sPath = null, $sUserName = null, $sUserPassword = null, $sShopId = null, $sShopLanguage = null )
00159 {
00160
00161
00162
00163 $myConfig = oxConfig::getInstance();
00164 $mySession = oxSession::getInstance();
00165
00166 $this->_sReturn = "";
00167 $iMaxLineLength = 8192;
00168 $blVersionLine = false;
00169
00170 if(!$sPath){
00171 $myConfig = oxConfig::getInstance();
00172 $this->_sPath = $myConfig->aERPInfo['sPath'];
00173 } else {
00174 $this->_sPath = $sPath;
00175 }
00176
00177 try{
00178 if (!$sUserName || !$sUserPassword) {
00179
00180 $this->loadSessionData($mySession->getId());
00181 } else {
00182
00183 $this->init($sUserName, $sUserPassword, $sShopId, $sShopLanguage);
00184 }
00185 }catch(Exception $ex){
00186 return self::$ERROR_USER_NO_RIGHTS;
00187 }
00188
00189
00190 $file = @fopen($this->_sPath,"r");
00191
00192 if(isset($file) && $file){
00193 $iRow = 0;
00194 $aRow = array();
00195 while ( ($aRow = fgetcsv( $file, $iMaxLineLength, ";",'"')) !== FALSE) {
00196
00197 if($aRow[0] == "V" && $this->_checkAndSetVersion($aRow[1])){
00198 $blVersionLine = true;
00199 } elseif($blVersionLine) {
00200 $this->_aData[] = $aRow;
00201 } else {
00202
00203 fclose($file);
00204 return self::$ERROR_WRONG_VERSION;
00205 }
00206 }
00207 try {
00208 $this->Import();
00209 } catch (Exception $ex) {
00210 $this->_sReturn .= self::$ERROR_DURING_IMPORT.PHP_EOL;
00211 }
00212
00213 }else {
00214 return self::$ERROR_WRONG_FILE;
00215 }
00216 fclose($file);
00217
00218 if(strlen($this->_sReturn)==0){
00219 $this->_sReturn .= self::$IMPORT_DONE;
00220 }
00221 return $this->_sReturn;
00222 }
00223
00231 protected function _checkAndSetVersion($sVersion)
00232 {
00233
00234 if (!in_array($sVersion, $this->_aSupportedVersions)) {
00235 return false;
00236 }
00237
00238 $this->_sCurrVersion = $sVersion;
00239
00240 if (oxERPBase::getUsedDbFieldsVersion() != $this->_aCsv2BaseVersionsMap[$sVersion]) {
00241 oxERPBase::setVersion($this->_aCsv2BaseVersionsMap[$sVersion]);
00242 }
00243
00244 return true;
00245 }
00246
00255 protected function _csvTextConvert($sText, $blMode)
00256 {
00257 $aSearch = array(chr(13), chr(10), '\'', '"');
00258 $aReplace = array(' ', ' ', ''', '"');
00259
00260 if( $blMode)
00261 $sText = str_replace( $aSearch, $aReplace ,$sText);
00262 else
00263 $sText = str_replace( $aReplace, $aSearch ,$sText);
00264
00265 return $sText;
00266 }
00267
00268 protected function checkVersion()
00269 {
00270 if (oxERPBase::getUsedDbFieldsVersion() != $this->_aCsv2BaseVersionsMap[$this->_sErpVersion]) {
00271
00272 $aArr = array_flip($this->_aCsv2BaseVersionsMap);
00273 $this->_sErpVersion = $aArr[oxERPBase::getUsedDbFieldsVersion()];
00274 }
00275 }
00276
00277 protected function _beforeExport($sType)
00278 {
00279 $this->checkVersion();
00280 if ((oxERPBase::getUsedDbFieldsVersion() == '1') && ($sType == 'oldOrder' || $sType == 'oldOrderArticle')) {
00281
00282 return ;
00283 }
00284 if (!$this->_blVersionSkip) {
00285 $this->_addVersionTag();
00286 }
00287 }
00288 protected function _afterExport($sType)
00289 {
00290 }
00291
00292 public function Import()
00293 {
00294 $this->_beforeImport();
00295
00296 do{
00297 while( $this->_importOne());
00298 }
00299 while ( !$this->_afterImport() );
00300
00301 }
00302
00303 protected function _beforeImport()
00304 {
00305 if(!$this->_iRetryRows){
00306
00307 foreach ($this->_aData as $key => $value) {
00308 $this->_aData[$key] = $this->_csvTextConvert($value, false);
00309 }
00310 }
00311
00312 }
00313 protected function _afterImport()
00314 {
00315
00316 $aStatistics = $this->getStatistics();
00317 $iRetryRows = 0;
00318
00319 foreach ($aStatistics as $key => $value) {
00320 if($value['r'] == false){
00321 $iRetryRows ++;
00322 $this->_sReturn.= "File[".$this->_sPath."] - dataset number: $key - Error: ".$value['m']." ---<br> ".PHP_EOL;
00323 }
00324 }
00325
00326 if($iRetryRows != $this->_iRetryRows && $iRetryRows>0){
00327 $this->_resetIdx();
00328 $this->_iRetryRows = $iRetryRows;
00329 $this->_sReturn = '';
00330
00331 return false;
00332 }
00333
00334 return true;
00335 }
00336 public function getImportData()
00337 {
00338 return $this->_aData[$this->_iIdx];
00339 }
00340
00341 protected function _modifyData($aData, $oType)
00342 {
00343
00344 if ($this->_getImportMode($aData) == oxERPBase::$MODE_DELETE) {
00345 return $aData[1];
00346 }
00347
00348
00349 if($this->_sCurrVersion == "0.1") {
00350 if ($oType->getFunctionSuffix() == "Article") {
00351
00352 array_splice($aData, 104, 2,array());
00353
00354 }
00355
00356 if ($oType->getFunctionSuffix() == "Category") {
00357
00358 array_splice($aData, 19, 2,array());
00359 }
00360
00361 }
00362
00363 array_shift ($aData);
00364 return $this->_mapFields($aData, $oType);
00365 }
00366
00367 protected function _getImportType(& $aData)
00368 {
00369 $sType = $aData[0];
00370 if (strpos($sType, "X")===0)
00371 {
00372 $sType = substr($sType, 1);
00373 }
00374
00375
00376 if ($sType == "L" && $this->_sCurrVersion == "0.1") {
00377 $aData[0] = "XA";
00378 }
00379
00380 if(strlen($sType) != 1 || !array_key_exists($sType, $this->_aObjects)){
00381 throw new Exception("Error unknown command: ".$sType);
00382 } else {
00383 return $this->_aObjects[$sType];
00384 }
00385 }
00386
00387 protected function _getImportMode($aData)
00388 {
00389 if (strpos($aData[0], "X")===0)
00390 {
00391 return oxERPBase::$MODE_DELETE;
00392 } else {
00393 return oxERPBase::$MODE_IMPORT;
00394 }
00395 }
00396
00404 protected function _exportFullOrder($oOrder)
00405 {
00406 $myConfig = oxConfig::getInstance();
00407 $this->_blVersionSkip = true;
00408 $sWhere = "where oxid = '" . $oOrder->getId() . "'";
00409 if (oxERPBase::getUsedDbFieldsVersion() == '1') {
00410 $old = $this->_sErpVersion;
00411 $this->_sErpVersion = "0.1";
00412 $this->_addVersionTag();
00413 $this->exportType('oldOrder', $sWhere);
00414 $this->_sErpVersion = $old;
00415 } else {
00416 $this->_addVersionTag();
00417 $this->exportType('order', $sWhere);
00418 }
00419
00420
00421
00422 if ($this->_iBufferRecCounter > 1) {
00423
00424
00425
00426 $aAddFields = array();
00427 $aAddFields[] = $this->_csvTextConvert(oxDb::getDb()->GetOne("select oxisoalpha3 from oxcountry where oxid = '".$oOrder->oUser->oxuser__oxcountryid->value."'"), true);
00428
00429 $aAddFields[] = $this->_csvTextConvert(oxDb::getDb()->GetOne("select oxdesc from oxpayments where oxid = '".$oOrder->oxorder__oxpaymenttype->value."'"), true);
00430
00431
00432 $oPayment = oxNew( "oxuserpayment", "core");
00433 $oPayment->Load( $oOrder->oxorder__oxpaymentid->value);
00434 if( isset( $oPayment->oxuserpayments__oxvalue->value) && $oPayment->oxuserpayments__oxvalue->value)
00435 { $oPayMethod = oxNew( "oxpayment", "core");
00436 $oPayMethod->Load( $oPayment->oxuserpayments__oxpaymentsid->value);
00437 $oOrder->aDynValues = AssignValuesFromText( $oPayment->oxuserpayments__oxvalue->value);
00438
00439
00440 $sUserPayment = "";
00441 $blSep = false;
00442 foreach( $oOrder->aDynValues as $oEntry)
00443 { if( $blSep)
00444 $sUserPayment .= "|";
00445 $sUserPayment .= $oEntry->value;
00446 $blSep = true;
00447 }
00448 $aAddFields[] = $this->_csvTextConvert($sUserPayment, true);
00449 }else{
00450 $aAddFields[] = "";
00451 }
00452
00453 $this->_appendDsToBuffer($aAddFields);
00454 }
00455
00456
00457 $sWhere = "where oxorderid = '" . $oOrder->getId() . "'";
00458
00459 if (oxERPBase::getUsedDbFieldsVersion() == '1') {
00460 $this->exportType('oldOrderArticle', $sWhere);
00461 } else {
00462 $this->exportType('orderarticle', $sWhere);
00463 }
00464
00465 $this->_blVersionSkip = false;
00466 try{
00467 $file = $this->_createFile("", $oOrder->oxorder__oxordernr->value, $myConfig->aERPInfo['sExpPath']);
00468 $this->_flushBuffer($file);
00469 }catch(Exception $ex){
00470 return false;
00471 }
00472
00473 return true;
00474 }
00475
00481 private function getOldOrderArticleFieldList()
00482 {
00483 $aFieldList = array(
00484 'OXID' => 'OXID',
00485 'OXORDERID' => 'OXORDERID',
00486 'OXAMOUNT' => 'OXAMOUNT',
00487 'OXARTID' => 'OXARTID',
00488 'OXARTNUM' => 'OXARTNUM',
00489 'OXTITLE' => 'OXTITLE',
00490 'OXSELVARIANT' => 'OXSELVARIANT',
00491 'OXNETPRICE' => 'OXNETPRICE',
00492 'OXBRUTPRICE' => 'OXBRUTPRICE',
00493 'OXVAT' => 'OXVAT',
00494 'OXPERSPARAM' => 'OXPERSPARAM',
00495 'OXPRICE' => 'OXPRICE',
00496 'OXBPRICE' => 'OXBPRICE',
00497 'OXTPRICE' => 'OXTPRICE',
00498 'OXWRAPID' => 'OXWRAPID',
00499 'OXSTOCK' => 'OXSTOCK',
00500 'OXORDERSHOPID' => 'OXORDERSHOPID',
00501 'OXTOTALVAT' => 'OXTOTALVAT'
00502 );
00503
00504 return $aFieldList;
00505 }
00506
00512 private function getOldOrderFielsList()
00513 {
00514 $aFieldList = array(
00515 'OXID' => 'OXID',
00516 'OXSHOPID' => 'OXSHOPID',
00517 'OXUSERID' => 'OXUSERID',
00518 'OXORDERDATE' => 'OXORDERDATE',
00519 'OXORDERNR' => 'OXORDERNR',
00520 'OXBILLCOMPANY' => 'OXBILLCOMPANY',
00521 'OXBILLEMAIL' => 'OXBILLEMAIL',
00522 'OXBILLFNAME' => 'OXBILLFNAME',
00523 'OXBILLLNAME' => 'OXBILLLNAME',
00524 'OXBILLSTREET' => 'OXBILLSTREET',
00525 'OXBILLSTREETNR' => 'OXBILLSTREETNR',
00526 'OXBILLADDINFO' => 'OXBILLADDINFO',
00527 'OXBILLUSTID' => 'OXBILLUSTID',
00528 'OXBILLCITY' => 'OXBILLCITY',
00529 'OXBILLCOUNTRY' => 'OXBILLCOUNTRY',
00530 'OXBILLZIP' => 'OXBILLZIP',
00531 'OXBILLFON' => 'OXBILLFON',
00532 'OXBILLFAX' => 'OXBILLFAX',
00533 'OXBILLSAL' => 'OXBILLSAL',
00534 'OXDELCOMPANY' => 'OXDELCOMPANY',
00535 'OXDELFNAME' => 'OXDELFNAME',
00536 'OXDELLNAME' => 'OXDELLNAME',
00537 'OXDELSTREET' => 'OXDELSTREET',
00538 'OXDELSTREETNR' => 'OXDELSTREETNR',
00539 'OXDELADDINFO' => 'OXDELADDINFO',
00540 'OXDELCITY' => 'OXDELCITY',
00541 'OXDELCOUNTRY' => 'OXDELCOUNTRY',
00542 'OXDELZIP' => 'OXDELZIP',
00543 'OXDELFON' => 'OXDELFON',
00544 'OXDELFAX' => 'OXDELFAX',
00545 'OXDELSAL' => 'OXDELSAL',
00546 'OXDELCOST' => 'OXDELCOST',
00547 'OXDELVAT' => 'OXDELVAT',
00548 'OXPAYCOST' => 'OXPAYCOST',
00549 'OXPAYVAT' => 'OXPAYVAT',
00550 'OXWRAPCOST' => 'OXWRAPCOST',
00551 'OXWRAPVAT' => 'OXWRAPVAT',
00552 'OXCARDID' => 'OXCARDID',
00553 'OXCARDTEXT' => 'OXCARDTEXT',
00554 'OXDISCOUNT' => 'OXDISCOUNT',
00555 'OXBILLNR' => 'OXBILLNR',
00556 'OXREMARK' => 'OXREMARK',
00557 'OXVOUCHERDISCOUNT' => 'OXVOUCHERDISCOUNT',
00558 'OXCURRENCY' => 'OXCURRENCY',
00559 'OXCURRATE' => 'OXCURRATE',
00560 'OXTRANSID' => 'OXTRANSID',
00561 'OXPAID' => 'OXPAID',
00562 'OXIP' => 'OXIP',
00563 'OXTRANSSTATUS' => 'OXTRANSSTATUS',
00564 'OXLANG' => 'OXLANG',
00565 'OXDELTYPE' => 'OXDELTYPE'
00566 );
00567
00568 return $aFieldList;
00569 }
00570
00584 protected function _createFile($sType, $sId, $sPath = null)
00585 {
00586 $myConfig = oxConfig::getInstance();
00587 if(strlen($sType)>0){
00588 $sType .= "_";
00589 }
00590 $sFileName = $sType.$sId.".txt";
00591 if(!$sPath){
00592 $sPath = $myConfig->aERPInfo['sExpPath'].$myConfig->getShopId();
00593 }
00594 $sFullPath = $sPath . DIRECTORY_SEPARATOR . $sFileName;
00595 if(file_exists($sFullPath)){
00596 throw new Exception(self::$EXCEPTION_FILE_EXIST, 0);
00597 }else{
00598 $file = @fopen( $sFullPath , "w");
00599 if($file){
00600 return $file;
00601 }else{
00602 throw new Exception (self::$EXCEPTION_FAIL_CREATE_FILE, 0);
00603 }
00604 }
00605 }
00606
00607 protected function _addVersionTag()
00608 {
00609 $aDs = array();
00610 $aDs[] = $this->_sErpVersion;
00611 $this->_writeDsToBuffer("V", $aDs);
00612 }
00613
00621 protected function _writeDsToBuffer($sTag, $aDs, $sSep = ";")
00622 {
00623 if(is_array($aDs) && count($aDs)>0){
00624 $this->_sBuffer .= '"'. $sTag .'"';
00625 $this->_iBufferRecCounter ++;
00626 foreach ($aDs as $value) {
00627 $value = $this->_csvTextConvert($value, true);
00628 $this->_sBuffer .= $sSep;
00629 $this->_sBuffer .='"'.$value.'"';
00630 }
00631 $this->_sBuffer .="\r\n";
00632 }
00633 }
00634
00641 protected function _appendDsToBuffer($aDs, $sSep = ";")
00642 {
00643
00644 $this->_sBuffer = substr($this->_sBuffer, 0, strlen($this->_sBuffer)-2);
00645 foreach ($aDs as $value) {
00646 $value = $this->_csvTextConvert($value, true);
00647 $this->_sBuffer .= $sSep;
00648 $this->_sBuffer .='"'.$value.'"';
00649 }
00650 $this->_sBuffer .="\r\n";
00651 }
00652
00662 protected function _flushBuffer($file)
00663 {
00664 if(strlen($this->_sBuffer)>0){
00665 $res = fputs($file, $this->_sBuffer);
00666 if(!$res){
00667 throw new Exception(self::$EXCEPTION_FAIL_WRITE_FILE, 0);
00668 }
00669 }
00670 }
00671
00672 public function getBuffer()
00673 {
00674 return $this->_sBuffer;
00675 }
00676
00677
00678 protected function _checkIDField( $sID)
00679 {
00680 if( !isset( $sID) || !$sID)
00681 throw new Exception("ERROR: Articlenumber/ID missing!");
00682 elseif( strlen( $sID) > 32)
00683 throw new Exception( "ERROR: Articlenumber/ID longer then allowed (32 chars max.)!");
00684 }
00685
00693 protected function _getInstanceOfType( $sType)
00694 {
00695
00696 if($sType == 'oldOrder'){
00697 $oType = parent::_getInstanceOfType('order');
00698 $oType->setFieldList($this->getOldOrderFielsList());
00699 $oType->setFunctionSuffix('OldOrder');
00700 }elseif($sType == 'oldOrderArticle'){
00701 $oType = parent::_getInstanceOfType('orderarticle');
00702 $oType->setFieldList($this->getOldOrderArticleFieldList());
00703 $oType->setFunctionSuffix('OldOrderArticle');
00704 }elseif($sType == 'article2vendor'){
00705 $oType = parent::_getInstanceOfType('article');
00706 $oType->setFieldList(array("OXID", "OXVENDORID"));
00707 }elseif($sType == 'mainarticle2categroy') {
00708 $oType = parent::_getInstanceOfType('article2category');
00709 $oType->setFieldList(array("OXOBJECTID", "OXCATNID", "OXTIME"));
00710 $oType->setFunctionSuffix('mainarticle2category');
00711 }
00712 else{
00713 $oType = parent::_getInstanceOfType($sType);
00714 }
00715
00716 return $oType;
00717 }
00718
00719
00726 protected function _mapFields($aData, $oType)
00727 { $aRet = array();
00728
00729 $iIdx = 0;
00730 foreach( $oType->getFieldList() as $sField) {
00731
00732
00733
00734
00735 $aRet[$sField] = $aData[$iIdx];
00736 $iIdx++;
00737 }
00738
00739 return $aRet;
00740 }
00741
00742
00743
00744
00745
00746
00747
00748
00749 protected function _ExportArticle( $aRow)
00750 {
00751 $this->_writeDsToBuffer("A", $aRow);
00752 return true;
00753 }
00754
00755 protected function _ExportAccessoire( $aRow)
00756 {
00757 $this->_writeDsToBuffer("Z", $aRow);
00758 return true;
00759 }
00760
00761 protected function _ExportArticle2Action( $aRow){
00762 $this->_writeDsToBuffer("I", $aRow);
00763 return true;
00764 }
00765
00766 protected function _ExportArticle2Category( $aRow)
00767 {
00768
00769 }
00770
00771 protected function _ExportCategory( $aRow)
00772 {
00773 $this->_writeDsToBuffer("K", $aRow);
00774 return true;
00775 }
00776
00777 protected function _ExportCrossselling( $aRow)
00778 {
00779 $this->_writeDsToBuffer("C", $aRow);
00780 return true;
00781 }
00782
00783 protected function _ExportScaleprice( $aRow)
00784 {
00785 $this->_writeDsToBuffer("P", $aRow);
00786 return true;
00787
00788 }
00789
00790 protected function _ExportOldOrder( $aRow)
00791 {
00792 $this->_writeDsToBuffer("O", $aRow);
00793 return true;
00794 }
00795
00796 protected function _ExportOrder( $aRow)
00797 {
00798 $this->_writeDsToBuffer("O", $aRow);
00799 return true;
00800 }
00801
00802 protected function _ExportOldOrderArticle( $aRow)
00803 {
00804 $this->_writeDsToBuffer("A", $aRow);
00805 return true;
00806 }
00807
00808 protected function _ExportOrderArticle( $aRow)
00809 {
00810 $this->_writeDsToBuffer("R", $aRow);
00811 return true;
00812 }
00813
00814 protected function _ExportUser( $aRow)
00815 {
00816 $this->_writeDsToBuffer("U", $aRow);
00817 return true;
00818 }
00819
00820 protected function _ExportVendor( $aRow)
00821 {
00822 $this->_writeDsToBuffer("H", $aRow);
00823 return true;
00824 }
00825
00826 protected function _ExportArticleStock( $aRow){
00827 $this->_writeDsToBuffer("O", $aRow);
00828 return true;
00829 }
00830
00831 protected function _ExportCountry( $aRow)
00832 {
00833 $this->_writeDsToBuffer("N", $aRow);
00834 return true;
00835 }
00836
00837 protected function _ExportArtextends( $aRow) {
00838 if (oxERPBase::getRequestedVersion() < 2) {
00839 return false;
00840 }
00841 $this->_writeDsToBuffer("Y", $aRow);
00842 return true;
00843 }
00844
00845
00846
00847
00848
00849
00850
00851
00852
00853
00854
00855 protected function _ImportArticle( oxERPType & $oType, $aRow)
00856 {
00857
00858 if($this->_sCurrVersion == "0.1")
00859 {
00860 $myConfig = oxConfig::getInstance();
00861
00862 $myConfig->setConfigParam('blMallCustomPrice', false);
00863 }
00864
00865
00866 if(isset($aRow['OXID'])){
00867 $this->_checkIDField($aRow['OXID']);
00868 }else{
00869 $this->_checkIDField($aRow['OXARTNUM']);
00870 $aRow['OXID'] = $aRow['OXARTNUM'];
00871 }
00872
00873 $sResult = $this->_Save( $oType, $aRow, $this->_sCurrVersion == "0.1");
00874 return (boolean) $sResult;
00875 }
00876
00877 protected function _ImportAccessoire( oxERPType & $oType, $aRow) {
00878
00879
00880 if ( $this->_sCurrVersion == "0.1" && !isset($this->_aImportedAccessoire2Article[$aRow['OXARTICLENID']] ) ) {
00881 $myConfig = oxConfig::getInstance();
00882 $sDeleteSQL = "delete from oxaccessoire2article where oxarticlenid = '{$aRow['OXARTICLENID']}'";
00883 oxDb::getDb()->Execute( $sDeleteSQL );
00884 $this->_aImportedAccessoire2Article[$aRow['OXARTICLENID']] = 1;
00885 }
00886
00887 $sResult = $this->_Save( $oType, $aRow);
00888 return (boolean) $sResult;
00889 }
00890
00891 protected function _DeleteAccessoire (oxERPType & $oType, $sId)
00892 {
00893
00894 $oType->checkForDeletion($sId);
00895 return $oType->delete($sId);
00896 }
00897
00898 protected function _ImportArticle2Action( oxERPType & $oType, $aRow)
00899 {
00900
00901 if ( $this->_sCurrVersion == "0.1" && !isset( $this->_aImportedActions2Article[$aRow['OXARTID']] ) ) {
00902
00903
00904 $myConfig = oxConfig::getInstance();
00905 $sDeleteSQL = "delete from oxactions2article where oxartid = '{$aRow['OXARTID']}'";
00906 oxDb::getDb()->Execute( $sDeleteSQL );
00907 $this->_aImportedActions2Article[$aRow['OXARTID']] = 1;
00908 }
00909
00910 $sResult = $this->_Save( $oType, $aRow, $this->_sCurrVersion == "0.1");
00911 return (boolean) $sResult;
00912 }
00913
00914 protected function _DeleteArticle2Action (oxERPType & $oType, $sId)
00915 {
00916 $oType->checkForDeletion($sId);
00917 return $oType->delete($sId);
00918 }
00919
00920 protected function _ImportArticle2Category( oxERPType & $oType, $aRow)
00921 {
00922
00923
00924 if ( $this->_sCurrVersion == "0.1" && !isset( $this->_aImportedObject2Category[$aRow['OXOBJECTID']] ) ) {
00925 $myConfig = oxConfig::getInstance();
00926 $sDeleteSQL = "delete from oxobject2category where oxobjectid = '{$aRow['OXOBJECTID']}'";
00927 oxDb::getDb()->Execute( $sDeleteSQL );
00928 $this->_aImportedObject2Category[$aRow['OXOBJECTID']] = 1;
00929 }
00930
00931 $sResult = $this->_Save( $oType, $aRow);
00932 return (boolean) $sResult;
00933 }
00934
00935 protected function _ImportMainArticle2Category( oxERPType & $oType, $aRow)
00936 {
00937 $aRow['OXTIME'] = 0;
00938
00939 $myConfig = oxConfig::getInstance();
00940 $sSql = "select OXID from oxobject2category where oxobjectid = '".$aRow['OXOBJECTID']."' and OXCATNID = '".$aRow['OXCATNID']."'";
00941 $aRow['OXID'] = oxDb::getDb()->GetOne($sSql);
00942
00943 $sResult = $this->_Save( $oType, $aRow);
00944
00945 if ((boolean) $sResult) {
00946
00947 $sSql = "Update oxobject2category set oxtime = oxtime+10 where oxobjectid = '" . $aRow['OXOBJECTID'] ."' and oxcatnid != '". $aRow['OXCATNID'] ."' and oxshopid = '".$myConfig->getShopId()."'";
00948 oxDb::getDb()->Execute($sSql);
00949
00950 }
00951
00952 return (boolean) $sResult;
00953 }
00954
00955 protected function _DeleteArticle2Category(oxERPType & $oType, $sId)
00956 {
00957
00958 $oType->checkForDeletion($sId);
00959 return $oType->delete($sId);
00960 }
00961
00962 protected function _ImportCategory( oxERPType & $oType, $aRow)
00963 {
00964
00965 $sResult = $this->_Save( $oType, $aRow, $this->_sCurrVersion == "0.1");
00966 return (boolean) $sResult;
00967 }
00968
00969 protected function _DeleteCategory( oxERPType & $oType, $sId)
00970 {
00971
00972 $oCategory = $oType->getObjectForDeletion($sId);
00973
00974 if( $oCategory->oxcategories__oxright->value != $oCategory->oxcategories__oxleft->value+1) {
00975 throw new Exception( self::$ERROR_DELETE_NO_EMPTY_CATEGORY);
00976 }
00977
00978 return $oType->deleteObject($oCategory, $sId);
00979
00980 }
00981
00982 protected function _ImportCrossselling( oxERPType & $oType, $aRow)
00983 {
00984
00985
00986
00987 if ( $this->_sCurrVersion == "0.1" && !isset($this->_aImportedObject2Article[$aRow['OXARTICLENID']] ) ) {
00988 $myConfig = oxConfig::getInstance();
00989 $sDeleteSQL = "delete from oxobject2article where oxarticlenid = '{$aRow['OXARTICLENID']}'";
00990 oxDb::getDb()->Execute( $sDeleteSQL );
00991 $this->aImportedObject2Article[$aRow['OXARTICLENID']] = 1;
00992 }
00993
00994 $sResult = $this->_Save( $oType, $aRow);
00995 return (boolean) $sResult;
00996 }
00997
00998 protected function _DeleteCrossselling(oxERPType & $oType, $sId)
00999 {
01000
01001 $oType->checkForDeletion($sId);
01002 return $oType->delete($sId);
01003 }
01004
01005
01006 protected function _ImportScaleprice( oxERPType & $oType, $aRow)
01007 {
01008
01009 $sResult = $this->_Save( $oType, $aRow, $this->_sCurrVersion == "0.1");
01010 return (boolean) $sResult;
01011 }
01012
01013 protected function _DeleteScalePrice(oxERPType & $oType, $sId)
01014 {
01015
01016 $oType->checkForDeletion($sId);
01017
01018 return $oType->delete($sId);
01019 }
01020
01021 protected function _ImportOrder( oxERPType & $oType, $aRow)
01022 {
01023
01024 $sResult = $this->_Save( $oType, $aRow);
01025 return true;
01026
01027 }
01028
01029 protected function _ImportOrderArticle( oxERPType & $oType, $aRow)
01030 {
01031
01032 $sResult = $this->_Save( $oType, $aRow);
01033 return (boolean) $sResult;
01034 }
01035
01036 protected function _DeleteOrderArticle( oxERPType & $oType, $sId)
01037 {
01038
01039 $oOrderArticle = $oType->getObjectForDeletion($sId);
01040
01041 return $oType->deleteObject($oOrderArticle, $sId);
01042
01043 }
01044
01045 protected function _DeleteOrder( oxERPType & $oType, $sId)
01046 {
01047
01048 $oOrder = $oType->getObjectForDeletion($sId);
01049
01050 return $oType->deleteObject($oOrder, $sId);
01051
01052 }
01053
01054 protected function _ImportOrderStatus( oxERPType & $oType, $aRow) {
01055 $oOrderArt = oxNew( "oxorderarticle", "core");
01056 $oOrderArt->Load( $aRow['OXID']);
01057
01058 if( $oOrderArt->getId()) {
01059
01060 try {
01061 if( $this->_sCurrVersion != "0.1")
01062 $oType->checkWriteAccess($oOrderArt->getId());
01063
01064
01065 $aStatuses = unserialize( $oOrderArt->oxorderarticles__oxerpstatus->value );
01066
01067 $oStatus = new stdClass();
01068 $oStatus->STATUS = $aRow['OXERPSTATUS_STATUS'];
01069 $oStatus->date = $aRow['OXERPSTATUS_TIME'];
01070 $oStatus->trackingid = $aRow['OXERPSTATUS_TRACKID'];
01071
01072 $aStatuses[$aRow['OXERPSTATUS_TIME']] = $oStatus;
01073 $oOrderArt->oxorderarticles__oxerpstatus->value = serialize( $aStatuses);
01074 $oOrderArt->Save();
01075 return true;
01076 } catch (Exception $ex) {
01077 return false;
01078 }
01079 }
01080
01081 return false;
01082 }
01083
01084 protected function _DeleteArticle( oxERPType & $oType, $sId)
01085 {
01086 $oArt = $oType->getObjectForDeletion($sId);
01087
01088 return $oType->deleteObject($oArt, $sId);
01089
01090 }
01091
01092 protected function _ImportUser( oxERPType & $oType, $aRow)
01093 {
01094
01095
01096 if(isset($aRow['OXUSERNAME']))
01097 {
01098 $sID = $aRow['OXID'];
01099 $sUserName = $aRow['OXUSERNAME'];
01100
01101 $oUser = oxNew( "oxuser", "core");
01102 $oUser->oxuser__oxusername->value = $sUserName;
01103
01104
01105
01106 if( $oUser->exists( $sID) && $sID != $oUser->getId() ) {
01107 throw new Exception( "USER $sUserName already exists!");
01108 }
01109
01110 }
01111
01112 $sResult = $this->_Save( $oType, $aRow);
01113 return (boolean) $sResult;
01114 }
01115
01116 protected function _DeleteUser( oxERPType & $oType, $sId) {
01117
01118 $oUser = $oType->getObjectForDeletion($sId);
01119
01120 return $oType->deleteObject($oUser, $sId);
01121
01122 }
01123
01124 protected function _ImportVendor( oxERPType & $oType, $aRow)
01125 {
01126
01127 $sResult = $this->_Save( $oType, $aRow, $this->_sCurrVersion == "0.1");
01128 return (boolean) $sResult;
01129 }
01130
01131 protected function _ImportArtextends( oxERPType & $oType, $aRow) {
01132 if (oxERPBase::getRequestedVersion() < 2) {
01133 return false;
01134 }
01135 $sResult = $this->_Save( $oType, $aRow);
01136 return (boolean) $sResult;
01137 }
01138
01139 protected function _DeleteVendor( oxERPType & $oType, $sId)
01140 {
01141
01142 $oVendor = $oType->getObjectForDeletion($sId);
01143 return $oType->deleteObject($oVendor, $sId);
01144 }
01145
01146 protected function _ImportCountry( oxERPType & $oType, $aRow)
01147 {
01148 $sResult = $this->_Save( $oType, $aRow);
01149 return (boolean) $sResult;
01150 }
01151
01152 protected function _DeleteCountry( oxERPType & $oType, $sId)
01153 {
01154 $oVendor = $oType->getObjectForDeletion($sId);
01155 return $oType->deleteObject($oVendor, $sId);
01156 }
01157
01158
01159 protected function _ImportArticleStock( oxERPType & $oType, $aRow) {
01160 $sResult = $this->_Save( $oType, $aRow);
01161 return (boolean) $sResult;
01162 }
01163 }