50 $this->
init(
'oxuserbaskets' );
61 $this->_blNewBasket =
false;
63 if ( !isset( $this->oxuserbaskets__oxpublic->value ) ) {
68 $this->oxuserbaskets__oxupdate =
new oxField( $iTime );
81 $this->_blNewBasket =
true;
83 $this->oxuserbaskets__oxupdate =
new oxField( $iTime );
119 if ( is_array( $aItems ) ) {
120 foreach ( $aItems as $sId => $oItem ) {
121 $oArticle = $oItem->getArticle( $sId );
122 $aRes[$this->
_getItemKey($oArticle->getId(), $oItem->getSelList(), $oItem->getPersParams())] = $oArticle;
136 public function getItems( $blReload =
false, $blActiveCheck =
true )
139 if ( $this->_aBasketItems !== null && !$blReload ) {
144 $this->_aBasketItems = array();
147 $oArticle =
oxNew(
'oxarticle' );
148 $sViewName = $oArticle->getViewName();
150 $sSelect =
"select oxuserbasketitems.* from oxuserbasketitems left join $sViewName on oxuserbasketitems.oxartid = $sViewName.oxid ";
151 if ($blActiveCheck) {
152 $sSelect .=
'and '.$oArticle->getSqlActiveSnippet().
' ';
154 $sSelect .=
"where oxuserbasketitems.oxbasketid = '".$this->getId().
"' and $sViewName.oxid is not null ";
156 $sSelect .=
" order by oxartnum, oxsellist, oxpersparam ";
158 $oItems =
oxNew(
'oxlist' );
159 $oItems->init(
'oxuserbasketitem' );
160 $oItems->selectstring( $sSelect );
162 foreach ( $oItems as $oItem ) {
163 $sKey = $this->
_getItemKey( $oItem->oxuserbasketitems__oxartid->value, $oItem->getSelList(), $oItem->getPersParams() );
164 $this->_aBasketItems[$sKey] = $oItem;
180 protected function _createItem( $sProductId, $aSelList = null, $aPersParams = null )
182 $oNewItem =
oxNew(
'oxuserbasketitem' );
185 if ( $aPersParams && count($aPersParams) ) {
186 $oNewItem->setPersParams( $aPersParams );
190 $oArticle =
oxNew(
'oxArticle' );
191 $oArticle->load( $sProductId );
192 $aSelectLists = $oArticle->getSelectLists();
193 if ( ( $iSelCnt = count( $aSelectLists ) ) ) {
194 $aSelList = array_fill( 0, $iSelCnt,
'0' );
198 $oNewItem->setSelList( $aSelList );
214 public function getItem( $sProductId, $aSelList, $aPersParams = null)
218 $sItemKey = $this->
_getItemKey( $sProductId, $aSelList, $aPersParams );
221 if ( isset( $aItems[$sProductId] )) {
222 $oItem = $aItems[$sProductId];
223 } elseif ( isset( $aItems[$sItemKey] ) ) {
224 $oItem = $aItems[$sItemKey];
226 $oItem = $this->
_createItem( $sProductId, $aSelList, $aPersParams );
241 protected function _getItemKey( $sProductId, $aSel = null, $aPersParam = null )
243 $aSel = ( $aSel != null) ? $aSel : array (0=>
'0');
244 return md5( $sProductId.
'|'.serialize( $aSel ).
'|'.serialize( $aPersParam ) );
256 return count( $this->
getItems( $blReload ) );
271 public function addItemToBasket( $sProductId = null, $dAmount = null, $aSel = null, $blOverride =
false, $aPersParam = null )
274 if ( $this->_blNewBasket ) {
278 if ( ( $oUserBasketItem = $this->
getItem( $sProductId, $aSel, $aPersParam ) ) ) {
280 if ( !$blOverride && !empty($oUserBasketItem->oxuserbasketitems__oxamount->value) ) {
281 $dAmount += $oUserBasketItem->oxuserbasketitems__oxamount->value;
286 $oUserBasketItem->delete();
287 if ( isset($this->_aBasketItems[$this->
_getItemKey($sProductId, $aSel, $aPersParam)])) {
288 unset( $this->_aBasketItems[$this->
_getItemKey($sProductId, $aSel, $aPersParam)] );
292 $oUserBasketItem->save();
294 $this->_aBasketItems[$this->
_getItemKey($sProductId, $aSel, $aPersParam)] = $oUserBasketItem;
312 public function delete( $sOXID = null )
315 $sOXID = $this->
getId();
319 if ( $sOXID && ( $blDelete = parent::delete( $sOXID ) ) ) {
322 $sQ =
"delete from oxuserbasketitems where oxbasketid = " . $oDb->quote( $sOXID );
323 $oDb->execute( $sQ );
335 $oActivUser = $this->
getConfig()->getUser();
336 $sActivUserId = null;
338 $sActivUserId = $oActivUser->getId();
340 $blIsVisible = (bool) ($this->oxuserbaskets__oxpublic->value) ||
341 ($sActivUserId && ($this->oxuserbaskets__oxuserid->value == $sActivUserId));