00001 <?php
00002
00008 class oxcmp_basket extends oxView
00009 {
00010
00015 protected $_blIsComponent = true;
00016
00022 public $aRedirectParams = array( 'cnid',
00023 'anid',
00024 'tpl',
00025 'listtype',
00026 'searchcnid',
00027 'searchvendor',
00028 'searchtag',
00029 'searchrecomm',
00030 'recommid'
00031 );
00032
00039 public function render()
00040 {
00041
00042 $myConfig = $this->getConfig();
00043
00044 if ( $oBasket = $this->getSession()->getBasket() ) {
00045 $oBasket->calculateBasket( false );
00046 }
00047
00048 parent::render();
00049
00050 return $oBasket;
00051 }
00052
00068 public function tobasket( $sProductId = null, $dAmount = null, $aSel = null, $aPersParam = null, $blOverride = false )
00069 {
00070
00071 $myConfig = $this->getConfig();
00072 if ( oxUtils::getInstance()->isSearchEngine() ) {
00073 return;
00074 }
00075
00076
00077 if ( $aProducts = $this->_getItems( $sProductId, $dAmount, $aSel, $aPersParam, $blOverride ) ) {
00078
00079 $this->_setLastCall( 'tobasket', $aProducts, $this->getSession()->getBasket()->getBasketSummary() );
00080 $oBasketItem = $this->_addItems( $aProducts );
00081
00082
00083 if ( $oBasketItem && $myConfig->getConfigParam( 'iNewBasketItemMessage' ) != 0 ) {
00084 $oNewItem = new OxstdClass();
00085 $oNewItem->sTitle = $oBasketItem->getTitle();
00086 $oNewItem->sId = $oBasketItem->getProductId();
00087 $oNewItem->dAmount = $oBasketItem->getAmount();
00088 $oNewItem->dBundledAmount = $oBasketItem->getdBundledAmount();
00089
00090
00091 oxSession::setVar( '_newitem', $oNewItem );
00092 }
00093
00094 }
00095
00096
00097 $sReturn = $this->_getRedirectUrl();
00098
00099 return $sReturn;
00100 }
00101
00113 public function changebasket( $sProductId = null, $dAmount = null, $aSel = null, $aPersParam = null, $blOverride = true )
00114 {
00115
00116 $myConfig = $this->getConfig();
00117 if ( oxUtils::getInstance()->isSearchEngine() ) {
00118 return;
00119 }
00120
00121
00122 if (!$sProductId) {
00123 $sBasketItemId = oxConfig::getParameter( 'bindex' );
00124
00125 if ( $sBasketItemId ) {
00126 $oBasket = $this->getSession()->getBasket();
00127
00128 $aBasketContents = $oBasket->getContents();
00129 $sProductId = isset( $aBasketContents[$sBasketItemId] )?$aBasketContents[$sBasketItemId]->getProductId():null;
00130 } else {
00131 $sProductId = oxConfig::getParameter( 'aid' );
00132 }
00133 }
00134
00135
00136 $dAmount = isset( $dAmount )?$dAmount:oxConfig::getParameter( 'am' );
00137 $aSel = isset( $aSel )?$aSel:oxConfig::getParameter( 'sel' );
00138 $aPersParam = $aPersParam?$aPersParam:oxConfig::getParameter( 'persparam' );
00139
00140
00141 if ( $aProducts = $this->_getItems( $sProductId, $dAmount, $aSel, $aPersParam, $blOverride ) ) {
00142
00143
00144 $this->_setLastCall( 'changebasket', $aProducts, $this->getSession()->getBasket()->getBasketSummary() );
00145 $oBasketItem = $this->_addItems( $aProducts );
00146 }
00147
00148 }
00149
00164 public function wl_tobasket( $sProductId = null, $dAmount = null, $aSel = null, $aPersParam = null, $blOverride = false )
00165 {
00166
00167 $myConfig = $this->getConfig();
00168 if ( oxUtils::getInstance()->isSearchEngine() ) {
00169 return;
00170 }
00171
00172
00173 $sProductId = $sProductId?$sProductId:oxConfig::getParameter( 'aid' );
00174 $dAmount = $dAmount?$dAmount:oxConfig::getParameter( 'am' );
00175 $aSel = $aSel?$aSel:oxConfig::getParameter( 'sel' );
00176 $aPersParam = $aPersParam?$aPersParam:oxConfig::getParameter( 'persparam' );
00177
00178
00179 if ( $aProducts = $this->_getItems( $sProductId, $dAmount, $aSel, $aPersParam, $blOverride ) ) {
00180
00181 $oBasketItem = $this->_addItems( $aProducts );
00182 $oBasketItem->setWishArticleId( oxConfig::getParameter( 'anid' ) );
00183
00184
00185 $this->_setLastCall( 'tobasket', $aProducts, $this->getSession()->getBasket()->getBasketSummary() );
00186
00187
00188 $oUser = $this->getUser();
00189 $oWishUser = oxNew( 'oxuser' );
00190 $sUserId = oxConfig::getParameter( 'owishid' )?oxConfig::getParameter( 'owishid' ):oxConfig::getParameter( 'wishid' );
00191 if ( $oWishUser->load( $sUserId ) && $oUser ) {
00192
00193 $oUser->addUserAddress( $oWishUser );
00194 $oBasketItem->setWishId( $sUserId );
00195 }
00196 }
00197
00198 return $this->_getRedirectUrl();
00199 }
00200
00207 protected function _getRedirectUrl()
00208 {
00209
00210
00211 $sClass = oxConfig::getParameter( 'cl' );
00212 $sClass = $sClass?$sClass.'?':'start?';
00213 $sPosition = '';
00214
00215
00216 foreach ( $this->aRedirectParams as $sParamName ) {
00217 $sParamVal = oxConfig::getParameter( $sParamName );
00218 $sPosition .= $sParamVal?$sParamName.'='.$sParamVal.'&':'';
00219 }
00220
00221
00222
00223 $sParam = rawurlencode( oxConfig::getParameter( 'searchparam', true ) );
00224 $sPosition .= $sParam?'searchparam='.$sParam.'&':'';
00225
00226
00227 $iPageNr = (int) oxConfig::getParameter( 'pgNr' );
00228 $sPosition .= ( $iPageNr > 0 )?'pgNr='.$iPageNr.'&':'';
00229
00230
00231 return $sClass.$sPosition;
00232 }
00233
00246 protected function _getItems( $sProductId = null, $dAmount = null, $aSel = null, $aPersParam = null, $blOverride = false )
00247 {
00248
00249 $aProducts = oxConfig::getParameter( 'aproducts' );
00250
00251
00252 $sProductId = $sProductId?$sProductId:oxConfig::getParameter( 'aid' );
00253 if ( $sProductId ) {
00254
00255
00256 $dAmount = isset( $dAmount ) ? $dAmount : oxConfig::getParameter( 'am' );
00257
00258
00259 $aSel = isset( $aSel )?$aSel:oxConfig::getParameter( 'sel' );
00260
00261
00262 $aPersParam = $aPersParam?$aPersParam:oxConfig::getParameter( 'persparam' );
00263
00264 $sBasketItemId = oxConfig::getParameter( 'bindex' );
00265
00266 $aProducts[$sProductId] = array( 'am' => $dAmount,
00267 'sel' => $aSel,
00268 'persparam' => $aPersParam,
00269 'override' => $blOverride,
00270 'basketitemid' => $sBasketItemId
00271 );
00272 }
00273
00274 if ( is_array( $aProducts ) && count( $aProducts ) ) {
00275
00276 if (oxConfig::getParameter( 'removeBtn' ) !== null) {
00277
00278 foreach( $aProducts as $sProductId => $aProduct ) {
00279 if (isset($aProduct['remove']) && $aProduct['remove']) {
00280 $aProducts[$sProductId]['am'] = 0;
00281 } else {
00282 unset ($aProducts[$sProductId]);
00283 }
00284 }
00285 }
00286
00287 return $aProducts;
00288 }
00289
00290 return false;
00291 }
00292
00301 protected function _addItems ( $aProducts )
00302 {
00303 $oBasket = $this->getSession()->getBasket();
00304 foreach ( $aProducts as $sProductId => $aProductInfo ) {
00305
00306
00307
00308 $sProductId = isset( $aProductInfo['aid'] ) ? $aProductInfo['aid'] : $sProductId;
00309
00310 $dAmount = isset( $aProductInfo['am'] )?$aProductInfo['am']:0;
00311 $aSelList = isset( $aProductInfo['sel'] )?$aProductInfo['sel']:null;
00312 $aPersParam = isset( $aProductInfo['persparam'] )?$aProductInfo['persparam']:null;
00313 $blOverride = isset( $aProductInfo['override'] )?$aProductInfo['override']:null;
00314 $sOldBasketItemId = isset( $aProductInfo['basketitemid'] )?$aProductInfo['basketitemid']:null;
00315
00316 try {
00317 $oBasketItem = $oBasket->addToBasket( $sProductId, $dAmount, $aSelList, $aPersParam, $blOverride, false, $sOldBasketItemId );
00318 } catch( oxOutOfStockException $oEx ) {
00319
00320 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'basket');
00321 } catch( oxArticleInputException $oEx ) {
00322
00323 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'basket');
00324 } catch( oxNoArticleException $oEx ) {
00325
00326 }
00327 }
00328
00329 return $oBasketItem;
00330 }
00331
00339 protected function _setLastCall( $sCallName, $aProductInfo, $aBasketInfo )
00340 {
00341 $aProducts = array();
00342
00343
00344 foreach ( $aProductInfo as $sProdId => $aProdData ) {
00345 $aProducts[$sProdId] = $aProdData;
00346
00347 $aProducts[$sProdId]['oldam'] = isset( $aBasketInfo->aArticles[$sProdId] ) ? $aBasketInfo->aArticles[$sProdId] : 0;
00348 }
00349
00350 oxSession::setVar( 'aLastcall', array( $sCallName => $aProducts ) );
00351 }
00352 }