oxcmp_basket.php

Go to the documentation of this file.
00001 <?php
00002 
00008 class oxcmp_basket extends oxView
00009 {
00010 
00015     protected $_blIsComponent = true;
00016 
00022     public $aRedirectParams = array( 'cnid',        // category id
00023                                      'anid',        // active article id
00024                                      'tpl',         // spec. template
00025                                      'listtype',    // list type
00026                                      'searchcnid',  // search category
00027                                      'searchvendor',// search vendor
00028                                      'searchtag',   // search vendor
00029                                      'searchrecomm',// search vendor
00030                                      'recommid'     // recomm. list id
00031                                     );
00032 
00039     public function render()
00040     {
00041         // Performance
00042         $myConfig = $this->getConfig();
00043         // recalculating
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         // adding to basket is not allowed ?
00071         $myConfig = $this->getConfig();
00072         if ( oxUtils::getInstance()->isSearchEngine() ) {
00073             return;
00074         }
00075 
00076         // adding articles
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             // new basket item marker
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                 // passing article
00091                 oxSession::setVar( '_newitem', $oNewItem );
00092             }
00093 
00094         }
00095 
00096         // fetching redirect URL
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         // adding to basket is not allowed ?
00116         $myConfig = $this->getConfig();
00117         if ( oxUtils::getInstance()->isSearchEngine() ) {
00118             return;
00119         }
00120 
00121         // fetching item ID
00122         if (!$sProductId) {
00123             $sBasketItemId = oxConfig::getParameter( 'bindex' );
00124 
00125             if ( $sBasketItemId ) {
00126                 $oBasket = $this->getSession()->getBasket();
00127                 //take params
00128                 $aBasketContents = $oBasket->getContents();
00129                 $sProductId = isset( $aBasketContents[$sBasketItemId] )?$aBasketContents[$sBasketItemId]->getProductId():null;
00130             } else {
00131                 $sProductId = oxConfig::getParameter( 'aid' );
00132             }
00133         }
00134 
00135         // fetching other needed info
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         // adding articles
00141         if ( $aProducts = $this->_getItems( $sProductId, $dAmount, $aSel, $aPersParam, $blOverride ) ) {
00142 
00143             // information that last call was changebasket
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         // adding to basket is not allowed ?
00167         $myConfig = $this->getConfig();
00168         if ( oxUtils::getInstance()->isSearchEngine() ) {
00169             return;
00170         }
00171 
00172         // collecting info
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         // adding articles
00179         if ( $aProducts = $this->_getItems( $sProductId, $dAmount, $aSel, $aPersParam, $blOverride ) ) {
00180 
00181             $oBasketItem = $this->_addItems( $aProducts );
00182             $oBasketItem->setWishArticleId( oxConfig::getParameter( 'anid' ) );
00183 
00184             // information that last call was tobasket
00185             $this->_setLastCall( 'tobasket', $aProducts, $this->getSession()->getBasket()->getBasketSummary() );
00186 
00187             // fetching user info
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                 // checking if this user isn't assigned to delivery address list and if not - adding him this address
00193                 $oUser->addUserAddress( $oWishUser );
00194                 $oBasketItem->setWishId( $sUserId );
00195             }
00196         }
00197 
00198         return $this->_getRedirectUrl();
00199     }
00200 
00207     protected function _getRedirectUrl()
00208     {
00209 
00210         // active class
00211         $sClass = oxConfig::getParameter( 'cl' );
00212         $sClass = $sClass?$sClass.'?':'start?';
00213         $sPosition = '';
00214 
00215         // setting redirect parameters
00216         foreach ( $this->aRedirectParams as $sParamName ) {
00217             $sParamVal  = oxConfig::getParameter( $sParamName );
00218             $sPosition .= $sParamVal?$sParamName.'='.$sParamVal.'&':'';
00219         }
00220 
00221         // special treatment
00222         // search param
00223         $sParam     = rawurlencode( oxConfig::getParameter( 'searchparam', true ) );
00224         $sPosition .= $sParam?'searchparam='.$sParam.'&':'';
00225 
00226         // current page number
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         // collecting items to add
00249         $aProducts = oxConfig::getParameter( 'aproducts' );
00250 
00251         // collecting specified item
00252         $sProductId = $sProductId?$sProductId:oxConfig::getParameter( 'aid' );
00253         if ( $sProductId ) {
00254 
00255             // additionally fething current product info
00256             $dAmount = isset( $dAmount ) ? $dAmount : oxConfig::getParameter( 'am' );
00257 
00258             // select lists
00259             $aSel = isset( $aSel )?$aSel:oxConfig::getParameter( 'sel' );
00260 
00261             // persistent parameters
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                 //setting amount to 0 if removing article from basket
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             // collecting input
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                 //add to display at specific position
00320                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'basket');
00321             } catch( oxArticleInputException $oEx ) {
00322                 //add to display at specific position
00323                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'basket');
00324             } catch( oxNoArticleException $oEx ) {
00325                 //ignored, best solution F ?
00326             }
00327         }
00328 
00329         return $oBasketItem;
00330     }
00331 
00339     protected function _setLastCall( $sCallName, $aProductInfo, $aBasketInfo )
00340     {
00341         $aProducts = array();
00342 
00343         // collecting amounts info
00344         foreach ( $aProductInfo as $sProdId => $aProdData ) {
00345             $aProducts[$sProdId] = $aProdData;
00346             // setting previous amount
00347             $aProducts[$sProdId]['oldam'] = isset( $aBasketInfo->aArticles[$sProdId] ) ? $aBasketInfo->aArticles[$sProdId] : 0;
00348         }
00349 
00350         oxSession::setVar( 'aLastcall', array( $sCallName => $aProducts ) );
00351     }
00352 }

Generated on Thu Dec 4 12:04:57 2008 for OXID eShop CE by  doxygen 1.5.5