47 $oReservations =
oxNew(
'oxuserbasket' );
48 $aWhere = array(
'oxuserbaskets.oxuserid' => $sBasketId,
'oxuserbaskets.oxtitle' =>
'reservations' );
51 if ( !$oReservations->assignRecord( $oReservations->buildSelectString( $aWhere ) ) ) {
52 $oReservations->oxuserbaskets__oxtitle =
new oxField(
'reservations');
53 $oReservations->oxuserbaskets__oxuserid =
new oxField($sBasketId);
55 $oReservations->setIsNewBasket();
57 return $oReservations;
67 if ($this->_oReservations) {
87 if (isset($this->_aCurrentlyReserved)) {
96 $this->_aCurrentlyReserved = array();
97 foreach ( $oReserved->getItems(
false,
false) as $oItem ) {
98 if (!isset($this->_aCurrentlyReserved[$oItem->oxuserbasketitems__oxartid->value])) {
99 $this->_aCurrentlyReserved[$oItem->oxuserbasketitems__oxartid->value] = 0;
101 $this->_aCurrentlyReserved[$oItem->oxuserbasketitems__oxartid->value] += $oItem->oxuserbasketitems__oxamount->value;
116 if (isset($aCurrentlyReserved[$sArticleId])) {
117 return $aCurrentlyReserved[$sArticleId];
134 $sProdId = $oItem->getProductId();
135 if (!isset($aDiff[$sProdId])) {
136 $aDiff[$sProdId] = -$oItem->getAmount();
138 $aDiff[$sProdId] -= $oItem->getAmount();
155 $blAllowNegativeStock = $this->
getConfig()->getConfigParam(
'blAllowNegativeStock' );
158 foreach ($aBasketDiff as $sId => $dAmount) {
160 $oArticle =
oxNew(
'oxarticle');
161 if ($oArticle->load($sId)) {
162 $oArticle->reduceStock(-$dAmount, $blAllowNegativeStock);
163 $oReserved->addItemToBasket( $sId, -$dAmount );
167 $this->_aCurrentlyReserved = null;
196 if ($dReserved < $dAmount) {
197 $dAmount = $dReserved;
200 $oArticle =
oxNew(
'oxarticle' );
201 $oArticle->load( $sArticleId );
204 $oArticle->beforeUpdate();
205 $oArticle->updateSoldAmount( $dAmount );
206 $this->_aCurrentlyReserved = null;
221 $oArticle =
oxNew(
'oxarticle');
222 if ($oArticle->load($sArticleId)) {
223 $oArticle->reduceStock(-$dReserved,
true);
225 $this->_aCurrentlyReserved = null;
240 if ($this->_oReservations) {
241 $this->_oReservations->delete();
242 $this->_oReservations = null;
243 $this->_aCurrentlyReserved = null;
258 $iStartTime =
oxRegistry::get(
"oxUtilsDate")->getTime() - (int) $this->
getConfig()->getConfigParam(
'iPsBasketReservationTimeout' );
259 $oRs = $oDb->select(
"select oxid from oxuserbaskets where oxtitle = 'reservations' and oxupdate <= $iStartTime limit $iLimit",
false,
false);
263 $aFinished = array();
265 $aFinished[] = $oDb->quote($oRs->fields[
'oxid']);
268 $oRs = $oDb->select(
"select oxartid, oxamount from oxuserbasketitems where oxbasketid in (".implode(
",", $aFinished).
")",
false,
false );
270 $oArticle =
oxNew(
'oxarticle');
271 if ($oArticle->load($oRs->fields[
'oxartid'])) {
272 $oArticle->reduceStock(-$oRs->fields[
'oxamount'],
true);
276 $oDb->execute(
"delete from oxuserbasketitems where oxbasketid in (".implode(
",", $aFinished).
")");
277 $oDb->execute(
"delete from oxuserbaskets where oxid in (".implode(
",", $aFinished).
")");
280 $oDb->execute(
"delete from oxuserbaskets where oxtitle = 'savedbasket' and oxupdate <= $iStartTime");
282 $this->_aCurrentlyReserved = null;
292 $iTimeout = $this->
getConfig()->getConfigParam(
'iPsBasketReservationTimeout' );
293 if ( $iTimeout > 0 ) {
295 if ( $oRev && $oRev->getId() ) {
296 $iTimeout -= (
oxRegistry::get(
"oxUtilsDate")->getTime() - (int) $oRev->oxuserbaskets__oxupdate->value );
297 oxSession::setVar(
"iBasketReservationTimeout", $oRev->oxuserbaskets__oxupdate->value );
298 } elseif ( ( $iSessionTimeout =
oxSession::getVar(
"iBasketReservationTimeout" ) ) ) {
299 $iTimeout -= (
oxRegistry::get(
"oxUtilsDate")->getTime() - (int) $iSessionTimeout );
302 return $iTimeout < 0 ? 0 : $iTimeout;
316 $oReserved->oxuserbaskets__oxupdate =
new oxField( $iTime );