00001 <?php
00002
00008 class oxUserBasketItem extends oxBase
00009 {
00015 protected $_sClassName = 'oxuserbasketitem';
00016
00022 protected $_oArticle = null;
00023
00029 protected $_blParentBuyable = false;
00030
00036 protected $_aSelList = null;
00037
00041 public function __construct()
00042 {
00043 $this->setVariantParentBuyable( $this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) );
00044 parent::__construct();
00045 $this->init( 'oxuserbasketitems' );
00046 }
00047
00055 public function setVariantParentBuyable( $blBuyable = false )
00056 {
00057 $this->_blParentBuyable = $blBuyable;
00058 }
00059
00069 public function getArticle( $sItemKey )
00070 {
00071 if ( !$this->oxuserbasketitems__oxartid->value ) {
00072
00073 $oEx = oxNew( 'oxArticleException' );
00074 $oEx->setMessage( 'EXCEPTION_ARTICLE_NOPRODUCTID' );
00075 throw $oEx;
00076 }
00077
00078 if ( $this->_oArticle ) {
00079 return $this->_oArticle;
00080 }
00081
00082 $this->_oArticle = oxNew( 'oxarticle' );
00083
00084
00085 if ( $this->_blParentBuyable ) {
00086 $this->_oArticle->setSkipAbPrice( true );
00087 $this->_oArticle->setNoVariantLoading( true );
00088 }
00089
00090 if ( !$this->_oArticle->load( $this->oxuserbasketitems__oxartid->value ) ) {
00091 return false;
00092 }
00093
00094 $aSelList = $this->getSelList();
00095 if ( ( $aSelectlist = $this->_oArticle->getSelectLists() ) && is_array( $aSelList ) ) {
00096 foreach ( $aSelList as $iKey => $iSel ) {
00097
00098 if ( isset( $aSelectlist[$iKey][$iSel] ) ) {
00099
00100 $aSelectlist[$iKey][$iSel] = clone $aSelectlist[$iKey][$iSel];
00101 $aSelectlist[$iKey][$iSel]->selected = 1;
00102 }
00103 }
00104 $this->_oArticle->setSelectlist( $aSelectlist );
00105 }
00106
00107 if ( $this->_oArticle->oxarticles__oxparentid->value ) {
00108 $oParent = oxNew( 'oxarticle' );
00109 if ( $oParent->load( $this->_oArticle->oxarticles__oxparentid->value ) ) {
00110 if ( $this->_oArticle->oxarticles__oxvarselect->value ) {
00111 $this->_oArticle->oxarticles__oxtitle->value .= ', '.$this->_oArticle->oxarticles__oxvarselect->value;
00112 }
00113 }
00114 }
00115
00116
00117 $this->_oArticle->setItemKey( $sItemKey );
00118
00119 return $this->_oArticle;
00120
00121 }
00122
00128 public function __sleep()
00129 {
00130 $aRet = array();
00131 foreach ( get_object_vars( $this ) as $sKey => $sVar ) {
00132 if ( $sKey != '_oArticle' ) {
00133 $aRet[] = $sKey;
00134 }
00135 }
00136 return $aRet;
00137 }
00138
00144 public function getSelList()
00145 {
00146 if ( $this->_aSelList == null && $this->oxuserbasketitems__oxsellist->value ) {
00147 $this->_aSelList = unserialize( $this->oxuserbasketitems__oxsellist->value );
00148 }
00149
00150 return $this->_aSelList;
00151 }
00152
00160 public function setSelList( $aSelList )
00161 {
00162 $this->oxuserbasketitems__oxsellist = new oxField(serialize( $aSelList ), oxField::T_RAW);
00163 }
00164
00174 protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
00175 {
00176 if ('oxsellist' === strtolower($sFieldName) || 'oxuserbasketitems__oxsellist' === strtolower($sFieldName)) {
00177 $iDataType = oxField::T_RAW;
00178 }
00179 return parent::_setFieldData($sFieldName, $sValue, $iDataType);
00180 }
00181 }