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                 $oArticle->oxarticles__oxremindactive = new oxField( $oParent->oxarticles__oxremindactive->value );
00147 
00148             }
00149         }
00150 
00151         $oArticle->save();
00152     }
00153 
00161     protected function _getProductParent( $sParentId )
00162     {
00163         if ( $this->_oProductParent === null ||
00164              ( $this->_oProductParent !== false && $this->_oProductParent->getId() != $sParentId ) ) {
00165             $this->_oProductParent = false;
00166             $oProduct = oxNew( "oxarticle" );
00167             if ( $oProduct->load( $sParentId ) ) {
00168                 $this->_oProductParent = $oProduct;
00169             }
00170         }
00171         return $this->_oProductParent;
00172     }
00173 
00179     public function savevariants()
00180     {
00181 
00182         $aParams = oxConfig::getParameter( "editval" );
00183         if ( is_array( $aParams ) ) {
00184             foreach ( $aParams as $soxId => $aVarParams ) {
00185                 $this->savevariant( $soxId, $aVarParams );
00186             }
00187         }
00188 
00189     }
00190 
00196     public function deleteVariant()
00197     {
00198 
00199 
00200         $soxId = oxConfig::getParameter( "voxid" );
00201         $oDelete = oxNew( "oxarticle" );
00202         $oDelete->delete( $soxId );
00203     }
00204 
00210     public function changename()
00211     {
00212         $soxId = $this->getEditObjectId();
00213         $aParams = oxConfig::getParameter( "editval");
00214 
00215 
00216             // shopid
00217             $aParams['oxarticles__oxshopid'] = oxSession::getVar( "actshop" );
00218 
00219         $oArticle = oxNew( "oxarticle" );
00220         if ( $soxId != "-1") {
00221             $oArticle->loadInLang( $this->_iEditLang, $soxId );
00222         }
00223 
00224         $oArticle->setLanguage( 0 );
00225         $oArticle->assign( $aParams);
00226         $oArticle->setLanguage( $this->_iEditLang );
00227         $oArticle->save();
00228     }
00229 
00230 
00236     public function addsel()
00237     {
00238         $oArticle = oxNew("oxarticle");
00239         //#3644
00240         //$oArticle->setEnableMultilang( false );
00241         if ( $oArticle->load( $this->getEditObjectId() ) ) {
00242 
00243 
00244 
00245             if ( $aSels = oxConfig::getParameter( "allsel" ) ) {
00246                 $oVariantHandler = oxNew( "oxVariantHandler" );
00247                 $oVariantHandler->genVariantFromSell( $aSels, $oArticle );
00248             }
00249         }
00250     }
00251 }