00001 <?php
00002
00007 class oxOrderArticle extends oxBase
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
00078 public function __construct()
00079 {
00080 parent::__construct();
00081 $this->init( 'oxorderarticles' );
00082 }
00083
00091 public function copyThis( $oProduct )
00092 {
00093 $aObjectVars = get_object_vars( $oProduct );
00094
00095 foreach ( $aObjectVars as $sName => $sValue ) {
00096 if ( isset( $oProduct->$sName->value ) ) {
00097 $sFieldName = preg_replace('/oxarticles__/', 'oxorderarticles__', $sName);
00098 $this->$sFieldName = $oProduct->$sName;
00099 }
00100 }
00101
00102 }
00103
00111 public function assign( $dbRecord )
00112 {
00113 parent::assign( $dbRecord );
00114 $this->_setDeprecatedValues();
00115 }
00116
00127 public function updateArticleStock( $dAddAmount = null, $blAllowNegativeStock = null )
00128 {
00129
00130 $oArticle = oxNew( 'oxarticle' );
00131 $oArticle->load( $this->oxorderarticles__oxartid->value );
00132 $oArticle->beforeUpdate();
00133
00134
00135 $iStockCount = $this->_getArtStock( $dAddAmount, $blAllowNegativeStock );
00136
00137
00138 $oArticle->oxarticles__oxstock = new oxField($iStockCount);
00139 oxDb::getDb()->execute( 'update oxarticles set oxarticles.oxstock = '.$iStockCount.', oxarticles.oxtimestamp = oxarticles.oxtimestamp where oxarticles.oxid = "'.$this->oxorderarticles__oxartid->value.'" ' );
00140 $oArticle->onChange( ACTION_UPDATE_STOCK );
00141
00142
00143 $oArticle->updateSoldAmount( $dAddAmount * ( -1 ) );
00144 }
00145
00154 protected function _getArtStock( $dAddAmount = null, $blAllowNegativeStock = null )
00155 {
00156
00157 $sQ = 'select oxstock from oxarticles where oxid = "'.$this->oxorderarticles__oxartid->value.'" ';
00158 $iStockCount = ( float ) oxDb::getDb()->getOne( $sQ );
00159
00160 $iStockCount += $dAddAmount;
00161
00162
00163 if ( !$blAllowNegativeStock && $iStockCount < 0 ) {
00164 $iStockCount = 0;
00165 }
00166
00167 return $iStockCount;
00168 }
00169
00170
00176 public function getPersParams()
00177 {
00178 if ( $this->_aPersParam != null ) {
00179 return $this->_aPersParam;
00180 }
00181
00182 if ( $this->oxorderarticles__oxpersparam->value ) {
00183 $this->_aPersParam = unserialize( $this->oxorderarticles__oxpersparam->value );
00184 }
00185
00186 return $this->_aPersParam;
00187 }
00188
00196 public function setPersParams( $aParams )
00197 {
00198 $this->_aPersParam = $aParams;
00199
00200
00201 $this->oxorderarticles__oxpersparam = new oxField(serialize( $aParams ), oxField::T_RAW);
00202 }
00203
00211 protected function _setDeprecatedValues()
00212 {
00213
00214 $this->aPersParam = $this->getPersParams();
00215
00216 if ( $this->oxorderarticles__oxstorno->value != 1 ) {
00217 $oLang = oxLang::getInstance();
00218 $this->ftotbrutprice = $oLang->formatCurrency( $this->oxorderarticles__oxbrutprice->value );
00219 $this->fbrutprice = $oLang->formatCurrency( $this->oxorderarticles__oxbprice->value );
00220 $this->fnetprice = $oLang->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 }