article_stock.php

Go to the documentation of this file.
00001 <?php
00002 
00010 class Article_Stock extends oxAdminDetails
00011 {
00017     public function render()
00018     {
00019         $myConfig = $this->getConfig();
00020 
00021         parent::render();
00022 
00023         $this->_aViewData["edit"] = $oArticle = oxNew( "oxarticle");
00024 
00025         $soxId = oxConfig::getParameter( "oxid");
00026         if ( $soxId != "-1" && isset( $soxId)) {
00027 
00028             // load object
00029             $oArticle->loadInLang( $this->_iEditLang, $soxId );
00030 
00031             // load object in other languages
00032             $oOtherLang = $oArticle->getAvailableInLangs();
00033             if (!isset($oOtherLang[$this->_iEditLang])) {
00034                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00035                 $oArticle->loadInLang( key($oOtherLang), $soxId );
00036             }
00037 
00038             foreach ( $oOtherLang as $id => $language) {
00039                 $oLang= new oxStdClass();
00040                 $oLang->sLangDesc = $language;
00041                 $oLang->selected = ($id == $this->_iEditLang);
00042                 $this->_aViewData["otherlang"][$id] =  clone $oLang;
00043             }
00044 
00045 
00046             // variant handling
00047             if ( $oArticle->oxarticles__oxparentid->value) {
00048                 $oParentArticle = oxNew( "oxarticle");
00049                 $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
00050                 $this->_aViewData["parentarticle"] =  $oParentArticle;
00051                 $this->_aViewData["oxparentid"] =  $oArticle->oxarticles__oxparentid->value;
00052             }
00053 
00054             $sShopID = $myConfig->getShopID();
00055             $oPriceList = oxNew("oxlist");
00056             $oPriceList->init( 'oxbase', "oxprice2article" );
00057             $sQ = "select * from oxprice2article where oxartid = '$soxId' and oxshopid = '$sShopID' and (oxamount > 0 or oxamountto > 0) order by oxamount ";
00058             $oPriceList->selectstring( $sQ );
00059 
00060             $this->_aViewData["amountprices"] = $oPriceList;
00061 
00062         }
00063 
00064         return "article_stock.tpl";
00065     }
00066 
00072     public function save()
00073     {
00074 
00075         $soxId      = oxConfig::getParameter( "oxid");
00076         $aParams    = oxConfig::getParameter( "editval");
00077 
00078         // checkbox handling
00079         if ( !isset( $aParams['oxarticles__oxremindactiv']))
00080             $aParams['oxarticles__oxremindactiv'] = 0;
00081 
00082         /*
00083         */
00084             //if( !$myConfig->getConfigParam( 'blAllowUnevenAmounts') && isset($aParams['oxarticles__oxstock']))
00085             //    $aParams['oxarticles__oxstock'] = round((string)$aParams['oxarticles__oxstock']);
00086 
00087             // shopid
00088             $sShopID = oxSession::getVar( "actshop");
00089             $aParams['oxarticles__oxshopid'] = $sShopID;
00090 
00091         $oArticle = oxNew( "oxarticle");
00092         $oArticle->loadInLang( $this->_iEditLang, $soxId );
00093         //$aParams = $oArticle->ConvertNameArray2Idx( $aParams);
00094         $oArticle->setLanguage(0);
00095         $oArticle->assign( $aParams);
00096         //tells to article to load in different language
00097         $oArticle->setLanguage($this->_iEditLang);
00098         $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00099 
00100         if ( $oArticle->oxarticles__oxremindactiv->value &&
00101              $oArticle->oxarticles__oxremindamount->value <= $oArticle->oxarticles__oxstock->value )
00102             $oArticle->oxarticles__oxremindactiv->value = 1;
00103 
00104         $oArticle->save();
00105 
00106         return $this->autosave();
00107     }
00108 
00109 
00115     public function savemallstuff()
00116     {
00117         $soxId      = oxConfig::getParameter( "oxid");
00118         $aParams    = oxConfig::getParameter( "mall");
00119         $sShopID    = oxSession::getVar( "actshop");
00120 
00121         $oDB = oxDb::getDb();
00122         $sID = $oDB->getOne( "select oxid from oxprice2article where oxartid = '$soxId' and oxshopid = '$sShopID'");
00123 
00124         $oNew = oxNew( "oxbase");
00125         $oNew->init( "oxprice2article" );
00126         if ( isset( $sID) && $sID)
00127             $oNew->load( $sID);
00128         else {
00129             $oNew->oxprice2article__oxshopid->setValue($sShopID);
00130             $oNew->oxprice2article__oxartid->setValue($soxId);
00131         }
00132         $oNew->oxprice2article__oxaddabs->setValue($aParams['oxprice2article__oxaddabs']);
00133         $oNew->oxprice2article__oxaddperc->setValue($aParams['oxprice2article__oxaddperc']);
00134         $oNew->save();
00135     }
00136 
00142     public function assignShop()
00143     {
00144         $aAddShop = oxConfig::getParameter( "allshop");
00145         $soxId    = oxConfig::getParameter( "oxid");
00146 
00147         if (is_array($aAddShop))
00148             foreach ($aAddShop as $sShopID) {
00149                 $oNew = oxNew( "oxbase");
00150                 $oNew->init( "oxarticle2shop" );
00151                 $oNew->oxarticle2shop__oxshopid = new oxField($sShopID);
00152                 $oNew->oxarticle2shop__oxartid = new oxField($soxId);
00153                 $oNew->save();
00154             }
00155     }
00156 
00162     public function removeShop()
00163     {
00164         $aRemShop = oxConfig::getParameter( "assignedshop");
00165         $soxId    = oxConfig::getParameter( "oxid");
00166 
00167         if (is_array($aRemShop))
00168             foreach ( $aRemShop as $sArtId) {
00169                 $oNew = oxNew( "oxbase" );
00170                 $oNew->init( "oxarticle2shop" );
00171                 $oNew->delete($sArtId);
00172             }
00173     }
00174 
00180     public function addprice()
00181     {
00182         $myConfig = $this->getConfig();
00183 
00184 
00185         $soxId   = oxConfig::getParameter( "oxid");
00186         $aParams = oxConfig::getParameter( "editval");
00187 
00188         //replacing commas
00189         foreach ($aParams as $key => $sParam)
00190             $aParams[$key] = str_replace(",", ".", $sParam);
00191 
00192             $sShopID = $myConfig->getShopID();
00193             $aParams['oxprice2article__oxshopid'] = $sShopID;
00194 
00195         $aParams['oxprice2article__oxartid'] = $soxId;
00196         if (!isset($aParams['oxprice2article__oxamount']) || !$aParams['oxprice2article__oxamount'])
00197             $aParams['oxprice2article__oxamount'] = "1";
00198 
00199         if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
00200             $aParams['oxprice2article__oxamount']   = round((string) $aParams['oxprice2article__oxamount']);
00201             $aParams['oxprice2article__oxamountto'] = round((string) $aParams['oxprice2article__oxamountto']);
00202         }
00203         $dPrice = $aParams['price'];
00204         $sType = $aParams['pricetype'];
00205 
00206         $oArticlePrice = oxNew( "oxbase" );
00207         $oArticlePrice->init( "oxprice2article" );
00208         $oArticlePrice->assign($aParams);
00209 
00210         $oArticlePrice->$sType = new oxField($dPrice);
00211 
00212         //validating
00213 
00214         if ($oArticlePrice->$sType->value &&
00215             $oArticlePrice->oxprice2article__oxamount->value &&
00216             $oArticlePrice->oxprice2article__oxamountto->value &&
00217             is_numeric($oArticlePrice->$sType->value) &&
00218             is_numeric($oArticlePrice->oxprice2article__oxamount->value) &&
00219             is_numeric($oArticlePrice->oxprice2article__oxamountto->value) &&
00220             $oArticlePrice->oxprice2article__oxamount->value <= $oArticlePrice->oxprice2article__oxamountto->value
00221             ) {
00222                 $oArticlePrice->save();
00223         }
00224 
00225     }
00226 
00232     public function deleteprice()
00233     {
00234 
00235         $sPriceID = oxConfig::getParameter("priceid");
00236         $sOXID = oxConfig::getParameter("oxid");
00237         $sQ = "delete from oxprice2article where oxid = '$sPriceID' and oxartid = '$sOXID'";
00238         oxDb::getDb()->Execute($sQ);
00239     }
00240 
00241 }

Generated on Thu Dec 4 12:04:55 2008 for OXID eShop CE by  doxygen 1.5.5