article_variant.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class Article_Variant extends oxAdminDetails
00009 {
00010 
00016     protected $_oProductParent = null;
00017 
00024     public function render()
00025     {
00026         parent::render();
00027 
00028         $soxId = $this->getEditObjectId();
00029         $sSLViewName = getViewName('oxselectlist');
00030 
00031         // all selectlists
00032         $oAllSel = oxNew("oxlist");
00033         $oAllSel->init("oxselectlist");
00034         $sQ = "select * from $sSLViewName";
00035         $oAllSel->selectString($sQ);
00036         $this->_aViewData["allsel"] = $oAllSel;
00037 
00038         $oArticle = oxNew("oxarticle");
00039         $this->_aViewData["edit"] = $oArticle;
00040 
00041         if ($soxId != "-1" && isset($soxId)) {
00042             // load object
00043             $oArticle->loadInLang($this->_iEditLang, $soxId);
00044 
00045 
00046             $_POST["language"] = $_GET["language"] = $this->_iEditLang;
00047             $oVariants = $oArticle->getAdminVariants($this->_iEditLang);
00048 
00049             $this->_aViewData["mylist"] = $oVariants;
00050 
00051             // load object in other languages
00052             $oOtherLang = $oArticle->getAvailableInLangs();
00053             if (!isset($oOtherLang[$this->_iEditLang])) {
00054                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00055                 $oArticle->loadInLang(key($oOtherLang), $soxId);
00056             }
00057 
00058             foreach ($oOtherLang as $id => $language) {
00059                 $oLang = new stdClass();
00060                 $oLang->sLangDesc = $language;
00061                 $oLang->selected = ($id == $this->_iEditLang);
00062                 $this->_aViewData["otherlang"][$id] = clone $oLang;
00063             }
00064 
00065             if ($oArticle->oxarticles__oxparentid->value) {
00066                 $this->_aViewData["parentarticle"] = $this->_getProductParent($oArticle->oxarticles__oxparentid->value);
00067                 $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
00068                 $this->_aViewData["issubvariant"] = 1;
00069                 // A. disable variant information editing for variant
00070                 $this->_aViewData["readonly"] = 1;
00071             }
00072             $this->_aViewData["editlanguage"] = $this->_iEditLang;
00073 
00074             $aLang = array_diff(oxRegistry::getLang()->getLanguageNames(), $oOtherLang);
00075             if (count($aLang)) {
00076                 $this->_aViewData["posslang"] = $aLang;
00077             }
00078 
00079             foreach ($oOtherLang as $id => $language) {
00080                 $oLang = new stdClass();
00081                 $oLang->sLangDesc = $language;
00082                 $oLang->selected = ($id == $this->_iEditLang);
00083                 $this->_aViewData["otherlang"][$id] = $oLang;
00084             }
00085         }
00086 
00087         return "article_variant.tpl";
00088     }
00089 
00098     public function savevariant($sOXID = null, $aParams = null)
00099     {
00100         if (!isset($sOXID) && !isset($aParams)) {
00101             $sOXID = oxRegistry::getConfig()->getRequestParameter("voxid");
00102             $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
00103         }
00104 
00105         // shopid
00106         $aParams['oxarticles__oxshopid'] = oxRegistry::getSession()->getVariable("actshop");
00107 
00108         // varianthandling
00109         $soxparentId = $this->getEditObjectId();
00110         if (isset($soxparentId) && $soxparentId && $soxparentId != "-1") {
00111             $aParams['oxarticles__oxparentid'] = $soxparentId;
00112         } else {
00113             unset($aParams['oxarticles__oxparentid']);
00114         }
00116         $oArticle = oxNew("oxarticle");
00117 
00118         if ($sOXID != "-1") {
00119             $oArticle->loadInLang($this->_iEditLang, $sOXID);
00120         }
00121 
00122         if (!$this->_isAnythingChanged($oArticle, $aParams)) {
00123             return;
00124         }
00125 
00126         // checkbox handling
00127         if (!isset($aParams['oxarticles__oxactive'])) {
00128             $aParams['oxarticles__oxactive'] = 0;
00129         }
00130 
00131         $oArticle->setLanguage(0);
00132         $oArticle->assign($aParams);
00133         $oArticle->setLanguage($this->_iEditLang);
00134 
00135         // #0004473
00136         $oArticle->resetRemindStatus();
00137 
00138         if ($sOXID == "-1") {
00139             if ($oParent = $this->_getProductParent($oArticle->oxarticles__oxparentid->value)) {
00140 
00141                 // assign field from parent for new variant
00142                 // #4406
00143                 $oArticle->oxarticles__oxisconfigurable = new oxField($oParent->oxarticles__oxisconfigurable->value);
00144                 $oArticle->oxarticles__oxremindactive = new oxField($oParent->oxarticles__oxremindactive->value);
00145             }
00146         }
00147 
00148         $oArticle->save();
00149     }
00150 
00159     protected function _isAnythingChanged($oProduct, $aData)
00160     {
00161         if (!is_array($aData)) {
00162             return true;
00163         }
00164         foreach ($aData as $sKey => $sValue) {
00165             if (isset($oProduct->$sKey) && $oProduct->$sKey->value != $aData[$sKey]) {
00166                 return true;
00167             }
00168         }
00169 
00170         return false;
00171     }
00172 
00180     protected function _getProductParent($sParentId)
00181     {
00182         if ($this->_oProductParent === null ||
00183             ($this->_oProductParent !== false && $this->_oProductParent->getId() != $sParentId)
00184         ) {
00185             $this->_oProductParent = false;
00186             $oProduct = oxNew("oxarticle");
00187             if ($oProduct->load($sParentId)) {
00188                 $this->_oProductParent = $oProduct;
00189             }
00190         }
00191 
00192         return $this->_oProductParent;
00193     }
00194 
00198     public function savevariants()
00199     {
00200 
00201         $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
00202         if (is_array($aParams)) {
00203             foreach ($aParams as $soxId => $aVarParams) {
00204                 $this->savevariant($soxId, $aVarParams);
00205             }
00206         }
00207 
00208     }
00209 
00215     public function deleteVariant()
00216     {
00217 
00218 
00219         $soxId = oxRegistry::getConfig()->getRequestParameter("voxid");
00220         $oDelete = oxNew("oxarticle");
00221         $oDelete->delete($soxId);
00222     }
00223 
00227     public function changename()
00228     {
00229         $soxId = $this->getEditObjectId();
00230         $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
00231 
00232 
00233         // shopid
00234         $aParams['oxarticles__oxshopid'] = oxRegistry::getSession()->getVariable("actshop");
00235 
00236         $oArticle = oxNew("oxarticle");
00237         if ($soxId != "-1") {
00238             $oArticle->loadInLang($this->_iEditLang, $soxId);
00239         }
00240 
00241         $oArticle->setLanguage(0);
00242         $oArticle->assign($aParams);
00243         $oArticle->setLanguage($this->_iEditLang);
00244         $oArticle->save();
00245     }
00246 
00247 
00253     public function addsel()
00254     {
00255         $oArticle = oxNew("oxarticle");
00256         //#3644
00257         //$oArticle->setEnableMultilang( false );
00258         if ($oArticle->load($this->getEditObjectId())) {
00259 
00260 
00261 
00262             if ($aSels = oxRegistry::getConfig()->getRequestParameter("allsel")) {
00263                 $oVariantHandler = oxNew("oxVariantHandler");
00264                 $oVariantHandler->genVariantFromSell($aSels, $oArticle);
00265             }
00266         }
00267     }
00268 }