OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
oxuserbasketitem.php
Go to the documentation of this file.
1 <?php
2 
8 class oxUserBasketItem extends oxBase
9 {
15  protected $_sClassName = 'oxuserbasketitem';
16 
22  protected $_oArticle = null;
23 
29  protected $_blParentBuyable = false;
30 
36  protected $_aSelList = null;
37 
43  protected $_aPersParam = null;
44 
48  public function __construct()
49  {
50  $this->setVariantParentBuyable( $this->getConfig()->getConfigParam( 'blVariantParentBuyable' ) );
52  $this->init( 'oxuserbasketitems' );
53  }
54 
62  public function setVariantParentBuyable( $blBuyable = false )
63  {
64  $this->_blParentBuyable = $blBuyable;
65  }
66 
76  public function getArticle( $sItemKey )
77  {
78  if ( !$this->oxuserbasketitems__oxartid->value ) {
79  //this exception may not be caught, anyhow this is a critical exception
80  $oEx = oxNew( 'oxArticleException' );
81  $oEx->setMessage( 'EXCEPTION_ARTICLE_NOPRODUCTID' );
82  throw $oEx;
83  }
84 
85  if ( $this->_oArticle === null ) {
86 
87  $this->_oArticle = oxNew( 'oxarticle' );
88 
89  // performance
90  /* removed due to #4178
91  if ( $this->_blParentBuyable ) {
92  $this->_oArticle->setNoVariantLoading( true );
93  }
94  */
95 
96  if ( !$this->_oArticle->load( $this->oxuserbasketitems__oxartid->value ) ) {
97  return false;
98  }
99 
100  $aSelList = $this->getSelList();
101  if ( ( $aSelectlist = $this->_oArticle->getSelectLists() ) && is_array( $aSelList ) ) {
102  foreach ( $aSelList as $iKey => $iSel ) {
103 
104  if ( isset( $aSelectlist[$iKey][$iSel] ) ) {
105  // cloning select list information
106  $aSelectlist[$iKey][$iSel] = clone $aSelectlist[$iKey][$iSel];
107  $aSelectlist[$iKey][$iSel]->selected = 1;
108  }
109  }
110  $this->_oArticle->setSelectlist( $aSelectlist );
111  }
112 
113  // generating item key
114  $this->_oArticle->setItemKey( $sItemKey );
115  }
116 
117  return $this->_oArticle;
118 
119  }
120 
126  public function __sleep()
127  {
128  $aRet = array();
129  foreach ( get_object_vars( $this ) as $sKey => $sVar ) {
130  if ( $sKey != '_oArticle' ) {
131  $aRet[] = $sKey;
132  }
133  }
134  return $aRet;
135  }
136 
142  public function getSelList()
143  {
144  if ( $this->_aSelList == null && $this->oxuserbasketitems__oxsellist->value ) {
145  $this->_aSelList = unserialize( $this->oxuserbasketitems__oxsellist->value );
146  }
147 
148  return $this->_aSelList;
149  }
150 
158  public function setSelList( $aSelList )
159  {
160  $this->oxuserbasketitems__oxsellist = new oxField(serialize( $aSelList ), oxField::T_RAW);
161  }
162 
168  public function getPersParams()
169  {
170  if ( $this->_aPersParam == null && $this->oxuserbasketitems__oxpersparam->value ) {
171  $this->_aPersParam = unserialize( $this->oxuserbasketitems__oxpersparam->value );
172  }
173 
174  return $this->_aPersParam;
175  }
176 
184  public function setPersParams( $sPersParams )
185  {
186  $this->oxuserbasketitems__oxpersparam = new oxField(serialize($sPersParams), oxField::T_RAW);
187  }
188 
198  protected function _setFieldData( $sFieldName, $sValue, $iDataType = oxField::T_TEXT)
199  {
200  if ('oxsellist' === strtolower($sFieldName) || 'oxuserbasketitems__oxsellist' === strtolower($sFieldName)
201  || 'oxpersparam' === strtolower($sFieldName) || 'oxuserbasketitems__oxpersparam' === strtolower($sFieldName)) {
202  $iDataType = oxField::T_RAW;
203  }
204  return parent::_setFieldData($sFieldName, $sValue, $iDataType);
205  }
206 }