00001 <?php
00002
00008 class oxOrderArticle extends oxBase
00009 {
00015 protected $_sClassName = 'oxorderarticle';
00016
00022 protected $_aPersParam = null;
00023
00029 protected $_aStatuses = null;
00030
00038 public $aStatuses = null;
00039
00047 public $aPersParam = null;
00048
00056 public $ftotbrutprice = null;
00057
00065 public $fbrutprice = null;
00066
00074 public $fnetprice = null;
00075
00079 public function __construct()
00080 {
00081 parent::__construct();
00082 $this->init( 'oxorderarticles' );
00083 }
00084
00092 public function copyThis( $oProduct )
00093 {
00094 $aObjectVars = get_object_vars( $oProduct );
00095
00096 foreach ( $aObjectVars as $sName => $sValue ) {
00097 if ( isset( $oProduct->$sName->value ) ) {
00098 $sFieldName = preg_replace('/oxarticles__/', 'oxorderarticles__', $sName);
00099 $this->$sFieldName = $oProduct->$sName;
00100 }
00101 }
00102
00103 }
00104
00112 public function assign( $dbRecord )
00113 {
00114 parent::assign( $dbRecord );
00115 $this->_setDeprecatedValues();
00116 }
00117
00128 public function updateArticleStock( $dAddAmount = null, $blAllowNegativeStock = null )
00129 {
00130
00131 $oArticle = oxNew( 'oxarticle' );
00132 $oArticle->load( $this->oxorderarticles__oxartid->value );
00133 $oArticle->beforeUpdate();
00134
00135
00136 $iStockCount = $this->_getArtStock( $dAddAmount, $blAllowNegativeStock );
00137
00138
00139 $oArticle->oxarticles__oxstock = new oxField($iStockCount);
00140 oxDb::getDb()->execute( 'update oxarticles set oxarticles.oxstock = '.$iStockCount.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = "'.$this->oxorderarticles__oxartid->value.'" ' );
00141 $oArticle->onChange( ACTION_UPDATE_STOCK );
00142
00143
00144 $oArticle->updateSoldAmount( $dAddAmount * ( -1 ) );
00145 }
00146
00155 protected function _getArtStock( $dAddAmount = null, $blAllowNegativeStock = null )
00156 {
00157
00158 $sQ = 'select oxstock from oxarticles where oxid = "'.$this->oxorderarticles__oxartid->value.'" ';
00159 $iStockCount = ( float ) oxDb::getDb()->getOne( $sQ );
00160
00161 $iStockCount += $dAddAmount;
00162
00163
00164 if ( !$blAllowNegativeStock && $iStockCount < 0 ) {
00165 $iStockCount = 0;
00166 }
00167
00168 return $iStockCount;
00169 }
00170
00171
00177 public function getPersParams()
00178 {
00179 if ( $this->_aPersParam != null ) {
00180 return $this->_aPersParam;
00181 }
00182
00183 if ( $this->oxorderarticles__oxpersparam->value ) {
00184 $this->_aPersParam = unserialize( $this->oxorderarticles__oxpersparam->value );
00185 }
00186
00187 return $this->_aPersParam;
00188 }
00189
00197 public function setPersParams( $aParams )
00198 {
00199 $this->_aPersParam = $aParams;
00200
00201
00202 $this->oxorderarticles__oxpersparam = new oxField(serialize( $aParams ), oxField::T_RAW);
00203 }
00204
00212 protected function _setDeprecatedValues()
00213 {
00214
00215 $this->aPersParam = $this->getPersParams();
00216
00217 if ( $this->oxorderarticles__oxstorno->value != 1 ) {
00218 $this->ftotbrutprice = oxLang::getInstance()->formatCurrency( $this->oxorderarticles__oxbrutprice->value );
00219 $this->fbrutprice = oxLang::getInstance()->formatCurrency( $this->oxorderarticles__oxbprice->value );
00220 $this->fnetprice = oxLang::getInstance()->formatCurrency( $this->oxorderarticles__oxnprice->value );
00221 }
00222 }
00223
00233 protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00234 {
00235 $sFieldName = strtolower($sFieldName);
00236 switch ( $sFieldName ) {
00237 case 'oxpersparam':
00238 case 'oxorderarticles__oxpersparam':
00239 case 'oxerpstatus':
00240 case 'oxorderarticles__oxerpstatus':
00241 case 'oxtitle':
00242 case 'oxorderarticles__oxtitle':
00243 $iDataType = oxField::T_RAW;
00244 break;
00245 }
00246 return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00247 }
00248 }