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