article_extend.php

Go to the documentation of this file.
00001 <?php
00002 
00010 class Article_Extend extends oxAdminDetails
00011 {
00016     protected $_aUnitsArray = null;
00017 
00024     public function render()
00025     {
00026         parent::render();
00027 
00028         $this->_aViewData['edit'] = $oArticle = oxNew( 'oxarticle' );
00029 
00030         $soxId = $this->getEditObjectId();
00031 
00032         $this->_createCategoryTree( "artcattree");
00033 
00034         // all categories
00035         if ( $soxId != "-1" && isset( $soxId ) ) {
00036             // load object
00037             $oArticle->loadInLang( $this->_iEditLang, $soxId );
00038 
00039 
00040             // load object in other languages
00041             $oOtherLang = $oArticle->getAvailableInLangs();
00042             if (!isset($oOtherLang[$this->_iEditLang])) {
00043                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00044                 $oArticle->loadInLang( key($oOtherLang), $soxId );
00045             }
00046 
00047             foreach ( $oOtherLang as $id => $language) {
00048                 $oLang= new stdClass();
00049                 $oLang->sLangDesc = $language;
00050                 $oLang->selected = ($id == $this->_iEditLang);
00051                 $this->_aViewData["otherlang"][$id] =  clone $oLang;
00052             }
00053 
00054             // variant handling
00055             if ( $oArticle->oxarticles__oxparentid->value) {
00056                 $oParentArticle = oxNew( 'oxarticle' );
00057                 $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
00058                 $oArticle->oxarticles__oxnonmaterial = new oxField( $oParentArticle->oxarticles__oxnonmaterial->value );
00059                 $oArticle->oxarticles__oxfreeshipping = new oxField( $oParentArticle->oxarticles__oxfreeshipping->value );
00060                 $this->_aViewData["parentarticle"] = $oParentArticle;
00061                 $this->_aViewData["oxparentid"]    = $oArticle->oxarticles__oxparentid->value;
00062             }
00063 
00064             $sO2CView = getViewName('oxobject2category');
00065         }
00066 
00067 
00068             $oDB = oxDb::getDB();
00069             $myConfig = $this->getConfig();
00070 
00071             $sArticleTable = getViewName( 'oxarticles', $this->_iEditLang );
00072             $sSelect  = "select $sArticleTable.oxtitle, $sArticleTable.oxartnum, $sArticleTable.oxvarselect from $sArticleTable where 1 ";
00073             // #546
00074             $sSelect .= $myConfig->getConfigParam( 'blVariantsSelection' )?'':" and $sArticleTable.oxparentid = '' ";
00075             $sSelect .= " and $sArticleTable.oxid = ".$oDB->quote( $oArticle->oxarticles__oxbundleid->value );
00076 
00077             $rs = $oDB->Execute( $sSelect);
00078             if ($rs != false && $rs->RecordCount() > 0) {
00079                 while (!$rs->EOF) {
00080                     $sArtNum = new oxField($rs->fields[1]);
00081                     $sArtTitle = new oxField($rs->fields[0]." ".$rs->fields[2]);
00082                     $rs->MoveNext();
00083                 }
00084             }
00085             $this->_aViewData['bundle_artnum'] = $sArtNum;
00086             $this->_aViewData['bundle_title'] = $sArtTitle;
00087 
00088 
00089         $iAoc = oxConfig::getParameter("aoc");
00090         if ( $iAoc == 1 ) {
00091             $oArticleExtendAjax = oxNew( 'article_extend_ajax' );
00092             $this->_aViewData['oxajax'] = $oArticleExtendAjax->getColumns();
00093 
00094             return "popups/article_extend.tpl";
00095         } elseif ( $iAoc == 2 ) {
00096             $oArticleBundleAjax = oxNew( 'article_bundle_ajax' );
00097             $this->_aViewData['oxajax'] = $oArticleBundleAjax->getColumns();
00098 
00099             return "popups/article_bundle.tpl";
00100         }
00101 
00102         //load media files
00103         $this->_aViewData['aMediaUrls'] = $oArticle->getMediaUrls();
00104 
00105         return "article_extend.tpl";
00106     }
00107 
00113     public function save()
00114     {
00115         parent::save();
00116 
00117         $aMyFile = $this->getConfig()->getUploadedFile( "myfile" );
00118         $aMediaFile = $this->getConfig()->getUploadedFile( "mediaFile" );
00119         if ( is_array( $aMyFile['name'] ) && reset( $aMyFile['name'] ) || $aMediaFile['name'] ) {
00120             $myConfig = $this->getConfig();
00121             if ( $myConfig->isDemoShop() ) {
00122                 $oEx = oxNew( "oxExceptionToDisplay" );
00123                 $oEx->setMessage( 'ARTICLE_EXTEND_UPLOADISDISABLED' );
00124                 oxRegistry::get("oxUtilsView")->addErrorToDisplay( $oEx, false );
00125 
00126                 return;
00127             }
00128         }
00129 
00130         $soxId = $this->getEditObjectId();
00131         $aParams = oxRegistry::getConfig()->getRequestParameter( "editval");
00132         // checkbox handling
00133         if ( !isset( $aParams['oxarticles__oxissearch'])) {
00134             $aParams['oxarticles__oxissearch'] = 0;
00135         }
00136         if ( !isset( $aParams['oxarticles__oxblfixedprice'])) {
00137             $aParams['oxarticles__oxblfixedprice'] = 0;
00138         }
00139 
00140         // new way of handling bundled articles
00141         //#1517C - remove posibility to add Bundled Product
00142         //$this->setBundleId($aParams, $soxId);
00143 
00144         // default values
00145         $aParams = $this->addDefaultValues( $aParams);
00146 
00147         $oArticle = oxNew( "oxarticle" );
00148         $oArticle->loadInLang( $this->_iEditLang, $soxId);
00149 
00150         if ( $aParams['oxarticles__oxtprice'] != $oArticle->oxarticles__oxtprice->value &&  $aParams['oxarticles__oxtprice'] && $aParams['oxarticles__oxtprice'] <= $oArticle->oxarticles__oxprice->value) {
00151             //$aParams['oxarticles__oxtprice'] = $oArticle->oxarticles__oxtprice->value;
00152             $this->_aViewData["errorsavingtprice"] = 1;
00153         }
00154 
00155         //$aParams = $oArticle->ConvertNameArray2Idx( $aParams);
00156         $oArticle->setLanguage(0);
00157         $oArticle->assign( $aParams);
00158         $oArticle->setLanguage($this->_iEditLang);
00159         $oArticle = oxRegistry::get("oxUtilsFile")->processFiles( $oArticle );
00160         $oArticle->save();
00161 
00162         //saving media file
00163         $sMediaUrl  = oxConfig::getParameter( "mediaUrl");
00164         $sMediaDesc = oxConfig::getParameter( "mediaDesc");
00165 
00166         if ( ( $sMediaUrl && $sMediaUrl != 'http://' ) || $aMediaFile['name'] || $sMediaDesc ) {
00167 
00168             if ( !$sMediaDesc ) {
00169                 return oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_NODESCRIPTIONADDED' );
00170             }
00171 
00172             if ( ( !$sMediaUrl || $sMediaUrl == 'http://' ) && !$aMediaFile['name'] ) {
00173                 return oxRegistry::get("oxUtilsView")->addErrorToDisplay( 'EXCEPTION_NOMEDIAADDED' );
00174             }
00175 
00176             $oMediaUrl = oxNew( "oxMediaUrl" );
00177             $oMediaUrl->setLanguage( $this->_iEditLang );
00178             $oMediaUrl->oxmediaurls__oxisuploaded = new oxField( 0, oxField::T_RAW );
00179 
00180             //handle uploaded file
00181             if ($aMediaFile['name']) {
00182                 try {
00183                     $sMediaUrl = oxRegistry::get("oxUtilsFile")->processFile( 'mediaFile', 'out/media/' );
00184                     $oMediaUrl->oxmediaurls__oxisuploaded = new oxField(1, oxField::T_RAW);
00185                 } catch (Exception $e) {
00186                     return oxRegistry::get("oxUtilsView")->addErrorToDisplay( $e->getMessage() );
00187                 }
00188             }
00189 
00190             //save media url
00191             $oMediaUrl->oxmediaurls__oxobjectid = new oxField($soxId, oxField::T_RAW);
00192             $oMediaUrl->oxmediaurls__oxurl      = new oxField($sMediaUrl, oxField::T_RAW);
00193             $oMediaUrl->oxmediaurls__oxdesc     = new oxField($sMediaDesc, oxField::T_RAW);
00194             $oMediaUrl->save();
00195         }
00196 
00197         // renew price update time
00198         oxNew( "oxArticleList" )->renewPriceUpdateTime();
00199     }
00200 
00206     public function deletemedia()
00207     {
00208         $soxId = $this->getEditObjectId();
00209         $sMediaId = oxConfig::getParameter( "mediaid");
00210         if ($sMediaId && $soxId) {
00211             $oMediaUrl = oxNew("oxMediaUrl");
00212             $oMediaUrl->load($sMediaId);
00213             $oMediaUrl->delete();
00214         }
00215     }
00216 
00225     public function addDefaultValues( $aParams)
00226     {
00227         $aParams['oxarticles__oxexturl'] = str_replace( "http://", "", $aParams['oxarticles__oxexturl']);
00228 
00229         return $aParams;
00230     }
00231 
00237     public function updateMedia()
00238     {
00239         $aMediaUrls = oxConfig::getParameter( 'aMediaUrls' );
00240         if ( is_array( $aMediaUrls ) ) {
00241             foreach ( $aMediaUrls as $sMediaId => $aMediaParams ) {
00242                 $oMedia = oxNew("oxMediaUrl");
00243                 if ( $oMedia->load( $sMediaId ) ) {
00244                     $oMedia->setLanguage(0);
00245                     $oMedia->assign( $aMediaParams );
00246                     $oMedia->setLanguage( $this->_iEditLang );
00247                     $oMedia->save();
00248                 }
00249             }
00250         }
00251     }
00252 
00258     public function getUnitsArray()
00259     {
00260         if ( $this->_aUnitsArray === null ) {
00261            $this->_aUnitsArray = oxRegistry::getLang()->getSimilarByKey( "_UNIT_", $this->_iEditLang, false );
00262         }
00263         return $this->_aUnitsArray;
00264     }
00265 }