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 stdClass();
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 $this->_aViewData["parentarticle"] = $oParentArticle;
00051 $this->_aViewData["oxparentid"] = $oArticle->oxarticles__oxparentid->value;
00052 }
00053
00054 if ( $myConfig->getConfigParam( 'blMallInterchangeArticles' ) ) {
00055 $sShopSelect = '1';
00056 } else {
00057 $sShopID = $myConfig->getShopID();
00058 $sShopSelect = " oxshopid = '$sShopID' ";
00059 }
00060
00061 $oPriceList = oxNew("oxlist");
00062 $oPriceList->init( 'oxbase', "oxprice2article" );
00063 $sQ = "select * from oxprice2article where oxartid = '$soxId' and {$sShopSelect} and (oxamount > 0 or oxamountto > 0) order by oxamount ";
00064 $oPriceList->selectstring( $sQ );
00065
00066 $this->_aViewData["amountprices"] = $oPriceList;
00067
00068 }
00069
00070 return "article_stock.tpl";
00071 }
00072
00078 public function save()
00079 {
00080 parent::save();
00081
00082 $soxId = $this->getEditObjectId();
00083 $aParams = oxConfig::getParameter( "editval");
00084
00085
00086 if ( !isset( $aParams['oxarticles__oxremindactive'])) {
00087 $aParams['oxarticles__oxremindactive'] = 0;
00088 }
00089
00090
00091 $sShopID = oxSession::getVar( "actshop");
00092 $aParams['oxarticles__oxshopid'] = $sShopID;
00093
00094 $oArticle = oxNew( "oxarticle");
00095 $oArticle->loadInLang( $this->_iEditLang, $soxId );
00096
00097 $oArticle->setLanguage( 0 );
00098 $oArticle->assign( $aParams );
00099
00100
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 $oArticle->updateVariantsRemind();
00109
00110 $oArticle->save();
00111 }
00112
00121 public function addprice( $sOXID = null, $aUpdateParams = null )
00122 {
00123 $myConfig = $this->getConfig();
00124
00125
00126 $sOxArtId = $this->getEditObjectId();
00127
00128
00129
00130 $aParams = oxConfig::getParameter( "editval" );
00131
00132 if ( !is_array($aParams) ) {
00133 return;
00134 }
00135
00136 if ( isset( $aUpdateParams ) && is_array( $aUpdateParams ) ) {
00137 $aParams = array_merge( $aParams, $aUpdateParams );
00138 }
00139
00140
00141 foreach ( $aParams as $key => $sParam ) {
00142 $aParams[$key] = str_replace( ",", ".", $sParam );
00143 }
00144
00145 $aParams['oxprice2article__oxshopid'] = $myConfig->getShopID();
00146
00147 if ( isset( $sOXID ) ) {
00148 $aParams['oxprice2article__oxid'] = $sOXID;
00149 }
00150
00151 $aParams['oxprice2article__oxartid'] = $sOxArtId;
00152 if ( !isset( $aParams['oxprice2article__oxamount'] ) || !$aParams['oxprice2article__oxamount'] ) {
00153 $aParams['oxprice2article__oxamount'] = "1";
00154 }
00155
00156 if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
00157 $aParams['oxprice2article__oxamount'] = round( ( string ) $aParams['oxprice2article__oxamount'] );
00158 $aParams['oxprice2article__oxamountto'] = round( ( string ) $aParams['oxprice2article__oxamountto'] );
00159 }
00160
00161 $dPrice = $aParams['price'];
00162 $sType = $aParams['pricetype'];
00163
00164 $oArticlePrice = oxNew( "oxbase" );
00165 $oArticlePrice->init( "oxprice2article" );
00166 $oArticlePrice->assign( $aParams );
00167
00168 $oArticlePrice->$sType = new oxField( $dPrice );
00169
00170
00171
00172 if ($oArticlePrice->$sType->value &&
00173 $oArticlePrice->oxprice2article__oxamount->value &&
00174 $oArticlePrice->oxprice2article__oxamountto->value &&
00175 is_numeric( $oArticlePrice->$sType->value ) &&
00176 is_numeric( $oArticlePrice->oxprice2article__oxamount->value ) &&
00177 is_numeric( $oArticlePrice->oxprice2article__oxamountto->value ) &&
00178 $oArticlePrice->oxprice2article__oxamount->value <= $oArticlePrice->oxprice2article__oxamountto->value
00179 ) {
00180 $oArticlePrice->save();
00181 }
00182
00183
00184 $oArticle = oxNew( "oxarticle");
00185 $oArticle->loadInLang( $this->_iEditLang, $sOxArtId );
00186 if ( $aParams['price'] >= $oArticle->oxarticles__oxprice->value) {
00187 if ( is_null($sOXID) ) {
00188 $sOXID = $oArticlePrice->getId();
00189 }
00190 $this->_aViewData["errorscaleprice"][] = $sOXID;
00191 }
00192
00193 }
00194
00200 public function updateprices()
00201 {
00202
00203 $aParams = oxConfig::getParameter( "updateval" );
00204 if ( is_array( $aParams ) ) {
00205 foreach ( $aParams as $soxId => $aStockParams ) {
00206 $this->addprice( $soxId, $aStockParams );
00207 }
00208 }
00209 }
00210
00211
00212
00218 public function deleteprice()
00219 {
00220
00221 $oDb = oxDb::getDb();
00222 $sPriceId = $oDb->quote( oxConfig::getParameter("priceid" ) );
00223 $sId = $oDb->quote( $this->getEditObjectId() );
00224 $oDb->execute( "delete from oxprice2article where oxid = {$sPriceId} and oxartid = {$sId}" );
00225 }
00226
00227 }