00001 <?php
00002 
00008 class Article_Variant extends oxAdminDetails
00009 {
00016     public function render()
00017     {
00018         parent::render();
00019 
00020         $soxId = oxConfig::getParameter( "oxid");
00021         $sSLViewName = getViewName('oxselectlist');
00022 
00023         
00024         $oAllSel = oxNew( "oxlist");
00025         $oAllSel->init( "oxselectlist");
00026         $sQ = "select * from $sSLViewName";
00027         $oAllSel->selectString( $sQ);
00028         $this->_aViewData["allsel"] = $oAllSel;
00029 
00030         $oArticle = oxNew( "oxarticle");
00031         $this->_aViewData["edit"] =  $oArticle;
00032 
00033         if ( $soxId != "-1" && isset( $soxId)) {
00034             
00035             $oArticle->loadInLang( $this->_iEditLang, $soxId );
00036 
00037 
00038             $_POST["language"] = $_GET["language"] = $this->_iEditLang;
00039             $oVariants = $oArticle->getAdminVariants( $this->_iEditLang);
00040 
00041             $this->_aViewData["mylist"] =  $oVariants;
00042 
00043             
00044             $oOtherLang = $oArticle->getAvailableInLangs();
00045             if (!isset($oOtherLang[ $this->_iEditLang])) {
00046                 
00047                 $oArticle->loadInLang( key($oOtherLang), $soxId );
00048             }
00049 
00050             foreach ( $oOtherLang as $id => $language) {
00051                 $oLang= new oxStdClass();
00052                 $oLang->sLangDesc = $language;
00053                 $oLang->selected = ($id == $this->_iEditLang);
00054                 $this->_aViewData["otherlang"][$id] =  clone $oLang;
00055             }
00056 
00057             if ( $oArticle->oxarticles__oxparentid->value) {
00058                 $oParentArticle = oxNew( "oxarticle");
00059                 $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
00060                 $this->_aViewData["parentarticle"] =  $oParentArticle;
00061                 $this->_aViewData["oxparentid"] =  $oArticle->oxarticles__oxparentid->value;
00062                 $this->_aViewData["issubvariant"] = 1;
00063                 
00064                 $this->_aViewData["readonly"] = 1;
00065             }
00066             $this->_aViewData["editlanguage"] = $this->_iEditLang;
00067 
00068             $aLang = array_diff (oxLang::getInstance()->getLanguageNames(), $oOtherLang);
00069             if ( count( $aLang))
00070                 $this->_aViewData["posslang"] = $aLang;
00071 
00072             foreach ( $oOtherLang as $id => $language) {
00073                 $oLang= new oxStdClass();
00074                 $oLang->sLangDesc = $language;
00075                 $oLang->selected = ($id == $this->_iEditLang);
00076                 $this->_aViewData["otherlang"][$id] =  $oLang;
00077             }
00078         }
00079 
00080         return "article_variant.tpl";
00081     }
00082 
00091     public function savevariant($soxId = null, $aParams = null)
00092     {
00093         $myConfig  = $this->getConfig();
00094 
00095         
00096         
00097 
00098         if (!isset($soxId) && !isset($aParams)) {
00099             $soxId      = oxConfig::getParameter( "voxid");
00100             $aParams    = oxConfig::getParameter( "editval");
00101         }
00102 
00103         
00104         if ( !isset( $aParams['oxarticles__oxactive']))
00105             $aParams['oxarticles__oxactive'] = 0;
00106 
00107             
00108             $sShopID = oxSession::getVar( "actshop");
00109             $aParams['oxarticles__oxshopid'] = $sShopID;
00110 
00111         
00112         $soxparentId = oxConfig::getParameter( "oxid");
00113         if ( isset( $soxparentId) && $soxparentId && $soxparentId != "-1")
00114             $aParams['oxarticles__oxparentid'] = $soxparentId;
00115         else
00116             unset( $aParams['oxarticles__oxparentid']);
00117 
00118         $oArticle = oxNew( "oxarticle");
00119 
00120         
00121 
00122 
00123 
00124 
00125 
00126 
00127 
00128 
00129 
00130 
00131         if ( $soxId != "-1") {
00132             $oArticle->loadInLang( $this->_iEditLang, $soxId );
00133         }
00134         
00135 
00136 
00137         $oArticle->setLanguage(0);
00138         $oArticle->assign( $aParams);
00139         $oArticle->setLanguage($this->_iEditLang);
00140 
00141             
00142             $oArticle->save();
00143 
00144         
00145 
00146 
00147 
00148 
00149 
00150 
00151 
00152 
00153 
00154 
00155 
00156 
00157         $oArticle->setLanguage( $this->_iEditLang);
00158     }
00159 
00165     public function savevariants()
00166     {
00167         $myConfig = $this->getConfig();
00168 
00169 
00170         $aParams = oxConfig::getParameter( "editval");
00171 
00172         if (is_array($aParams))
00173             foreach($aParams as $soxId => $aVarParams)
00174                 $this->savevariant($soxId, $aVarParams);
00175 
00176     }
00177 
00183     public function deleteVariant()
00184     {
00185 
00186 
00187         $soxId = oxConfig::getParameter( "voxid");
00188         $oDelete = oxNew( "oxarticle" );
00189         $oDelete->delete( $soxId);
00190     }
00191 
00197     public function changename()
00198     {
00199         
00200         
00201 
00202         $soxId   = oxConfig::getParameter( "oxid");
00203         $aParams = oxConfig::getParameter( "editval");
00204 
00205 
00206 
00207             
00208             $sShopID = oxSession::getVar( "actshop");
00209             $aParams['oxarticles__oxshopid'] = $sShopID;
00210 
00211         $oArticle = oxNew( "oxarticle");
00212 
00213         if ( $soxId != "-1")
00214             $oArticle->loadInLang( $this->_iEditLang, $soxId );
00215 
00216         
00217 
00218         $oArticle->setLanguage(0);
00219         $oArticle->assign( $aParams);
00220         $oArticle->setLanguage($this->_iEditLang);
00221 
00222         $oArticle->save();
00223         
00224         $oArticle->setLanguage( $this->_iEditLang);
00225     }
00226 
00227 
00232     public function addsel()
00233     {
00234         $myConfig = $this->getConfig();
00235 
00236         $aSels = oxConfig::getParameter("allsel");
00237         $sParentID = oxConfig::getParameter("oxid");
00238         $oArticle = oxNew("oxarticle");
00239         $oArticle->load($sParentID);
00240         $oVariants = $oArticle->getAdminVariants();
00241 
00242 
00243 
00244         $sSLViewName = getViewName('oxselectlist');
00245 
00246         if ($aSels) {
00247             $myUtils = oxUtils::getInstance();
00248             $myLang  = oxLang::getInstance();
00249             $oDb = oxDb::getDb();
00250             foreach ($aSels as $sSelID) {
00251 
00252                 $oSel = oxNew("oxselectlist");
00253                 $oSel->load($sSelID);
00254 
00255                 
00256                 $this->sLanguage = $myLang->getBaseLanguage();
00257 
00258                 $sField = "oxvaldesc".$myLang->getLanguageTag();
00259                 $sQ = "select $sField from $sSLViewName where oxid  = ". $oDb->quote( $sSelID );
00260                 $sValues = $oDb->GetOne($sQ);
00261 
00262                 $aValues = $myUtils->assignValuesFromText($sValues );
00263                 
00264                 $iCounter = 0;
00265                 foreach ($aValues as $oValue) {
00266                     $dPriceMod = 0;
00267                     if ( $myConfig->getConfigParam( 'bl_perfLoadSelectLists' ) && $myConfig->getConfigParam( 'bl_perfUseSelectlistPrice' ) ) {
00268                         if ($oValue->priceUnit == 'abs')
00269                             $dPriceMod = $oValue->price;
00270                         elseif ($oValue->priceUnit == '%') {
00271                             $dPriceModPerc = abs($oValue->price)*$oArticle->oxarticles__oxprice->value/100.0;
00272                             if (($oValue->price) >= 0.0)
00273                                 $dPriceMod = $dPriceModPerc;
00274                             else
00275                                 $dPriceMod = -$dPriceModPerc;
00276                         }
00277                     }
00278 
00279                     if ($oVariants->count()>0) {
00280                         
00281                         foreach ($oVariants as $oSimpleVariant) {
00282                             if (!$iCounter) {
00283                                 
00284                                 $oVariant = oxNew("oxarticle");
00285                                 $oVariant->load($oSimpleVariant->oxarticles__oxid->value);
00286                                 $oVariant->oxarticles__oxprice->setValue($oVariant->oxarticles__oxprice->value + $dPriceMod);
00287                                 $oVariant->oxarticles__oxvarselect->setValue($oVariant->oxarticles__oxvarselect->value." ".$oValue->name);
00288                                 $oVariant->oxarticles__oxsort->setValue($oVariant->oxarticles__oxsort->value * 10);
00289                                 $oVariant->save();
00290                             } else {
00291 
00292                                 
00293                                 $aParams['oxarticles__oxvarselect'] = $oSimpleVariant->oxarticles__oxvarselect->value." ".$oValue->name;
00294                                 $aParams['oxarticles__oxartnum'] = $oSimpleVariant->oxarticles__oxartnum->value;
00295                                 $aParams['oxarticles__oxprice'] = $oSimpleVariant->oxarticles__oxprice->value + $dPriceMod;
00296                                 $aParams['oxarticles__oxsort'] = $oSimpleVariant->oxarticles__oxsort->value*10 + 10*$iCounter;
00297                                 $aParams['oxarticles__oxstock'] = 0;
00298                                 $aParams['oxarticles__oxstockflag'] = $oSimpleVariant->oxarticles__oxstockflag->value;
00299                                 $this->savevariant(null, $aParams);
00300                             }
00301                         }
00302 
00303                         $iCounter++;
00304 
00305                     } else {
00306                         
00307 
00308                         
00309                         $aParams['oxarticles__oxvarselect'] = $oValue->name;
00310                         $aParams['oxarticles__oxartnum'] = $oArticle->oxarticles__oxartnum->value;
00311                         $aParams['oxarticles__oxprice'] = $oArticle->oxarticles__oxprice->value + $dPriceMod;
00312                         $aParams['oxarticles__oxsort'] = 5000 + $iCounter++ * 1000;
00313                         $aParams['oxarticles__oxstock'] = 0;
00314                         $aParams['oxarticles__oxstockflag'] = $oArticle->oxarticles__oxstockflag->value;
00315                         $this->savevariant(null, $aParams);
00316                     }
00317                 }
00318                 $oArticle->oxarticles__oxvarname->setValue($oArticle->oxarticles__oxvarname->value." ".$oSel->oxselectlist__oxtitle->value);
00319                 $oArticle->oxarticles__oxvarname->setValue(trim($oArticle->oxarticles__oxvarname->value));
00320                 $oArticle->save();
00321             }
00322         }
00323     }
00324 }