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 = oxConfig::getParameter( "oxid");
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 oxStdClass();
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 (oxLang::getInstance()->getLanguageNames(), $oOtherLang);
00074             if ( count( $aLang))
00075                 $this->_aViewData["posslang"] = $aLang;
00076 
00077             foreach ( $oOtherLang as $id => $language) {
00078                 $oLang= new oxStdClass();
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 = oxConfig::getParameter( "oxid" );
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 
00137         $oArticle->setLanguage( 0 );
00138         $oArticle->assign( $aParams );
00139         $oArticle->setLanguage( $this->_iEditLang );
00140 
00141 
00142         $oArticle->save();
00143     }
00144 
00152     protected function _getProductParent( $sParentId )
00153     {
00154         if ( $this->_oProductParent === null ||
00155              ( $this->_oProductParent !== false && $this->_oProductParent->getId() != $sParentId ) ) {
00156             $this->_oProductParent = false;
00157             $oProduct = oxNew( "oxarticle" );
00158             if ( $oProduct->load( $sParentId ) ) {
00159                 $this->_oProductParent = $oProduct;
00160             }
00161         }
00162         return $this->_oProductParent;
00163     }
00164 
00170     public function savevariants()
00171     {
00172 
00173         $aParams = oxConfig::getParameter( "editval" );
00174         if ( is_array( $aParams ) ) {
00175             foreach ( $aParams as $soxId => $aVarParams ) {
00176                 $this->savevariant( $soxId, $aVarParams );
00177             }
00178         }
00179 
00180     }
00181 
00187     public function deleteVariant()
00188     {
00189 
00190 
00191         $soxId = oxConfig::getParameter( "voxid" );
00192         $oDelete = oxNew( "oxarticle" );
00193         $oDelete->delete( $soxId );
00194     }
00195 
00201     public function changename()
00202     {
00203         $soxId = oxConfig::getParameter( "oxid" );
00204 
00205         $aParams = oxConfig::getParameter( "editval");
00206 
00207 
00208             // shopid
00209             $aParams['oxarticles__oxshopid'] = oxSession::getVar( "actshop" );
00210 
00211         $oArticle = oxNew( "oxarticle" );
00212         if ( $soxId != "-1") {
00213             $oArticle->loadInLang( $this->_iEditLang, $soxId );
00214         }
00215 
00216         $oArticle->setLanguage( 0 );
00217         $oArticle->assign( $aParams);
00218         $oArticle->setLanguage( $this->_iEditLang );
00219         $oArticle->save();
00220     }
00221 
00222 
00228     public function addsel()
00229     {
00230         $oArticle = oxNew("oxarticle");
00231         $oArticle->setEnableMultilang( false );
00232         if ( $oArticle->load( oxConfig::getParameter("oxid") ) ) {
00233 
00234 
00235 
00236             if ( $aSels = oxConfig::getParameter( "allsel" ) ) {
00237                 $oVariantHandler = oxNew( "oxVariantHandler" );
00238                 $oVariantHandler->genVariantFromSell( $aSels, $oArticle );
00239             }
00240         }
00241     }
00242 }