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         $oDb = oxDb::getDb();
00159 
00160         // #874A. added oxarticles.oxtimestamp = oxarticles.oxtimestamp to keep old timestamp value
00161         $oArticle->oxarticles__oxstock = new oxField($iStockCount);
00162         $oDb->execute( 'update oxarticles set oxarticles.oxstock = '.$oDb->quote( $iStockCount ).', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = '.$oDb->quote( $this->oxorderarticles__oxartid->value ) );
00163         $oArticle->onChange( ACTION_UPDATE_STOCK );
00164 
00165         //update article sold amount
00166         $oArticle->updateSoldAmount( $dAddAmount * ( -1 ) );
00167     }
00168 
00177     protected function _getArtStock( $dAddAmount = null, $blAllowNegativeStock = null )
00178     {
00179         $oDb = oxDb::getDb();
00180 
00181         // #1592A. must take real value
00182         $sQ = 'select oxstock from oxarticles where oxid = '.$oDb->quote( $this->oxorderarticles__oxartid->value );
00183         $iStockCount  = ( float ) $oDb->getOne( $sQ );
00184 
00185         $iStockCount += $dAddAmount;
00186 
00187         // #1592A. calculating according new stock option
00188         if ( !$blAllowNegativeStock && $iStockCount < 0 ) {
00189             $iStockCount = 0;
00190         }
00191 
00192         return $iStockCount;
00193     }
00194 
00195 
00201     public function getPersParams()
00202     {
00203         if ( $this->_aPersParam != null ) {
00204             return $this->_aPersParam;
00205         }
00206 
00207         if ( $this->oxorderarticles__oxpersparam->value ) {
00208             $this->_aPersParam = unserialize( $this->oxorderarticles__oxpersparam->value );
00209         }
00210 
00211         return $this->_aPersParam;
00212     }
00213 
00221     public function setPersParams( $aParams )
00222     {
00223         $this->_aPersParam = $aParams;
00224 
00225         // serializing persisten info stored while ordering
00226         $this->oxorderarticles__oxpersparam = new oxField(serialize( $aParams ), oxField::T_RAW);
00227     }
00228 
00236     protected function _setDeprecatedValues()
00237     {
00238 
00239         $this->aPersParam = $this->getPersParams();
00240 
00241         if ( $this->oxorderarticles__oxstorno->value != 1 ) {
00242             $oLang = oxLang::getInstance();
00243             $this->ftotbrutprice = $oLang->formatCurrency( $this->oxorderarticles__oxbrutprice->value );
00244             $this->fbrutprice    = $oLang->formatCurrency( $this->oxorderarticles__oxbprice->value );
00245             $this->fnetprice     = $oLang->formatCurrency( $this->oxorderarticles__oxnprice->value );
00246         }
00247     }
00248 
00258     protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00259     {
00260         $sFieldName = strtolower($sFieldName);
00261         switch ( $sFieldName ) {
00262             case 'oxpersparam':
00263             case 'oxorderarticles__oxpersparam':
00264             case 'oxerpstatus':
00265             case 'oxorderarticles__oxerpstatus':
00266             case 'oxtitle':
00267             case 'oxorderarticles__oxtitle':
00268                 $iDataType = oxField::T_RAW;
00269                 break;
00270         }
00271         return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00272     }
00273 
00282     public function loadInLang( $iLanguage, $sOxid )
00283     {
00284         return $this->load( $sOxid );
00285     }
00286 
00292     public function getProductId()
00293     {
00294         return $this->oxorderarticles__oxartid->value;
00295     }
00296 
00302     public function getProductParentId()
00303     {
00304         // when this field will be introduced there will be no need to load from real article
00305         if ( isset( $this->oxorderarticles__oxartparentid ) && $this->oxorderarticles__oxartparentid->value !== false ) {
00306             return $this->oxorderarticles__oxartparentid->value;
00307         }
00308 
00309         $oDb = oxDb::getDb();
00310         $oArticle = oxNew( "oxarticle" );
00311         $sQ = "select oxparentid from " . $oArticle->getViewName() . " where oxid=" . $oDb->quote( $this->getProductId() );
00312         $this->oxarticles__oxparentid = new oxField( $oDb->getOne( $sQ ) );
00313         return $this->oxarticles__oxparentid->value;
00314     }
00315 
00321     protected function _setArticleParams()
00322     {
00323         // creating needed fields
00324         $this->oxarticles__oxstock  = $this->oxorderarticles__oxamount;
00325         $this->oxarticles__oxtitle  = $this->oxorderarticles__oxtitle;
00326         $this->oxarticles__oxwidth  = $this->oxorderarticles__oxwidth;
00327         $this->oxarticles__oxlength = $this->oxorderarticles__oxlength;
00328         $this->oxarticles__oxheight = $this->oxorderarticles__oxheight;
00329         $this->oxarticles__oxweight = $this->oxorderarticles__oxweight;
00330         $this->oxarticles__oxsubclass  = $this->oxorderarticles__oxsubclass;
00331         $this->oxarticles__oxartnum    = $this->oxorderarticles__oxartnum;
00332         $this->oxarticles__oxshortdesc = $this->oxorderarticles__oxshortdesc;
00333 
00334         $this->oxarticles__oxvat    = $this->oxorderarticles__oxvat;
00335         $this->oxarticles__oxprice  = $this->oxorderarticles__oxprice;
00336         $this->oxarticles__oxbprice = $this->oxorderarticles__oxbprice;
00337 
00338         $this->oxarticles__oxthumb = $this->oxorderarticles__oxthumb;
00339         $this->oxarticles__oxpic1  = $this->oxorderarticles__oxpic1;
00340         $this->oxarticles__oxpic2  = $this->oxorderarticles__oxpic2;
00341         $this->oxarticles__oxpic3  = $this->oxorderarticles__oxpic3;
00342         $this->oxarticles__oxpic4  = $this->oxorderarticles__oxpic4;
00343         $this->oxarticles__oxpic5  = $this->oxorderarticles__oxpic5;
00344 
00345         $this->oxarticles__oxfile     = $this->oxorderarticles__oxfile;
00346         $this->oxarticles__oxdelivery = $this->oxorderarticles__oxdelivery;
00347         $this->oxarticles__oxissearch = $this->oxorderarticles__oxissearch;
00348         $this->oxarticles__oxfolder   = $this->oxorderarticles__oxfolder;
00349         $this->oxarticles__oxtemplate = $this->oxorderarticles__oxtemplate;
00350         $this->oxarticles__oxexturl   = $this->oxorderarticles__oxexturl;
00351         $this->oxarticles__oxurlimg   = $this->oxorderarticles__oxurlimg;
00352         $this->oxarticles__oxurldesc  = $this->oxorderarticles__oxurldesc;
00353         $this->oxarticles__oxshopid   = $this->oxorderarticles__oxordershopid;
00354         $this->oxarticles__oxquestionemail = $this->oxorderarticles__oxquestionemail;
00355         $this->oxarticles__oxsearchkeys    = $this->oxorderarticles__oxsearchkeys;
00356     }
00357 
00365     public function checkForStock( $dAmount )
00366     {
00367         return true;
00368     }
00369 
00378     protected function _getOrderArticle( $sArticleId = null )
00379     {
00380         if ( $this->_oOrderArticle === null ) {
00381             $this->_oOrderArticle = false;
00382 
00383             $sArticleId = $sArticleId ? $sArticleId : $this->getProductId();
00384             $oArticle = oxNew( "oxArticle" );
00385             if ( $oArticle->load( $sArticleId ) ) {
00386                 $this->_oOrderArticle = $oArticle;
00387             }
00388         }
00389         return $this->_oOrderArticle;
00390     }
00391 
00399     public function getSelectLists( $sKeyPrefix = null )
00400     {
00401         $aSelLists = array();
00402         if ( $oArticle = $this->_getOrderArticle() ) {
00403             $aSelLists = $oArticle->getSelectLists();
00404         }
00405         return $aSelLists;
00406     }
00407 
00416     public function getOrderArticleSelectList( $sArtId = null, $sOrderArtSelList = null )
00417     {
00418         if ( $this->_aOrderArticleSelList === null ) {
00419 
00420             $sOrderArtSelList = $sOrderArtSelList ? $sOrderArtSelList : $this->oxorderarticles__oxselvariant->value;
00421 
00422             $aList = array();
00423             $aRet  = array();
00424 
00425             if ( $oArticle = $this->_getOrderArticle( $sArtId ) ) {
00426                 $aList = explode( ",", $sOrderArtSelList );
00427                 $oStr = getStr();
00428 
00429                 $aArticleSelList = $oArticle->getSelectLists();
00430 
00431                 //formating temporary list array from string
00432                 foreach ( $aList as $sList ) {
00433                     if ( $sList ) {
00434 
00435                         $aVal = explode( ":", $sList );
00436                         if ( isset($aVal[0]) && isset($aVal[1])) {
00437                             $sOrderArtListTitle = $oStr->strtolower( trim($aVal[0]) );
00438                             $sOrderArtSelValue  = $oStr->strtolower( trim($aVal[1]) );
00439 
00440                             //checking article list for matches with article list stored in oxorderitem
00441                             $iSelListNum = 0;
00442                             if ( count($aArticleSelList) > 0 ) {
00443                                 foreach ( $aArticleSelList as $aSelect ) {
00444                                     //chek if selects titles are equal
00445 
00446                                     if ( $oStr->strtolower($aSelect['name']) == $sOrderArtListTitle ) {
00447                                         //try to find matching select items value
00448                                         $iSelValueNum = 0;
00449                                         foreach ( $aSelect as $oSel ) {
00450                                             if ( $oStr->strtolower($oSel->name) == $sOrderArtSelValue ) {
00451                                                 // found, adding tu return array
00452                                                 $aRet[$iSelListNum] = $iSelValueNum;
00453                                             }
00454                                             //next article list item
00455                                             $iSelValueNum++;
00456                                         }
00457                                     }
00458                                     //next article list
00459                                     $iSelListNum++;
00460                                 }
00461                             }
00462                         }
00463                     }
00464                 }
00465             }
00466 
00467             $this->_aOrderArticleSelList = $aRet;
00468         }
00469 
00470         return $this->_aOrderArticleSelList;
00471     }
00472 
00482     public function getBasketPrice( $dAmount, $aSelList, $oBasket )
00483     {
00484         return $this->getPrice();
00485     }
00486 
00492     public function skipDiscounts()
00493     {
00494         return false;
00495     }
00496 
00505     public function getCategoryIds( $blActCats = false, $blSkipCache = false )
00506     {
00507         $aCatIds = array();
00508         if ( $oOrderArticle = $this->_getOrderArticle() ) {
00509             $aCatIds = $oOrderArticle->getCategoryIds( $blActCats, $blSkipCache );
00510         }
00511         return $aCatIds;
00512     }
00513 
00519     public function getLanguage()
00520     {
00521         return oxLang::getInstance()->getBaseLanguage();
00522     }
00523 
00531     public function getBasePrice( $dAmount = 1 )
00532     {
00533         return $this->getPrice();
00534     }
00535 
00541     public function getPrice()
00542     {
00543         $oBasePrice = oxNew( 'oxPrice' );
00544         // prices in db are ONLY brutto
00545         $oBasePrice->setBruttoPriceMode();
00546         $oBasePrice->setVat( $this->oxorderarticles__oxvat->value );
00547         $oBasePrice->setPrice( $this->oxorderarticles__oxbprice->value );
00548 
00549         return $oBasePrice;
00550     }
00551 
00559     public function setIsNewOrderItem( $blIsNew )
00560     {
00561         $this->_blIsNewOrderItem = $blIsNew;
00562     }
00563 
00569     public function isNewOrderItem()
00570     {
00571         return $this->_blIsNewOrderItem;
00572     }
00573 
00583     public function setNewAmount( $iNewAmount )
00584     {
00585         if ( $iNewAmount >= 0 ) {
00586             // to update stock we must first check if it is possible - article exists?
00587             $oArticle = oxNew( "oxarticle" );
00588             if ( $oArticle->load( $this->oxorderarticles__oxartid->value ) ) {
00589 
00590                 // updating stock info
00591                 $iStockChange = $iNewAmount - $this->oxorderarticles__oxamount->value;
00592                 if ( $iStockChange > 0 && ( $iOnStock = $oArticle->checkForStock( $iStockChange ) ) !== false ) {
00593                     if ( $iOnStock !== true ) {
00594                         $iStockChange = $iOnStock;
00595                         $iNewAmount   = $this->oxorderarticles__oxamount->value + $iStockChange;
00596                     }
00597                 }
00598 
00599                 $this->updateArticleStock( $iStockChange * -1, $this->getConfig()->getConfigParam( 'blAllowNegativeStock' ) );
00600 
00601                 // updating self
00602                 $this->oxorderarticles__oxamount = new oxField ( $iNewAmount, oxField::T_RAW );
00603                 $this->save();
00604             }
00605         }
00606     }
00607 
00613     public function isOrderArticle()
00614     {
00615         return true;
00616     }
00617 
00618 
00625    public function cancelOrderArticle()
00626    {
00627         if ( $this->oxorderarticles__oxstorno->value == 0 ) {
00628             $myConfig = $this->getConfig();
00629             $this->oxorderarticles__oxstorno->setValue( 1 );
00630             if ( $this->save() && $myConfig->getConfigParam( 'blUseStock' ) ) {
00631                 $this->updateArticleStock( $this->oxorderarticles__oxamount->value, $myConfig->getConfigParam('blAllowNegativeStock') );
00632             }
00633         }
00634    }
00635 }

Generated on Tue Sep 29 16:45:12 2009 for OXID eShop CE by  doxygen 1.5.5