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         // checkbox handling
00123         if (is_array($aParams) && !isset($aParams['oxarticles__oxactive'])) {
00124             $aParams['oxarticles__oxactive'] = 0;
00125         }
00126 
00127         if (!$this->_isAnythingChanged($oArticle, $aParams)) {
00128             return;
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         $this->resetContentCache();
00209     }
00210 
00216     public function deleteVariant()
00217     {
00218 
00219         $this->resetContentCache();
00220 
00221         $soxId = oxRegistry::getConfig()->getRequestParameter("voxid");
00222         $oDelete = oxNew("oxarticle");
00223         $oDelete->delete($soxId);
00224     }
00225 
00229     public function changename()
00230     {
00231         $soxId = $this->getEditObjectId();
00232         $aParams = oxRegistry::getConfig()->getRequestParameter("editval");
00233 
00234         $this->resetContentCache();
00235 
00236         // shopid
00237         $aParams['oxarticles__oxshopid'] = oxRegistry::getSession()->getVariable("actshop");
00238 
00239         $oArticle = oxNew("oxarticle");
00240         if ($soxId != "-1") {
00241             $oArticle->loadInLang($this->_iEditLang, $soxId);
00242         }
00243 
00244         $oArticle->setLanguage(0);
00245         $oArticle->assign($aParams);
00246         $oArticle->setLanguage($this->_iEditLang);
00247         $oArticle->save();
00248     }
00249 
00250 
00256     public function addsel()
00257     {
00258         $oArticle = oxNew("oxarticle");
00259         //#3644
00260         //$oArticle->setEnableMultilang( false );
00261         if ($oArticle->load($this->getEditObjectId())) {
00262 
00263 
00264             $this->resetContentCache();
00265 
00266             if ($aSels = oxRegistry::getConfig()->getRequestParameter("allsel")) {
00267                 $oVariantHandler = oxNew("oxVariantHandler");
00268                 $oVariantHandler->genVariantFromSell($aSels, $oArticle);
00269             }
00270         }
00271     }
00272 }