article_stock.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Article_Stock extends oxAdminDetails
00010 {
00016     public function render()
00017     {
00018         $myConfig = $this->getConfig();
00019 
00020         parent::render();
00021 
00022         $this->_aViewData["edit"] = $oArticle = oxNew( "oxarticle");
00023 
00024         $soxId = oxConfig::getParameter( "oxid");
00025         if ( $soxId != "-1" && isset( $soxId)) {
00026 
00027             // load object
00028             $oArticle->loadInLang( $this->_iEditLang, $soxId );
00029 
00030             // load object in other languages
00031             $oOtherLang = $oArticle->getAvailableInLangs();
00032             if (!isset($oOtherLang[$this->_iEditLang])) {
00033                 // echo "language entry doesn't exist! using: ".key($oOtherLang);
00034                 $oArticle->loadInLang( key($oOtherLang), $soxId );
00035             }
00036 
00037             foreach ( $oOtherLang as $id => $language) {
00038                 $oLang= new oxStdClass();
00039                 $oLang->sLangDesc = $language;
00040                 $oLang->selected = ($id == $this->_iEditLang);
00041                 $this->_aViewData["otherlang"][$id] =  clone $oLang;
00042             }
00043 
00044 
00045             // variant handling
00046             if ( $oArticle->oxarticles__oxparentid->value) {
00047                 $oParentArticle = oxNew( "oxarticle");
00048                 $oParentArticle->load( $oArticle->oxarticles__oxparentid->value);
00049                 $this->_aViewData["parentarticle"] =  $oParentArticle;
00050                 $this->_aViewData["oxparentid"] =  $oArticle->oxarticles__oxparentid->value;
00051             }
00052 
00053             $sShopID = $myConfig->getShopID();
00054             $oPriceList = oxNew("oxlist");
00055             $oPriceList->init( 'oxbase', "oxprice2article" );
00056             $sQ = "select * from oxprice2article where oxartid = '$soxId' and oxshopid = '$sShopID' and (oxamount > 0 or oxamountto > 0) order by oxamount ";
00057             $oPriceList->selectstring( $sQ );
00058 
00059             $this->_aViewData["amountprices"] = $oPriceList;
00060 
00061         }
00062 
00063         return "article_stock.tpl";
00064     }
00065 
00071     public function save()
00072     {
00073 
00074         $soxId      = oxConfig::getParameter( "oxid");
00075         $aParams    = oxConfig::getParameter( "editval");
00076 
00077         // checkbox handling
00078         if ( !isset( $aParams['oxarticles__oxremindactive']))
00079             $aParams['oxarticles__oxremindactive'] = 0;
00080 
00081         /*
00082         */
00083             //if( !$myConfig->getConfigParam( 'blAllowUnevenAmounts') && isset($aParams['oxarticles__oxstock']))
00084             //    $aParams['oxarticles__oxstock'] = round((string)$aParams['oxarticles__oxstock']);
00085 
00086             // shopid
00087             $sShopID = oxSession::getVar( "actshop");
00088             $aParams['oxarticles__oxshopid'] = $sShopID;
00089 
00090         $oArticle = oxNew( "oxarticle");
00091         $oArticle->loadInLang( $this->_iEditLang, $soxId );
00092         //$aParams = $oArticle->ConvertNameArray2Idx( $aParams);
00093         $oArticle->setLanguage(0);
00094         $oArticle->assign( $aParams);
00095         //tells to article to load in different language
00096         $oArticle->setLanguage($this->_iEditLang);
00097         $oArticle = oxUtilsFile::getInstance()->processFiles( $oArticle );
00098 
00099         if ( $oArticle->oxarticles__oxremindactive->value &&
00100              $oArticle->oxarticles__oxremindamount->value <= $oArticle->oxarticles__oxstock->value )
00101             $oArticle->oxarticles__oxremindactive->value = 1;
00102 
00103         $oArticle->save();
00104     }
00105 
00106 
00112     public function savemallstuff()
00113     {
00114         $soxId      = oxConfig::getParameter( "oxid");
00115         $aParams    = oxConfig::getParameter( "mall");
00116         $sShopID    = oxSession::getVar( "actshop");
00117 
00118         $oDB = oxDb::getDb();
00119         $sID = $oDB->getOne( "select oxid from oxprice2article where oxartid = '$soxId' and oxshopid = '$sShopID'");
00120 
00121         $oNew = oxNew( "oxbase");
00122         $oNew->init( "oxprice2article" );
00123         if ( isset( $sID) && $sID)
00124             $oNew->load( $sID);
00125         else {
00126             $oNew->oxprice2article__oxshopid->setValue($sShopID);
00127             $oNew->oxprice2article__oxartid->setValue($soxId);
00128         }
00129         $oNew->oxprice2article__oxaddabs->setValue($aParams['oxprice2article__oxaddabs']);
00130         $oNew->oxprice2article__oxaddperc->setValue($aParams['oxprice2article__oxaddperc']);
00131         $oNew->save();
00132     }
00133 
00139     public function assignShop()
00140     {
00141         $aAddShop = oxConfig::getParameter( "allshop");
00142         $soxId    = oxConfig::getParameter( "oxid");
00143 
00144         if (is_array($aAddShop))
00145             foreach ($aAddShop as $sShopID) {
00146                 $oNew = oxNew( "oxbase");
00147                 $oNew->init( "oxarticle2shop" );
00148                 $oNew->oxarticle2shop__oxshopid = new oxField($sShopID);
00149                 $oNew->oxarticle2shop__oxartid = new oxField($soxId);
00150                 $oNew->save();
00151             }
00152     }
00153 
00159     public function removeShop()
00160     {
00161         $aRemShop = oxConfig::getParameter( "assignedshop");
00162         $soxId    = oxConfig::getParameter( "oxid");
00163 
00164         if (is_array($aRemShop))
00165             foreach ( $aRemShop as $sArtId) {
00166                 $oNew = oxNew( "oxbase" );
00167                 $oNew->init( "oxarticle2shop" );
00168                 $oNew->delete($sArtId);
00169             }
00170     }
00171 
00177     public function addprice()
00178     {
00179         $myConfig = $this->getConfig();
00180 
00181 
00182         $soxId   = oxConfig::getParameter( "oxid");
00183         $aParams = oxConfig::getParameter( "editval");
00184 
00185         //replacing commas
00186         foreach ($aParams as $key => $sParam)
00187             $aParams[$key] = str_replace(",", ".", $sParam);
00188 
00189             $sShopID = $myConfig->getShopID();
00190             $aParams['oxprice2article__oxshopid'] = $sShopID;
00191 
00192         $aParams['oxprice2article__oxartid'] = $soxId;
00193         if (!isset($aParams['oxprice2article__oxamount']) || !$aParams['oxprice2article__oxamount'])
00194             $aParams['oxprice2article__oxamount'] = "1";
00195 
00196         if ( !$myConfig->getConfigParam( 'blAllowUnevenAmounts' ) ) {
00197             $aParams['oxprice2article__oxamount']   = round((string) $aParams['oxprice2article__oxamount']);
00198             $aParams['oxprice2article__oxamountto'] = round((string) $aParams['oxprice2article__oxamountto']);
00199         }
00200         $dPrice = $aParams['price'];
00201         $sType = $aParams['pricetype'];
00202 
00203         $oArticlePrice = oxNew( "oxbase" );
00204         $oArticlePrice->init( "oxprice2article" );
00205         $oArticlePrice->assign($aParams);
00206 
00207         $oArticlePrice->$sType = new oxField($dPrice);
00208 
00209         //validating
00210 
00211         if ($oArticlePrice->$sType->value &&
00212             $oArticlePrice->oxprice2article__oxamount->value &&
00213             $oArticlePrice->oxprice2article__oxamountto->value &&
00214             is_numeric($oArticlePrice->$sType->value) &&
00215             is_numeric($oArticlePrice->oxprice2article__oxamount->value) &&
00216             is_numeric($oArticlePrice->oxprice2article__oxamountto->value) &&
00217             $oArticlePrice->oxprice2article__oxamount->value <= $oArticlePrice->oxprice2article__oxamountto->value
00218             ) {
00219                 $oArticlePrice->save();
00220         }
00221 
00222     }
00223 
00229     public function deleteprice()
00230     {
00231 
00232         $sPriceID = oxConfig::getParameter("priceid");
00233         $sOXID = oxConfig::getParameter("oxid");
00234         $sQ = "delete from oxprice2article where oxid = '$sPriceID' and oxartid = '$sOXID'";
00235         oxDb::getDb()->Execute($sQ);
00236     }
00237 
00238 }

Generated on Wed May 13 13:25:50 2009 for OXID eShop CE by  doxygen 1.5.5