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             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 = oxUtilsFile::getInstance()->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 
00117     public function addprice()
00118     {
00119         $myConfig = $this->getConfig();
00120 
00121 
00122         $soxId = $this->getEditObjectId();
00123         $aParams = oxConfig::getParameter( "editval" );
00124 
00125         //replacing commas
00126         foreach ( $aParams as $key => $sParam ) {
00127             $aParams[$key] = str_replace( ",", ".", $sParam );
00128         }
00129 
00130             $sShopID = $myConfig->getShopID();
00131             $aParams['oxprice2article__oxshopid'] = $sShopID;
00132 
00133         $aParams['oxprice2article__oxartid'] = $soxId;
00134         if ( !isset( $aParams['oxprice2article__oxamount'] ) || !$aParams['oxprice2article__oxamount'] ) {
00135             $aParams['oxprice2article__oxamount'] = "1";
00136         }
00137 
00138         if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
00139             $aParams['oxprice2article__oxamount']   = round( ( string ) $aParams['oxprice2article__oxamount'] );
00140             $aParams['oxprice2article__oxamountto'] = round( ( string ) $aParams['oxprice2article__oxamountto'] );
00141         }
00142 
00143         $dPrice = $aParams['price'];
00144         $sType = $aParams['pricetype'];
00145 
00146         $oArticlePrice = oxNew( "oxbase" );
00147         $oArticlePrice->init( "oxprice2article" );
00148         $oArticlePrice->assign( $aParams );
00149 
00150         $oArticlePrice->$sType = new oxField( $dPrice );
00151 
00152         //validating
00153 
00154         if ($oArticlePrice->$sType->value &&
00155             $oArticlePrice->oxprice2article__oxamount->value &&
00156             $oArticlePrice->oxprice2article__oxamountto->value &&
00157             is_numeric( $oArticlePrice->$sType->value ) &&
00158             is_numeric( $oArticlePrice->oxprice2article__oxamount->value ) &&
00159             is_numeric( $oArticlePrice->oxprice2article__oxamountto->value ) &&
00160             $oArticlePrice->oxprice2article__oxamount->value <= $oArticlePrice->oxprice2article__oxamountto->value
00161             ) {
00162             $oArticlePrice->save();
00163         }
00164 
00165     }
00166 
00172     public function deleteprice()
00173     {
00174 
00175         $oDb = oxDb::getDb();
00176         $sPriceId = $oDb->quote( oxConfig::getParameter("priceid" ) );
00177         $sId = $oDb->quote( $this->getEditObjectId() );
00178         $oDb->execute( "delete from oxprice2article where oxid = {$sPriceId} and oxartid = {$sId}" );
00179     }
00180 
00181 }