article_stock.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Article_Stock extends oxAdminDetails
00010 {
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__oxremindactive'])) {
00080             $aParams['oxarticles__oxremindactive'] = 0;
00081         }
00082 
00083             // shopid
00084             $sShopID = oxSession::getVar( "actshop");
00085             $aParams['oxarticles__oxshopid'] = $sShopID;
00086 
00087         $oArticle = oxNew( "oxarticle");
00088         $oArticle->loadInLang( $this->_iEditLang, $soxId );
00089         $oArticle->setLanguage( 0 );
00090         $oArticle->assign( $aParams );
00091 
00092         //tells to article to save in different language
00093         $oArticle->setLanguage( $this->_iEditLang );
00094         $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00095 
00096         if ( $oArticle->oxarticles__oxremindactive->value &&
00097              $oArticle->oxarticles__oxremindamount->value <= $oArticle->oxarticles__oxstock->value ) {
00098             $oArticle->oxarticles__oxremindactive->value = 1;
00099         }
00100 
00101         $oArticle->save();
00102     }
00103 
00109     public function addprice()
00110     {
00111         $myConfig = $this->getConfig();
00112 
00113 
00114         $soxId   = oxConfig::getParameter( "oxid" );
00115         $aParams = oxConfig::getParameter( "editval" );
00116 
00117         //replacing commas
00118         foreach ( $aParams as $key => $sParam ) {
00119             $aParams[$key] = str_replace( ",", ".", $sParam );
00120         }
00121 
00122             $sShopID = $myConfig->getShopID();
00123             $aParams['oxprice2article__oxshopid'] = $sShopID;
00124 
00125         $aParams['oxprice2article__oxartid'] = $soxId;
00126         if ( !isset( $aParams['oxprice2article__oxamount'] ) || !$aParams['oxprice2article__oxamount'] ) {
00127             $aParams['oxprice2article__oxamount'] = "1";
00128         }
00129 
00130         if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
00131             $aParams['oxprice2article__oxamount']   = round( ( string ) $aParams['oxprice2article__oxamount'] );
00132             $aParams['oxprice2article__oxamountto'] = round( ( string ) $aParams['oxprice2article__oxamountto'] );
00133         }
00134 
00135         $dPrice = $aParams['price'];
00136         $sType = $aParams['pricetype'];
00137 
00138         $oArticlePrice = oxNew( "oxbase" );
00139         $oArticlePrice->init( "oxprice2article" );
00140         $oArticlePrice->assign( $aParams );
00141 
00142         $oArticlePrice->$sType = new oxField( $dPrice );
00143 
00144         //validating
00145 
00146         if ($oArticlePrice->$sType->value &&
00147             $oArticlePrice->oxprice2article__oxamount->value &&
00148             $oArticlePrice->oxprice2article__oxamountto->value &&
00149             is_numeric( $oArticlePrice->$sType->value ) &&
00150             is_numeric( $oArticlePrice->oxprice2article__oxamount->value ) &&
00151             is_numeric( $oArticlePrice->oxprice2article__oxamountto->value ) &&
00152             $oArticlePrice->oxprice2article__oxamount->value <= $oArticlePrice->oxprice2article__oxamountto->value
00153             ) {
00154             $oArticlePrice->save();
00155         }
00156 
00157     }
00158 
00164     public function deleteprice()
00165     {
00166 
00167         $oDb = oxDb::getDb();
00168         $sPriceId = $oDb->quote( oxConfig::getParameter("priceid" ) );
00169         $sId = $oDb->quote( oxConfig::getParameter( "oxid" ) );
00170         $oDb->execute( "delete from oxprice2article where oxid = {$sPriceId} and oxartid = {$sId}" );
00171     }
00172 
00173 }