article_variant.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Article_Variant extends oxAdminDetails
00009 {
00015     protected $_oProductParent = null;
00016 
00023     public function render()
00024     {
00025         parent::render();
00026 
00027         $soxId = $this->getEditObjectId();
00028         $sSLViewName = getViewName('oxselectlist');
00029 
00030         // all selectlists
00031         $oAllSel = oxNew( "oxlist");
00032         $oAllSel->init( "oxselectlist");
00033         $sQ = "select * from $sSLViewName";
00034         $oAllSel->selectString( $sQ);
00035         $this->_aViewData["allsel"] = $oAllSel;
00036 
00037         $oArticle = oxNew( "oxarticle");
00038         $this->_aViewData["edit"] =  $oArticle;
00039 
00040         if ( $soxId != "-1" && isset( $soxId)) {
00041             // load object
00042             $oArticle->loadInLang( $this->_iEditLang, $soxId );
00043 
00044 
00045             $_POST["language"] = $_GET["language"] = $this->_iEditLang;
00046             $oVariants = $oArticle->getAdminVariants( $this->_iEditLang);
00047 
00048             $this->_aViewData["mylist"] =  $oVariants;
00049 
00050             // load object in other languages
00051             $oOtherLang = $oArticle->getAvailableInLangs();
00052             if (!isset($oOtherLang[ $this->_iEditLang])) {
00053                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00054                 $oArticle->loadInLang( key($oOtherLang), $soxId );
00055             }
00056 
00057             foreach ( $oOtherLang as $id => $language) {
00058                 $oLang= new stdClass();
00059                 $oLang->sLangDesc = $language;
00060                 $oLang->selected = ($id == $this->_iEditLang);
00061                 $this->_aViewData["otherlang"][$id] =  clone $oLang;
00062             }
00063 
00064             if ( $oArticle->oxarticles__oxparentid->value) {
00065                 $this->_aViewData["parentarticle"] =  $this->_getProductParent( $oArticle->oxarticles__oxparentid->value );
00066                 $this->_aViewData["oxparentid"]    =  $oArticle->oxarticles__oxparentid->value;
00067                 $this->_aViewData["issubvariant"]  = 1;
00068                 // A. disable variant information editing for variant
00069                 $this->_aViewData["readonly"] = 1;
00070             }
00071             $this->_aViewData["editlanguage"] = $this->_iEditLang;
00072 
00073             $aLang = array_diff (oxRegistry::getLang()->getLanguageNames(), $oOtherLang);
00074             if ( count( $aLang))
00075                 $this->_aViewData["posslang"] = $aLang;
00076 
00077             foreach ( $oOtherLang as $id => $language) {
00078                 $oLang= new stdClass();
00079                 $oLang->sLangDesc = $language;
00080                 $oLang->selected = ($id == $this->_iEditLang);
00081                 $this->_aViewData["otherlang"][$id] =  $oLang;
00082             }
00083         }
00084 
00085         return "article_variant.tpl";
00086     }
00087 
00096     public function savevariant($sOXID = null, $aParams = null)
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 
00108             // shopid
00109             $aParams['oxarticles__oxshopid'] = oxSession::getVar( "actshop" );
00110 
00111         // varianthandling
00112         $soxparentId = $this->getEditObjectId();
00113         if ( isset( $soxparentId) && $soxparentId && $soxparentId != "-1" ) {
00114             $aParams['oxarticles__oxparentid'] = $soxparentId;
00115         } else {
00116             unset( $aParams['oxarticles__oxparentid'] );
00117         }
00118 
00119         $oArticle = oxNew( "oxarticle");
00120 
00121         /*
00122         //TODO: solve this from lazy loading point of view
00123         //acessing main fields for lazy loading mechnism to iniatialise them
00124         $oArticle->oxarticles__oxvarselect->value;
00125         $oArticle->oxarticles__oxartnum->value;
00126         $oArticle->oxarticles__oxprice->value;
00127         $oArticle->oxarticles__oxstock->value;
00128         $oArticle->oxarticles__oxshopid->value;
00129         $oArticle->oxarticles__oxshopincl->value;
00130         $oArticle->oxarticles__oxshopexcl->value;*/
00131 
00132         if ( $sOXID != "-1" ) {
00133             $oArticle->loadInLang( $this->_iEditLang, $sOXID );
00134         }
00135 
00136         $oArticle->setLanguage( 0 );
00137         $oArticle->assign( $aParams );
00138         $oArticle->setLanguage( $this->_iEditLang );
00139 
00140         if ( $sOXID == "-1" ) {
00141             if ( $oParent = $this->_getProductParent( $oArticle->oxarticles__oxparentid->value ) ) {
00142 
00143                 // assign field from parent for new variant
00144                 // #4406
00145                 $oArticle->oxarticles__oxisconfigurable = new oxField( $oParent->oxarticles__oxisconfigurable->value );
00146 
00147             }
00148         }
00149 
00150         $oArticle->save();
00151     }
00152 
00160     protected function _getProductParent( $sParentId )
00161     {
00162         if ( $this->_oProductParent === null ||
00163              ( $this->_oProductParent !== false && $this->_oProductParent->getId() != $sParentId ) ) {
00164             $this->_oProductParent = false;
00165             $oProduct = oxNew( "oxarticle" );
00166             if ( $oProduct->load( $sParentId ) ) {
00167                 $this->_oProductParent = $oProduct;
00168             }
00169         }
00170         return $this->_oProductParent;
00171     }
00172 
00178     public function savevariants()
00179     {
00180 
00181         $aParams = oxConfig::getParameter( "editval" );
00182         if ( is_array( $aParams ) ) {
00183             foreach ( $aParams as $soxId => $aVarParams ) {
00184                 $this->savevariant( $soxId, $aVarParams );
00185             }
00186         }
00187 
00188     }
00189 
00195     public function deleteVariant()
00196     {
00197 
00198 
00199         $soxId = oxConfig::getParameter( "voxid" );
00200         $oDelete = oxNew( "oxarticle" );
00201         $oDelete->delete( $soxId );
00202     }
00203 
00209     public function changename()
00210     {
00211         $soxId = $this->getEditObjectId();
00212         $aParams = oxConfig::getParameter( "editval");
00213 
00214 
00215             // shopid
00216             $aParams['oxarticles__oxshopid'] = oxSession::getVar( "actshop" );
00217 
00218         $oArticle = oxNew( "oxarticle" );
00219         if ( $soxId != "-1") {
00220             $oArticle->loadInLang( $this->_iEditLang, $soxId );
00221         }
00222 
00223         $oArticle->setLanguage( 0 );
00224         $oArticle->assign( $aParams);
00225         $oArticle->setLanguage( $this->_iEditLang );
00226         $oArticle->save();
00227     }
00228 
00229 
00235     public function addsel()
00236     {
00237         $oArticle = oxNew("oxarticle");
00238         //#3644
00239         //$oArticle->setEnableMultilang( false );
00240         if ( $oArticle->load( $this->getEditObjectId() ) ) {
00241 
00242 
00243 
00244             if ( $aSels = oxConfig::getParameter( "allsel" ) ) {
00245                 $oVariantHandler = oxNew( "oxVariantHandler" );
00246                 $oVariantHandler->genVariantFromSell( $aSels, $oArticle );
00247             }
00248         }
00249     }
00250 }