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                                      'mnid',        // manufacturer id
00024                                      'anid',        // active article id
00025                                      'tpl',         // spec. template
00026                                      'listtype',    // list type
00027                                      'searchcnid',  // search category
00028                                      'searchvendor',// search vendor
00029                                      'searchmanufacturer',// search manufacturer
00030                                      'searchtag',   // search tag
00031                                      'searchrecomm',// search recomendation
00032                                      'recommid'     // recomm. list id
00033                                     );
00034 
00041     public function render()
00042     {
00043         // Performance
00044         $myConfig = $this->getConfig();
00045         // recalculating
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         // adding to basket is not allowed ?
00073         $myConfig = $this->getConfig();
00074         if ( oxUtils::getInstance()->isSearchEngine() ) {
00075             return;
00076         }
00077 
00078         // adding articles
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             // new basket item marker
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                 // passing article
00093                 oxSession::setVar( '_newitem', $oNewItem );
00094             }
00095 
00096         }
00097 
00098         // fetching redirect URL
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         // adding to basket is not allowed ?
00118         $myConfig = $this->getConfig();
00119         if ( oxUtils::getInstance()->isSearchEngine() ) {
00120             return;
00121         }
00122 
00123         // fetching item ID
00124         if (!$sProductId) {
00125             $sBasketItemId = oxConfig::getParameter( 'bindex' );
00126 
00127             if ( $sBasketItemId ) {
00128                 $oBasket = $this->getSession()->getBasket();
00129                 //take params
00130                 $aBasketContents = $oBasket->getContents();
00131                 $sProductId = isset( $aBasketContents[$sBasketItemId] )?$aBasketContents[$sBasketItemId]->getProductId():null;
00132             } else {
00133                 $sProductId = oxConfig::getParameter( 'aid' );
00134             }
00135         }
00136 
00137         // fetching other needed info
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         // adding articles
00143         if ( $aProducts = $this->_getItems( $sProductId, $dAmount, $aSel, $aPersParam, $blOverride ) ) {
00144 
00145             // information that last call was changebasket
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         // adding to basket is not allowed ?
00172         $myConfig = $this->getConfig();
00173         if ( oxUtils::getInstance()->isSearchEngine() ) {
00174             return;
00175         }
00176 
00177         // collecting info
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         // adding articles
00184         if ( $aProducts = $this->_getItems( $sProductId, $dAmount, $aSel, $aPersParam, $blOverride ) ) {
00185 
00186             $oBasketItem = $this->_addItems( $aProducts );
00187             $oBasketItem->setWishArticleId( oxConfig::getParameter( 'anid' ) );
00188 
00189             // information that last call was tobasket
00190             $this->_setLastCall( 'tobasket', $aProducts, $this->getSession()->getBasket()->getBasketSummary() );
00191 
00192             // fetching user info
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                 // checking if this user isn't assigned to delivery address list and if not - adding him this address
00198                 $oUser->addUserAddress( $oWishUser );
00199                 $oBasketItem->setWishId( $sUserId );
00200             }
00201         }
00202 
00203         return $this->_getRedirectUrl();
00204     }
00205 
00212     protected function _getRedirectUrl()
00213     {
00214 
00215         // active class
00216         $sClass = oxConfig::getParameter( 'cl' );
00217         $sClass = $sClass?$sClass.'?':'start?';
00218         $sPosition = '';
00219 
00220         // setting redirect parameters
00221         foreach ( $this->aRedirectParams as $sParamName ) {
00222             $sParamVal  = oxConfig::getParameter( $sParamName );
00223             $sPosition .= $sParamVal?$sParamName.'='.$sParamVal.'&':'';
00224         }
00225 
00226         // special treatment
00227         // search param
00228         $sParam     = rawurlencode( oxConfig::getParameter( 'searchparam', true ) );
00229         $sPosition .= $sParam?'searchparam='.$sParam.'&':'';
00230 
00231         // current page number
00232         $iPageNr    = (int) oxConfig::getParameter( 'pgNr' );
00233         $sPosition .= ( $iPageNr > 0 )?'pgNr='.$iPageNr.'&':'';
00234 
00235         // reload and backbutton blocker
00236         if ( $this->getConfig()->getConfigParam( 'iNewBasketItemMessage' ) == 3 ) {
00237 
00238             // saving return to shop link to session
00239             oxSession::setVar( '_backtoshop', $sClass.$sPosition );
00240 
00241             // redirecting to basket
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         // collecting items to add
00263         $aProducts = oxConfig::getParameter( 'aproducts' );
00264 
00265         // collecting specified item
00266         $sProductId = $sProductId?$sProductId:oxConfig::getParameter( 'aid' );
00267         if ( $sProductId ) {
00268 
00269             // additionally fething current product info
00270             $dAmount = isset( $dAmount ) ? $dAmount : oxConfig::getParameter( 'am' );
00271 
00272             // select lists
00273             $aSel = isset( $aSel )?$aSel:oxConfig::getParameter( 'sel' );
00274 
00275             // persistent parameters
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                 //setting amount to 0 if removing article from basket
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             // collecting input
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                 //add to display at specific position
00334                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'basket');
00335             } catch( oxArticleInputException $oEx ) {
00336                 //add to display at specific position
00337                 oxUtilsView::getInstance()->addErrorToDisplay( $oEx, false, true, 'basket');
00338             } catch( oxNoArticleException $oEx ) {
00339                 //ignored, best solution F ?
00340             }
00341         }
00342 
00343         return $oBasketItem;
00344     }
00345 
00355     protected function _setLastCall( $sCallName, $aProductInfo, $aBasketInfo )
00356     {
00357         $aProducts = array();
00358 
00359         // collecting amounts info
00360         foreach ( $aProductInfo as $sProdId => $aProdData ) {
00361             $aProducts[$sProdId] = $aProdData;
00362             // setting previous amount
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 }

Generated on Wed Apr 22 12:26:32 2009 for OXID eShop CE by  doxygen 1.5.5