oxorderarticle.php

Go to the documentation of this file.
00001 <?php
00002 
00007 class oxOrderArticle extends oxBase implements oxIArticle
00008 {
00014     protected $_sClassName = 'oxorderarticle';
00015 
00021     protected $_aPersParam = null;
00022 
00028     protected $_aStatuses = null;
00029 
00037     public $aStatuses = null;
00038 
00046     public $aPersParam = null;
00047 
00055     public $ftotbrutprice = null;
00056 
00064     public $fbrutprice = null;
00065 
00073     public $fnetprice = null;
00074 
00080     protected $_aOrderArticleSelList = null;
00081 
00087     protected $_oOrderArticle = null;
00088 
00094     protected $_blIsNewOrderItem = false;
00095 
00099     public function __construct()
00100     {
00101         parent::__construct();
00102         $this->init( 'oxorderarticles' );
00103     }
00104 
00112     public function copyThis( $oProduct )
00113     {
00114         $aObjectVars = get_object_vars( $oProduct );
00115 
00116         foreach ( $aObjectVars as $sName => $sValue ) {
00117             if ( isset( $oProduct->$sName->value ) ) {
00118                 $sFieldName = preg_replace('/oxarticles__/', 'oxorderarticles__', $sName);
00119                 $this->$sFieldName = $oProduct->$sName;
00120             }
00121         }
00122 
00123     }
00124 
00132     public function assign( $dbRecord )
00133     {
00134         parent::assign( $dbRecord );
00135         $this->_setDeprecatedValues();
00136         $this->_setArticleParams();
00137     }
00138 
00149     public function updateArticleStock( $dAddAmount = null, $blAllowNegativeStock = null )
00150     {
00151         // decrement stock if there is any
00152         $oArticle = oxNew( 'oxarticle' );
00153         $oArticle->load( $this->oxorderarticles__oxartid->value );
00154         $oArticle->beforeUpdate();
00155 
00156         // get real article stock count
00157         $iStockCount = $this->_getArtStock( $dAddAmount, $blAllowNegativeStock );
00158 
00159         // #874A. added oxarticles.oxtimestamp = oxarticles.oxtimestamp to keep old timestamp value
00160         $oArticle->oxarticles__oxstock = new oxField($iStockCount);
00161         oxDb::getDb()->execute( 'update oxarticles set oxarticles.oxstock = '.$iStockCount.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = "'.$this->oxorderarticles__oxartid->value.'" ' );
00162         $oArticle->onChange( ACTION_UPDATE_STOCK );
00163 
00164         //update article sold amount
00165         $oArticle->updateSoldAmount( $dAddAmount * ( -1 ) );
00166     }
00167 
00176     protected function _getArtStock( $dAddAmount = null, $blAllowNegativeStock = null )
00177     {
00178         // #1592A. must take real value
00179         $sQ = 'select oxstock from oxarticles where oxid = "'.$this->oxorderarticles__oxartid->value.'" ';
00180         $iStockCount  = ( float ) oxDb::getDb()->getOne( $sQ );
00181 
00182         $iStockCount += $dAddAmount;
00183 
00184         // #1592A. calculating according new stock option
00185         if ( !$blAllowNegativeStock && $iStockCount < 0 ) {
00186             $iStockCount = 0;
00187         }
00188 
00189         return $iStockCount;
00190     }
00191 
00192 
00198     public function getPersParams()
00199     {
00200         if ( $this->_aPersParam != null ) {
00201             return $this->_aPersParam;
00202         }
00203 
00204         if ( $this->oxorderarticles__oxpersparam->value ) {
00205             $this->_aPersParam = unserialize( $this->oxorderarticles__oxpersparam->value );
00206         }
00207 
00208         return $this->_aPersParam;
00209     }
00210 
00218     public function setPersParams( $aParams )
00219     {
00220         $this->_aPersParam = $aParams;
00221 
00222         // serializing persisten info stored while ordering
00223         $this->oxorderarticles__oxpersparam = new oxField(serialize( $aParams ), oxField::T_RAW);
00224     }
00225 
00233     protected function _setDeprecatedValues()
00234     {
00235 
00236         $this->aPersParam = $this->getPersParams();
00237 
00238         if ( $this->oxorderarticles__oxstorno->value != 1 ) {
00239             $oLang = oxLang::getInstance();
00240             $this->ftotbrutprice = $oLang->formatCurrency( $this->oxorderarticles__oxbrutprice->value );
00241             $this->fbrutprice    = $oLang->formatCurrency( $this->oxorderarticles__oxbprice->value );
00242             $this->fnetprice     = $oLang->formatCurrency( $this->oxorderarticles__oxnprice->value );
00243         }
00244     }
00245 
00255     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00256     {
00257         $sFieldName = strtolower($sFieldName);
00258         switch ( $sFieldName ) {
00259             case 'oxpersparam':
00260             case 'oxorderarticles__oxpersparam':
00261             case 'oxerpstatus':
00262             case 'oxorderarticles__oxerpstatus':
00263             case 'oxtitle':
00264             case 'oxorderarticles__oxtitle':
00265                 $iDataType = oxField::T_RAW;
00266                 break;
00267         }
00268         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00269     }
00270 
00276     public function loadInLang( $iLanguage, $sOxid )
00277     {
00278         return $this->load( $sOxid );
00279     }
00280 
00286     public function getProductId()
00287     {
00288         return $this->oxorderarticles__oxartid->value;
00289     }
00290 
00296     public function getProductParentId()
00297     {
00298         // when this field will be introduced there will be no need to load from real article
00299         if ( isset( $this->oxorderarticles__oxartparentid ) && $this->oxorderarticles__oxartparentid->value !== false ) {
00300             return $this->oxorderarticles__oxartparentid->value;
00301         }
00302 
00303         $oArticle = oxNew( "oxarticle" );
00304         $sQ = "select oxparentid from " . $oArticle->getViewName() . " where oxid='" . $this->getProductId() . "'";
00305         $this->oxarticles__oxparentid = new oxField( oxDb::getDb()->getOne( $sQ ) );
00306         return $this->oxarticles__oxparentid->value;
00307     }
00308 
00314     protected function _setArticleParams()
00315     {
00316         // creating needed fields
00317         $this->oxarticles__oxstock  = $this->oxorderarticles__oxamount;
00318         $this->oxarticles__oxtitle  = $this->oxorderarticles__oxtitle;
00319         $this->oxarticles__oxwidth  = $this->oxorderarticles__oxwidth;
00320         $this->oxarticles__oxlength = $this->oxorderarticles__oxlength;
00321         $this->oxarticles__oxheight = $this->oxorderarticles__oxheight;
00322         $this->oxarticles__oxweight = $this->oxorderarticles__oxweight;
00323         $this->oxarticles__oxsubclass  = $this->oxorderarticles__oxsubclass;
00324         $this->oxarticles__oxartnum    = $this->oxorderarticles__oxartnum;
00325         $this->oxarticles__oxshortdesc = $this->oxorderarticles__oxshortdesc;
00326 
00327         $this->oxarticles__oxvat    = $this->oxorderarticles__oxvat;
00328         $this->oxarticles__oxprice  = $this->oxorderarticles__oxprice;
00329         $this->oxarticles__oxbprice = $this->oxorderarticles__oxbprice;
00330 
00331         $this->oxarticles__oxthumb = $this->oxorderarticles__oxthumb;
00332         $this->oxarticles__oxpic1  = $this->oxorderarticles__oxpic1;
00333         $this->oxarticles__oxpic2  = $this->oxorderarticles__oxpic2;
00334         $this->oxarticles__oxpic3  = $this->oxorderarticles__oxpic3;
00335         $this->oxarticles__oxpic4  = $this->oxorderarticles__oxpic4;
00336         $this->oxarticles__oxpic5  = $this->oxorderarticles__oxpic5;
00337 
00338         $this->oxarticles__oxfile     = $this->oxorderarticles__oxfile;
00339         $this->oxarticles__oxdelivery = $this->oxorderarticles__oxdelivery;
00340         $this->oxarticles__oxissearch = $this->oxorderarticles__oxissearch;
00341         $this->oxarticles__oxfolder   = $this->oxorderarticles__oxfolder;
00342         $this->oxarticles__oxtemplate = $this->oxorderarticles__oxtemplate;
00343         $this->oxarticles__oxexturl   = $this->oxorderarticles__oxexturl;
00344         $this->oxarticles__oxurlimg   = $this->oxorderarticles__oxurlimg;
00345         $this->oxarticles__oxurldesc  = $this->oxorderarticles__oxurldesc;
00346         $this->oxarticles__oxshopid   = $this->oxorderarticles__oxordershopid;
00347         $this->oxarticles__oxquestionemail = $this->oxorderarticles__oxquestionemail;
00348         $this->oxarticles__oxsearchkeys    = $this->oxorderarticles__oxsearchkeys;
00349     }
00350 
00358     public function checkForStock( $dAmount )
00359     {
00360         return true;
00361     }
00362 
00371     protected function _getOrderArticle( $sArticleId = null )
00372     {
00373         if ( $this->_oOrderArticle === null ) {
00374             $this->_oOrderArticle = false;
00375 
00376             $sArticleId = $sArticleId ? $sArticleId : $this->getProductId();
00377             $oArticle = oxNew( "oxArticle" );
00378             if ( $oArticle->load( $sArticleId ) ) {
00379                 $this->_oOrderArticle = $oArticle;
00380             }
00381         }
00382         return $this->_oOrderArticle;
00383     }
00384 
00390     public function getSelectLists( $sKeyPrefix = null )
00391     {
00392         $aSelLists = array();
00393         if ( $oArticle = $this->_getOrderArticle() ) {
00394             $aSelLists = $oArticle->getSelectLists();
00395         }
00396         return $aSelLists;
00397     }
00398 
00407     public function getOrderArticleSelectList( $sArtId = null, $sOrderArtSelList = null )
00408     {
00409         if ( $this->_aOrderArticleSelList === null ) {
00410 
00411             $sOrderArtSelList = $sOrderArtSelList ? $sOrderArtSelList : $this->oxorderarticles__oxselvariant->value;
00412 
00413             $aList = array();
00414             $aRet  = array();
00415 
00416             if ( $oArticle = $this->_getOrderArticle( $sArtId ) ) {
00417                 $aList = explode( ",", $sOrderArtSelList );
00418                 $oStr = getStr();
00419 
00420                 $aArticleSelList = $oArticle->getSelectLists();
00421 
00422                 //formating temporary list array from string
00423                 foreach ( $aList as $sList ) {
00424                     if ( $sList ) {
00425 
00426                         $aVal = explode( ":", $sList );
00427                         if ( isset($aVal[0]) && isset($aVal[1])) {
00428                             $sOrderArtListTitle = $oStr->strtolower( trim($aVal[0]) );
00429                             $sOrderArtSelValue  = $oStr->strtolower( trim($aVal[1]) );
00430 
00431                             //checking article list for matches with article list stored in oxorderitem
00432                             $iSelListNum = 0;
00433                             if ( count($aArticleSelList) > 0 ) {
00434                                 foreach ( $aArticleSelList as $aSelect ) {
00435                                     //chek if selects titles are equal
00436 
00437                                     if ( $oStr->strtolower($aSelect['name']) == $sOrderArtListTitle ) {
00438                                         //try to find matching select items value
00439                                         $iSelValueNum = 0;
00440                                         foreach ( $aSelect as $oSel ) {
00441                                             if ( $oStr->strtolower($oSel->name) == $sOrderArtSelValue ) {
00442                                                 // found, adding tu return array
00443                                                 $aRet[$iSelListNum] = $iSelValueNum;
00444                                             }
00445                                             //next article list item
00446                                             $iSelValueNum++;
00447                                         }
00448                                     }
00449                                     //next article list
00450                                     $iSelListNum++;
00451                                 }
00452                             }
00453                         }
00454                     }
00455                 }
00456             }
00457 
00458             $this->_aOrderArticleSelList = $aRet;
00459         }
00460 
00461         return $this->_aOrderArticleSelList;
00462     }
00463 
00473     public function getBasketPrice( $dAmount, $aSelList, $oBasket )
00474     {
00475         return $this->getPrice();
00476     }
00477 
00483     public function skipDiscounts()
00484     {
00485         return false;
00486     }
00487 
00495     public function getCategoryIds( $blSkipCache = false )
00496     {
00497         $aCatIds = array();
00498         if ( $oOrderArticle = $this->_getOrderArticle() ) {
00499             $aCatIds = $oOrderArticle->getCategoryIds( $blSkipCache );
00500         }
00501         return $aCatIds;
00502     }
00503 
00509     public function getLanguage()
00510     {
00511         return oxLang::getInstance()->getBaseLanguage();
00512     }
00513 
00521     public function getBasePrice( $dAmount = 1 )
00522     {
00523         return $this->getPrice();
00524     }
00525 
00531     public function getPrice()
00532     {
00533         $oBasePrice = oxNew( 'oxPrice' );
00534         // prices in db are ONLY brutto
00535         $oBasePrice->setBruttoPriceMode();
00536         $oBasePrice->setVat( $this->oxorderarticles__oxvat->value );
00537         $oBasePrice->setPrice( $this->oxorderarticles__oxbprice->value );
00538 
00539         return $oBasePrice;
00540     }
00541 
00549     public function setIsNewOrderItem( $blIsNew )
00550     {
00551         $this->_blIsNewOrderItem = $blIsNew;
00552     }
00553 
00559     public function isNewOrderItem()
00560     {
00561         return $this->_blIsNewOrderItem;
00562     }
00563 
00573     public function setNewAmount( $iNewAmount )
00574     {
00575         if ( $iNewAmount >= 0 ) {
00576             // to update stock we must first check if it is possible - article exists?
00577             $oArticle = oxNew( "oxarticle" );
00578             if ( $oArticle->load( $this->oxorderarticles__oxartid->value ) ) {
00579 
00580                 // updating stock info
00581                 $iStockChange = $iNewAmount - $this->oxorderarticles__oxamount->value;
00582                 if ( $iStockChange > 0 && ( $iOnStock = $oArticle->checkForStock( $iStockChange ) ) !== false ) {
00583                     if ( $iOnStock !== true ) {
00584                         $iStockChange = $iOnStock;
00585                         $iNewAmount   = $this->oxorderarticles__oxamount->value + $iStockChange;
00586                     }
00587                 }
00588 
00589                 $this->updateArticleStock( $iStockChange * -1, $this->getConfig()->getConfigParam( 'blAllowNegativeStock' ) );
00590 
00591                 // updating self
00592                 $this->oxorderarticles__oxamount = new oxField ( $iNewAmount, oxField::T_RAW );
00593                 $this->save();
00594             }
00595         }
00596     }
00597 
00603     public function isOrderArticle()
00604     {
00605         return true;
00606     }
00607 
00608 }

Generated on Tue Aug 18 09:21:06 2009 for OXID eShop CE by  doxygen 1.5.5