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 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                 $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             $sShopID = $myConfig->getShopID();
00056             $oPriceList = oxNew("oxlist");
00057             $oPriceList->init( 'oxbase', "oxprice2article" );
00058             $sQ = "select * from oxprice2article where oxartid = '$soxId' and oxshopid = '$sShopID' and (oxamount > 0 or oxamountto > 0) order by oxamount ";
00059             $oPriceList->selectstring( $sQ );
00060 
00061             $this->_aViewData["amountprices"] = $oPriceList;
00062 
00063         }
00064 
00065         return "article_stock.tpl";
00066     }
00067 
00073     public function save()
00074     {
00075 
00076         $soxId = $this->getEditObjectId();
00077         $aParams = oxConfig::getParameter( "editval");
00078 
00079         // checkbox handling
00080         if ( !isset( $aParams['oxarticles__oxremindactive'])) {
00081             $aParams['oxarticles__oxremindactive'] = 0;
00082         }
00083 
00084             // shopid
00085             $sShopID = oxSession::getVar( "actshop");
00086             $aParams['oxarticles__oxshopid'] = $sShopID;
00087 
00088         $oArticle = oxNew( "oxarticle");
00089         $oArticle->loadInLang( $this->_iEditLang, $soxId );
00090         $oArticle->setLanguage( 0 );
00091         $oArticle->assign( $aParams );
00092 
00093         //tells to article to save in different language
00094         $oArticle->setLanguage( $this->_iEditLang );
00095         $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00096 
00097         if ( $oArticle->oxarticles__oxremindactive->value &&
00098              $oArticle->oxarticles__oxremindamount->value <= $oArticle->oxarticles__oxstock->value ) {
00099             $oArticle->oxarticles__oxremindactive->value = 1;
00100         }
00101 
00102         $oArticle->save();
00103     }
00104 
00110     public function addprice()
00111     {
00112         $myConfig = $this->getConfig();
00113 
00114 
00115         $soxId = $this->getEditObjectId();
00116         $aParams = oxConfig::getParameter( "editval" );
00117 
00118         //replacing commas
00119         foreach ( $aParams as $key => $sParam ) {
00120             $aParams[$key] = str_replace( ",", ".", $sParam );
00121         }
00122 
00123             $sShopID = $myConfig->getShopID();
00124             $aParams['oxprice2article__oxshopid'] = $sShopID;
00125 
00126         $aParams['oxprice2article__oxartid'] = $soxId;
00127         if ( !isset( $aParams['oxprice2article__oxamount'] ) || !$aParams['oxprice2article__oxamount'] ) {
00128             $aParams['oxprice2article__oxamount'] = "1";
00129         }
00130 
00131         if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
00132             $aParams['oxprice2article__oxamount']   = round( ( string ) $aParams['oxprice2article__oxamount'] );
00133             $aParams['oxprice2article__oxamountto'] = round( ( string ) $aParams['oxprice2article__oxamountto'] );
00134         }
00135 
00136         $dPrice = $aParams['price'];
00137         $sType = $aParams['pricetype'];
00138 
00139         $oArticlePrice = oxNew( "oxbase" );
00140         $oArticlePrice->init( "oxprice2article" );
00141         $oArticlePrice->assign( $aParams );
00142 
00143         $oArticlePrice->$sType = new oxField( $dPrice );
00144 
00145         //validating
00146 
00147         if ($oArticlePrice->$sType->value &&
00148             $oArticlePrice->oxprice2article__oxamount->value &&
00149             $oArticlePrice->oxprice2article__oxamountto->value &&
00150             is_numeric( $oArticlePrice->$sType->value ) &&
00151             is_numeric( $oArticlePrice->oxprice2article__oxamount->value ) &&
00152             is_numeric( $oArticlePrice->oxprice2article__oxamountto->value ) &&
00153             $oArticlePrice->oxprice2article__oxamount->value <= $oArticlePrice->oxprice2article__oxamountto->value
00154             ) {
00155             $oArticlePrice->save();
00156         }
00157 
00158     }
00159 
00165     public function deleteprice()
00166     {
00167 
00168         $oDb = oxDb::getDb();
00169         $sPriceId = $oDb->quote( oxConfig::getParameter("priceid" ) );
00170         $sId = $oDb->quote( $this->getEditObjectId() );
00171         $oDb->execute( "delete from oxprice2article where oxid = {$sPriceId} and oxartid = {$sId}" );
00172     }
00173 
00174 }