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
00029 $oArticle->loadInLang( $this->_iEditLang, $soxId );
00030
00031
00032 $oOtherLang = $oArticle->getAvailableInLangs();
00033 if (!isset($oOtherLang[$this->_iEditLang])) {
00034
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
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
00087 if ( !isset( $aParams['oxarticles__oxremindactive'])) {
00088 $aParams['oxarticles__oxremindactive'] = 0;
00089 }
00090
00091
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
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
00120 public function addprice( $sOXID = null, $aUpdateParams = null )
00121 {
00122 $myConfig = $this->getConfig();
00123
00124
00125 $sOxArtId = $this->getEditObjectId();
00126
00127 $aParams = oxConfig::getParameter( "editval" );
00128
00129 if ( !is_array($aParams) ) {
00130 return;
00131 }
00132
00133 if ( isset( $aUpdateParams ) && is_array( $aUpdateParams ) ) {
00134 $aParams = array_merge( $aParams, $aUpdateParams );
00135 }
00136
00137
00138 foreach ( $aParams as $key => $sParam ) {
00139 $aParams[$key] = str_replace( ",", ".", $sParam );
00140 }
00141
00142 $sShopID = $myConfig->getShopID();
00143 $aParams['oxprice2article__oxshopid'] = $sShopID;
00144
00145 if ( isset( $sOXID ) ) {
00146 $aParams['oxprice2article__oxid'] = $sOXID;
00147 }
00148
00149 $aParams['oxprice2article__oxartid'] = $sOxArtId;
00150 if ( !isset( $aParams['oxprice2article__oxamount'] ) || !$aParams['oxprice2article__oxamount'] ) {
00151 $aParams['oxprice2article__oxamount'] = "1";
00152 }
00153
00154 if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
00155 $aParams['oxprice2article__oxamount'] = round( ( string ) $aParams['oxprice2article__oxamount'] );
00156 $aParams['oxprice2article__oxamountto'] = round( ( string ) $aParams['oxprice2article__oxamountto'] );
00157 }
00158
00159 $dPrice = $aParams['price'];
00160 $sType = $aParams['pricetype'];
00161
00162 $oArticlePrice = oxNew( "oxbase" );
00163 $oArticlePrice->init( "oxprice2article" );
00164 $oArticlePrice->assign( $aParams );
00165
00166 $oArticlePrice->$sType = new oxField( $dPrice );
00167
00168
00169
00170 if ($oArticlePrice->$sType->value &&
00171 $oArticlePrice->oxprice2article__oxamount->value &&
00172 $oArticlePrice->oxprice2article__oxamountto->value &&
00173 is_numeric( $oArticlePrice->$sType->value ) &&
00174 is_numeric( $oArticlePrice->oxprice2article__oxamount->value ) &&
00175 is_numeric( $oArticlePrice->oxprice2article__oxamountto->value ) &&
00176 $oArticlePrice->oxprice2article__oxamount->value <= $oArticlePrice->oxprice2article__oxamountto->value
00177 ) {
00178 $oArticlePrice->save();
00179 }
00180
00181 }
00182
00188 public function updateprices()
00189 {
00190 $aParams = oxConfig::getParameter( "updateval" );
00191 if ( is_array( $aParams ) ) {
00192 foreach ( $aParams as $soxId => $aStockParams ) {
00193 $this->addprice( $soxId, $aStockParams );
00194 }
00195 }
00196 }
00197
00198
00199
00205 public function deleteprice()
00206 {
00207
00208 $oDb = oxDb::getDb();
00209 $sPriceId = $oDb->quote( oxConfig::getParameter("priceid" ) );
00210 $sId = $oDb->quote( $this->getEditObjectId() );
00211 $oDb->execute( "delete from oxprice2article where oxid = {$sPriceId} and oxartid = {$sId}" );
00212 }
00213
00214 }