article_variant.php

Go to the documentation of this file.
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         // all selectlists
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             // load object
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             // load object in other languages
00044             $oOtherLang = $oArticle->getAvailableInLangs();
00045             if (!isset($oOtherLang[ $this->_iEditLang])) {
00046                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
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                 // A. we do not support variants for variants, as this will broke all stock logics etc
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         //if (!oxConfig::getParameter( "editlanguage"))
00096         //    oxSession::setVar( "editlanguage", $this->_iEditLang);
00097 
00098         if (!isset($soxId) && !isset($aParams)) {
00099             $soxId      = oxConfig::getParameter( "voxid");
00100             $aParams    = oxConfig::getParameter( "editval");
00101         }
00102 
00103         // checkbox handling
00104         if ( !isset( $aParams['oxarticles__oxactive']))
00105             $aParams['oxarticles__oxactive'] = 0;
00106 
00107             // shopid
00108             $sShopID = oxSession::getVar( "actshop");
00109             $aParams['oxarticles__oxshopid'] = $sShopID;
00110 
00111         // varianthandling
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         //TODO: solve this from lazy loading point of view
00122         //acessing main fields for lazy loading mechnism to iniatialise them
00123         $oArticle->oxarticles__oxvarselect->value;
00124         $oArticle->oxarticles__oxartnum->value;
00125         $oArticle->oxarticles__oxprice->value;
00126         $oArticle->oxarticles__oxstock->value;
00127         $oArticle->oxarticles__oxshopid->value;
00128         $oArticle->oxarticles__oxshopincl->value;
00129         $oArticle->oxarticles__oxshopexcl->value;*/
00130 
00131         if ( $soxId != "-1") {
00132             $oArticle->loadInLang( $this->_iEditLang, $soxId );
00133         }
00134         //$aParams = $oArticle->ConvertNameArray2Idx( $aParams);
00135 
00136 
00137         $oArticle->setLanguage(0);
00138         $oArticle->assign( $aParams);
00139         $oArticle->setLanguage($this->_iEditLang);
00140 
00141             //echo $aParams['oxarticles__oxartnum']."---";
00142             $oArticle->save();
00143 
00144         /*V Do we need this?
00145         $sParentVarName = oxConfig::getParameter("parentvarname");
00146         if ($sParentVarName) {
00147             $oParent = oxNew( "oxarticle");
00148             $oArticle->loadInLang( $this->_iEditLang, $oArticle->oxarticles__oxparentid->value );
00149             $oParent->setLanguage(0);
00150             $aParam['oxarticles__oxvarname'] = $sParentVarName;
00151             $oParent->assign( $aParam);
00152             $oParent->setLanguage($this->_iEditLang);
00153             $oParent->save();
00154             $oParent->setLanguage($this->_iEditLang);
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         //if (!oxConfig::getParameter( "editlanguage"))
00200         //    oxSession::setVar( "editlanguage",$this->_iEditLang);
00201 
00202         $soxId   = oxConfig::getParameter( "oxid");
00203         $aParams = oxConfig::getParameter( "editval");
00204 
00205 
00206 
00207             // shopid
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         //$aParams = $oArticle->ConvertNameArray2Idx( $aParams);
00217 
00218         $oArticle->setLanguage(0);
00219         $oArticle->assign( $aParams);
00220         $oArticle->setLanguage($this->_iEditLang);
00221 
00222         $oArticle->save();
00223         //$oArticle->SetLanguage(oxConfig::getParameter( "editlanguage"));
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                 //selecting select list name values
00256                 $this->sLanguage = $myLang->getBaseLanguage();
00257 
00258                 $sField = "oxvaldesc".$myLang->getLanguageTag();
00259                 $sQ = "select $sField from $sSLViewName where oxid  = '$sSelID' ";
00260                 $sValues = $oDb->GetOne($sQ);
00261 
00262                 $aValues = $myUtils->assignValuesFromText($sValues );
00263                 //iterating through all select list values (eg. $oValue->name = S, M, X, XL)
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                         //if we have any existing variants then copying each variant with $oValue->name
00281                         foreach ($oVariants as $oSimpleVariant) {
00282                             if (!$iCounter) {
00283                                 //we just update the first variant
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                                 //we create new variants
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                         //in case we don't have any variants then we just create variant(s) with $oValue->name
00307 
00308                         //so yes here we create a new variant
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 }

Generated on Tue Apr 21 15:45:43 2009 for OXID eShop CE by  doxygen 1.5.5