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 = $this->getEditObjectId();
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 stdClass();
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                 $oArticle->oxarticles__oxremindactive = new oxField( $oParentArticle->oxarticles__oxremindactive->value );
00051                 $this->_aViewData["parentarticle"] =  $oParentArticle;
00052                 $this->_aViewData["oxparentid"] =  $oArticle->oxarticles__oxparentid->value;
00053             }
00054 
00055             if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
00056                 $sShopSelect = '1';
00057             } else {
00058                 $sShopID = $myConfig->getShopID();
00059                 $sShopSelect = " oxshopid =  '$sShopID' ";
00060             }
00061 
00062             $oPriceList = oxNew("oxlist");
00063             $oPriceList->init( 'oxbase', "oxprice2article" );
00064             $sQ = "select * from oxprice2article where oxartid = '$soxId' and {$sShopSelect} and (oxamount > 0 or oxamountto > 0) order by oxamount ";
00065             $oPriceList->selectstring( $sQ );
00066 
00067             $this->_aViewData["amountprices"] = $oPriceList;
00068 
00069         }
00070 
00071         return "article_stock.tpl";
00072     }
00073 
00079     public function save()
00080     {
00081         parent::save();
00082 
00083         $soxId = $this->getEditObjectId();
00084         $aParams = oxConfig::getParameter( "editval");
00085 
00086         // checkbox handling
00087         if ( !isset( $aParams['oxarticles__oxremindactive'])) {
00088             $aParams['oxarticles__oxremindactive'] = 0;
00089         }
00090 
00091             // shopid
00092             $sShopID = oxSession::getVar( "actshop");
00093             $aParams['oxarticles__oxshopid'] = $sShopID;
00094 
00095         $oArticle = oxNew( "oxarticle");
00096         $oArticle->loadInLang( $this->_iEditLang, $soxId );
00097         $oArticle->setLanguage( 0 );
00098         $oArticle->assign( $aParams );
00099 
00100         //tells to article to save in different language
00101         $oArticle->setLanguage( $this->_iEditLang );
00102         $oArticle = oxRegistry::get("oxUtilsFile")->processFiles( $oArticle );
00103 
00104         if ( $oArticle->oxarticles__oxremindactive->value &&
00105              $oArticle->oxarticles__oxremindamount->value <= $oArticle->oxarticles__oxstock->value ) {
00106             $oArticle->oxarticles__oxremindactive->value = 1;
00107         }
00108 
00109         $oArticle->save();
00110     }
00111 
00120     public function addprice( $sOXID = null, $aUpdateParams = null )
00121     {
00122         $myConfig = $this->getConfig();
00123 
00124 
00125         $sOxArtId = $this->getEditObjectId();
00126 
00127 
00128 
00129         $aParams = oxConfig::getParameter( "editval" );
00130 
00131         if ( !is_array($aParams) ) {
00132             return;
00133         }
00134 
00135         if ( isset( $aUpdateParams ) && is_array( $aUpdateParams ) ) {
00136             $aParams = array_merge( $aParams, $aUpdateParams );
00137         }
00138 
00139         //replacing commas
00140         foreach ( $aParams as $key => $sParam ) {
00141             $aParams[$key] = str_replace( ",", ".", $sParam );
00142         }
00143 
00144         $aParams['oxprice2article__oxshopid'] = $myConfig->getShopID();
00145 
00146         if ( isset( $sOXID ) ) {
00147             $aParams['oxprice2article__oxid'] = $sOXID;
00148         }
00149 
00150         $aParams['oxprice2article__oxartid'] = $sOxArtId;
00151         if ( !isset( $aParams['oxprice2article__oxamount'] ) || !$aParams['oxprice2article__oxamount'] ) {
00152             $aParams['oxprice2article__oxamount'] = "1";
00153         }
00154 
00155         if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
00156             $aParams['oxprice2article__oxamount']   = round( ( string ) $aParams['oxprice2article__oxamount'] );
00157             $aParams['oxprice2article__oxamountto'] = round( ( string ) $aParams['oxprice2article__oxamountto'] );
00158         }
00159 
00160         $dPrice = $aParams['price'];
00161         $sType = $aParams['pricetype'];
00162 
00163         $oArticlePrice = oxNew( "oxbase" );
00164         $oArticlePrice->init( "oxprice2article" );
00165         $oArticlePrice->assign( $aParams );
00166 
00167         $oArticlePrice->$sType = new oxField( $dPrice );
00168 
00169         //validating
00170 
00171         if ($oArticlePrice->$sType->value &&
00172             $oArticlePrice->oxprice2article__oxamount->value &&
00173             $oArticlePrice->oxprice2article__oxamountto->value &&
00174             is_numeric( $oArticlePrice->$sType->value ) &&
00175             is_numeric( $oArticlePrice->oxprice2article__oxamount->value ) &&
00176             is_numeric( $oArticlePrice->oxprice2article__oxamountto->value ) &&
00177             $oArticlePrice->oxprice2article__oxamount->value <= $oArticlePrice->oxprice2article__oxamountto->value
00178             ) {
00179             $oArticlePrice->save();
00180         }
00181 
00182     }
00183 
00189     public function updateprices()
00190     {
00191 
00192         $aParams = oxConfig::getParameter( "updateval" );
00193         if ( is_array( $aParams ) ) {
00194             foreach ( $aParams as $soxId => $aStockParams ) {
00195                 $this->addprice( $soxId, $aStockParams );
00196             }
00197         }
00198     }
00199 
00200 
00201 
00207     public function deleteprice()
00208     {
00209 
00210         $oDb = oxDb::getDb();
00211         $sPriceId = $oDb->quote( oxConfig::getParameter("priceid" ) );
00212         $sId = $oDb->quote( $this->getEditObjectId() );
00213         $oDb->execute( "delete from oxprice2article where oxid = {$sPriceId} and oxartid = {$sId}" );
00214     }
00215 
00216 }