50 $this->
init(
'oxuserbaskets');
61 $this->_blNewBasket =
false;
63 if (!isset($this->oxuserbaskets__oxpublic->value)) {
68 $this->oxuserbaskets__oxupdate =
new oxField($iTime);
79 $this->_blNewBasket =
true;
81 $this->oxuserbaskets__oxupdate =
new oxField($iTime);
117 if (is_array($aItems)) {
118 foreach ($aItems as $sId => $oItem) {
119 $oArticle = $oItem->getArticle($sId);
120 $aRes[$this->
_getItemKey($oArticle->getId(), $oItem->getSelList(), $oItem->getPersParams())] = $oArticle;
135 public function getItems($blReload =
false, $blActiveCheck =
true)
138 if ($this->_aBasketItems !== null && !$blReload) {
143 $this->_aBasketItems = array();
146 $oArticle =
oxNew(
'oxarticle');
147 $sViewName = $oArticle->getViewName();
149 $sSelect =
"select oxuserbasketitems.* from oxuserbasketitems left join $sViewName on oxuserbasketitems.oxartid = $sViewName.oxid ";
150 if ($blActiveCheck) {
151 $sSelect .=
'and ' . $oArticle->getSqlActiveSnippet() .
' ';
153 $sSelect .=
"where oxuserbasketitems.oxbasketid = '" . $this->
getId() .
"' and $sViewName.oxid is not null ";
155 $sSelect .=
" order by oxartnum, oxsellist, oxpersparam ";
157 $oItems =
oxNew(
'oxlist');
158 $oItems->init(
'oxuserbasketitem');
159 $oItems->selectstring($sSelect);
161 foreach ($oItems as $oItem) {
162 $sKey = $this->
_getItemKey($oItem->oxuserbasketitems__oxartid->value, $oItem->getSelList(), $oItem->getPersParams());
163 $this->_aBasketItems[$sKey] = $oItem;
179 protected function _createItem($sProductId, $aSelList = null, $aPersParams = null)
181 $oNewItem =
oxNew(
'oxuserbasketitem');
184 if ($aPersParams && count($aPersParams)) {
185 $oNewItem->setPersParams($aPersParams);
189 $oArticle =
oxNew(
'oxArticle');
190 $oArticle->load($sProductId);
191 $aSelectLists = $oArticle->getSelectLists();
192 if (($iSelCnt = count($aSelectLists))) {
193 $aSelList = array_fill(0, $iSelCnt,
'0');
197 $oNewItem->setSelList($aSelList);
213 public function getItem($sProductId, $aSelList, $aPersParams = null)
217 $sItemKey = $this->
_getItemKey($sProductId, $aSelList, $aPersParams);
220 if (isset($aItems[$sProductId])) {
221 $oItem = $aItems[$sProductId];
222 } elseif (isset($aItems[$sItemKey])) {
223 $oItem = $aItems[$sItemKey];
225 $oItem = $this->
_createItem($sProductId, $aSelList, $aPersParams);
240 protected function _getItemKey($sProductId, $aSel = null, $aPersParam = null)
242 $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);
324 $this->_aBasketItems = null;
337 $oActivUser = $this->
getConfig()->getUser();
338 $sActivUserId = null;
340 $sActivUserId = $oActivUser->getId();
343 $blIsVisible = (bool) ($this->oxuserbaskets__oxpublic->value) ||
344 ($sActivUserId && ($this->oxuserbaskets__oxuserid->value == $sActivUserId));