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
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
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
00051 $oOtherLang = $oArticle->getAvailableInLangs();
00052 if (!isset($oOtherLang[ $this->_iEditLang])) {
00053
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
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
00104 if ( !isset( $aParams['oxarticles__oxactive'] ) ) {
00105 $aParams['oxarticles__oxactive'] = 0;
00106 }
00107
00108
00109 $aParams['oxarticles__oxshopid'] = oxSession::getVar( "actshop" );
00110
00111
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
00123
00124
00125
00126
00127
00128
00129
00130
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
00141 $oArticle->resetRemindStatus();
00142
00143 if ( $sOXID == "-1" ) {
00144 if ( $oParent = $this->_getProductParent( $oArticle->oxarticles__oxparentid->value ) ) {
00145
00146
00147
00148 $oArticle->oxarticles__oxisconfigurable = new oxField( $oParent->oxarticles__oxisconfigurable->value );
00149 $oArticle->oxarticles__oxremindactive = new oxField( $oParent->oxarticles__oxremindactive->value );
00150
00151 }
00152 }
00153
00154 $oArticle->save();
00155 }
00156
00164 protected function _getProductParent( $sParentId )
00165 {
00166 if ( $this->_oProductParent === null ||
00167 ( $this->_oProductParent !== false && $this->_oProductParent->getId() != $sParentId ) ) {
00168 $this->_oProductParent = false;
00169 $oProduct = oxNew( "oxarticle" );
00170 if ( $oProduct->load( $sParentId ) ) {
00171 $this->_oProductParent = $oProduct;
00172 }
00173 }
00174 return $this->_oProductParent;
00175 }
00176
00182 public function savevariants()
00183 {
00184
00185 $aParams = oxConfig::getParameter( "editval" );
00186 if ( is_array( $aParams ) ) {
00187 foreach ( $aParams as $soxId => $aVarParams ) {
00188 $this->savevariant( $soxId, $aVarParams );
00189 }
00190 }
00191
00192 }
00193
00199 public function deleteVariant()
00200 {
00201
00202
00203 $soxId = oxConfig::getParameter( "voxid" );
00204 $oDelete = oxNew( "oxarticle" );
00205 $oDelete->delete( $soxId );
00206 }
00207
00213 public function changename()
00214 {
00215 $soxId = $this->getEditObjectId();
00216 $aParams = oxConfig::getParameter( "editval");
00217
00218
00219
00220 $aParams['oxarticles__oxshopid'] = oxSession::getVar( "actshop" );
00221
00222 $oArticle = oxNew( "oxarticle" );
00223 if ( $soxId != "-1") {
00224 $oArticle->loadInLang( $this->_iEditLang, $soxId );
00225 }
00226
00227 $oArticle->setLanguage( 0 );
00228 $oArticle->assign( $aParams);
00229 $oArticle->setLanguage( $this->_iEditLang );
00230 $oArticle->save();
00231 }
00232
00233
00239 public function addsel()
00240 {
00241 $oArticle = oxNew("oxarticle");
00242
00243
00244 if ( $oArticle->load( $this->getEditObjectId() ) ) {
00245
00246
00247
00248 if ( $aSels = oxConfig::getParameter( "allsel" ) ) {
00249 $oVariantHandler = oxNew( "oxVariantHandler" );
00250 $oVariantHandler->genVariantFromSell( $aSels, $oArticle );
00251 }
00252 }
00253 }
00254 }