00001 <?php
00002
00008 class oxcmp_basket extends oxView
00009 {
00010
00015 protected $_blIsComponent = true;
00016
00022 public $aRedirectParams = array( 'cnid',
00023 'mnid',
00024 'anid',
00025 'tpl',
00026 'listtype',
00027 'searchcnid',
00028 'searchvendor',
00029 'searchmanufacturer',
00030 'searchtag',
00031 'searchrecomm',
00032 'recommid'
00033 );
00034
00041 public function render()
00042 {
00043
00044 $myConfig = $this->getConfig();
00045
00046 if ( $oBasket = $this->getSession()->getBasket() ) {
00047 $oBasket->calculateBasket( false );
00048 }
00049
00050 parent::render();
00051
00052 return $oBasket;
00053 }
00054
00070 public function tobasket( $sProductId = null, $dAmount = null, $aSel = null, $aPersParam = null, $blOverride = false )
00071 {
00072
00073 $myConfig = $this->getConfig();
00074 if ( oxUtils::getInstance()->isSearchEngine() ) {
00075 return;
00076 }
00077
00078
00079 if ( $aProducts = $this->_getItems( $sProductId, $dAmount, $aSel, $aPersParam, $blOverride ) ) {
00080
00081 $this->_setLastCall( 'tobasket', $aProducts, $this->getSession()->getBasket()->getBasketSummary() );
00082 $oBasketItem = $this->_addItems( $aProducts );
00083
00084
00085 if ( $oBasketItem && $myConfig->getConfigParam( 'iNewBasketItemMessage' ) != 0 ) {
00086 $oNewItem = new OxstdClass();
00087 $oNewItem->sTitle = $oBasketItem->getTitle();
00088 $oNewItem->sId = $oBasketItem->getProductId();
00089 $oNewItem->dAmount = $oBasketItem->getAmount();
00090 $oNewItem->dBundledAmount = $oBasketItem->getdBundledAmount();
00091
00092
00093 oxSession::setVar( '_newitem', $oNewItem );
00094 }
00095
00096 }
00097
00098
00099 $sReturn = $this->_getRedirectUrl();
00100
00101 return $sReturn;
00102 }
00103
00115 public function changebasket( $sProductId = null, $dAmount = null, $aSel = null, $aPersParam = null, $blOverride = true )
00116 {
00117
00118 $myConfig = $this->getConfig();
00119 if ( oxUtils::getInstance()->isSearchEngine() ) {
00120 return;
00121 }
00122
00123
00124 if (!$sProductId) {
00125 $sBasketItemId = oxConfig::getParameter( 'bindex' );
00126
00127 if ( $sBasketItemId ) {
00128 $oBasket = $this->getSession()->getBasket();
00129
00130 $aBasketContents = $oBasket->getContents();
00131 $sProductId = isset( $aBasketContents[$sBasketItemId] )?$aBasketContents[$sBasketItemId]->getProductId():null;
00132 } else {
00133 $sProductId = oxConfig::getParameter( 'aid' );
00134 }
00135 }
00136
00137
00138 $dAmount = isset( $dAmount )?$dAmount:oxConfig::getParameter( 'am' );
00139 $aSel = isset( $aSel )?$aSel:oxConfig::getParameter( 'sel' );
00140 $aPersParam = $aPersParam?$aPersParam:oxConfig::getParameter( 'persparam' );
00141
00142
00143 if ( $aProducts = $this->_getItems( $sProductId, $dAmount, $aSel, $aPersParam, $blOverride ) ) {
00144
00145
00146 $oBasket = $this->getSession()->getBasket();
00147 $oBasket->onUpdate();
00148 $this->_setLastCall( 'changebasket', $aProducts, $oBasket->getBasketSummary() );
00149
00150 $oBasketItem = $this->_addItems( $aProducts );
00151 }
00152
00153 }
00154
00169 public function wl_tobasket( $sProductId = null, $dAmount = null, $aSel = null, $aPersParam = null, $blOverride = false )
00170 {
00171
00172 $myConfig = $this->getConfig();
00173 if ( oxUtils::getInstance()->isSearchEngine() ) {
00174 return;
00175 }
00176
00177
00178 $sProductId = $sProductId?$sProductId:oxConfig::getParameter( 'aid' );
00179 $dAmount = $dAmount?$dAmount:oxConfig::getParameter( 'am' );
00180 $aSel = $aSel?$aSel:oxConfig::getParameter( 'sel' );
00181 $aPersParam = $aPersParam?$aPersParam:oxConfig::getParameter( 'persparam' );
00182
00183
00184 if ( $aProducts = $this->_getItems( $sProductId, $dAmount, $aSel, $aPersParam, $blOverride ) ) {
00185
00186 $oBasketItem = $this->_addItems( $aProducts );
00187 $oBasketItem->setWishArticleId( oxConfig::getParameter( 'anid' ) );
00188
00189
00190 $this->_setLastCall( 'tobasket', $aProducts, $this->getSession()->getBasket()->getBasketSummary() );
00191
00192
00193 $oUser = $this->getUser();
00194 $oWishUser = oxNew( 'oxuser' );
00195 $sUserId = oxConfig::getParameter( 'owishid' )?oxConfig::getParameter( 'owishid' ):oxConfig::getParameter( 'wishid' );
00196 if ( $oWishUser->load( $sUserId ) && $oUser ) {
00197
00198 $oUser->addUserAddress( $oWishUser );
00199 $oBasketItem->setWishId( $sUserId );
00200 }
00201 }
00202
00203 return $this->_getRedirectUrl();
00204 }
00205
00212 protected function _getRedirectUrl()
00213 {
00214
00215
00216 $sClass = oxConfig::getParameter( 'cl' );
00217 $sClass = $sClass?$sClass.'?':'start?';
00218 $sPosition = '';
00219
00220
00221 foreach ( $this->aRedirectParams as $sParamName ) {
00222 $sParamVal = oxConfig::getParameter( $sParamName );
00223 $sPosition .= $sParamVal?$sParamName.'='.$sParamVal.'&':'';
00224 }
00225
00226
00227
00228 $sParam = rawurlencode( oxConfig::getParameter( 'searchparam', true ) );
00229 $sPosition .= $sParam?'searchparam='.$sParam.'&':'';
00230
00231
00232 $iPageNr = (int) oxConfig::getParameter( 'pgNr' );
00233 $sPosition .= ( $iPageNr > 0 )?'pgNr='.$iPageNr.'&':'';
00234
00235
00236 if ( $this->getConfig()->getConfigParam( 'iNewBasketItemMessage' ) == 3 ) {
00237
00238
00239 oxSession::setVar( '_backtoshop', $sClass.$sPosition );
00240
00241
00242 $sClass = 'basket?';
00243 }
00244
00245 return $sClass.$sPosition;
00246 }
00247
00260 protected function _getItems( $sProductId = null, $dAmount = null, $aSel = null, $aPersParam = null, $blOverride = false )
00261 {
00262
00263 $aProducts = oxConfig::getParameter( 'aproducts' );
00264
00265
00266 $sProductId = $sProductId?$sProductId:oxConfig::getParameter( 'aid' );
00267 if ( $sProductId ) {
00268
00269
00270 $dAmount = isset( $dAmount ) ? $dAmount : oxConfig::getParameter( 'am' );
00271
00272
00273 $aSel = isset( $aSel )?$aSel:oxConfig::getParameter( 'sel' );
00274
00275
00276 $aPersParam = $aPersParam?$aPersParam:oxConfig::getParameter( 'persparam' );
00277
00278 $sBasketItemId = oxConfig::getParameter( 'bindex' );
00279
00280 $aProducts[$sProductId] = array( 'am' => $dAmount,
00281 'sel' => $aSel,
00282 'persparam' => $aPersParam,
00283 'override' => $blOverride,
00284 'basketitemid' => $sBasketItemId
00285 );
00286 }
00287
00288 if ( is_array( $aProducts ) && count( $aProducts ) ) {
00289
00290 if (oxConfig::getParameter( 'removeBtn' ) !== null) {
00291
00292 foreach ( $aProducts as $sProductId => $aProduct ) {
00293 if ( isset($aProduct['remove']) && $aProduct['remove']) {
00294 $aProducts[$sProductId]['am'] = 0;
00295 } else {
00296 unset ($aProducts[$sProductId]);
00297 }
00298 }
00299 }
00300
00301 return $aProducts;
00302 }
00303
00304 return false;
00305 }
00306
00315 protected function _addItems ( $aProducts )
00316 {
00317 $oBasket = $this->getSession()->getBasket();
00318 foreach ( $aProducts as $sProductId => $aProductInfo ) {
00319
00320
00321
00322 $sProductId = isset( $aProductInfo['aid'] ) ? $aProductInfo['aid'] : $sProductId;
00323
00324 $dAmount = isset( $aProductInfo['am'] )?$aProductInfo['am']:0;
00325 $aSelList = isset( $aProductInfo['sel'] )?$aProductInfo['sel']:null;
00326 $aPersParam = isset( $aProductInfo['persparam'] )?$aProductInfo['persparam']:null;
00327 $blOverride = isset( $aProductInfo['override'] )?$aProductInfo['override']:null;
00328 $sOldBasketItemId = isset( $aProductInfo['basketitemid'] )?$aProductInfo['basketitemid']:null;
00329
00330 try {
00331 $oBasketItem = $oBasket->addToBasket( $sProductId, $dAmount, $aSelList, $aPersParam, $blOverride, false, $sOldBasketItemId );
00332 } catch( oxOutOfStockException $oEx ) {
00333
00334 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'basket');
00335 } catch( oxArticleInputException $oEx ) {
00336
00337 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'basket');
00338 } catch( oxNoArticleException $oEx ) {
00339
00340 }
00341 }
00342
00343 return $oBasketItem;
00344 }
00345
00355 protected function _setLastCall( $sCallName, $aProductInfo, $aBasketInfo )
00356 {
00357 $aProducts = array();
00358
00359
00360 foreach ( $aProductInfo as $sProdId => $aProdData ) {
00361 $aProducts[$sProdId] = $aProdData;
00362
00363 $aProducts[$sProdId]['oldam'] = isset( $aBasketInfo->aArticles[$aProdData['aid']] ) ? $aBasketInfo->aArticles[$aProdData['aid']] : 0;
00364 }
00365
00366 oxSession::setVar( 'aLastcall', array( $sCallName => $aProducts ) );
00367 }
00368 }