basket.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Basket extends oxUBase
00010 {
00016     protected $_sThisTemplate = 'basket.tpl';
00017 
00023     protected $_sThisAltTemplate = 'content.tpl';
00024 
00030     protected $_blIsOrderStep = true;
00031 
00037     protected $_oBasketArticles = null;
00038 
00044     protected $_oSimilarList = null;
00045 
00051     protected $_oRecommList = null;
00052 
00059     protected $_oFirstBasketProduct = null;
00060 
00066     protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00067 
00078     public function render()
00079     {
00080         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00081             $this->getSession()->getBasketReservations()->renewExpiration();
00082         }
00083 
00084         parent::render();
00085 
00086         // checks if current http client is SE and skips basket preview on success
00087         if ( oxUtils::getInstance()->isSearchEngine() ) {
00088             return $this->_sThisTemplate = $this->_sThisAltTemplate;
00089         }
00090 
00091         //for older templates
00092         $this->_aViewData['basketitemlist']    = $this->getBasketArticles();
00093         $this->_aViewData['basketsimilarlist'] = $this->getBasketSimilarList();
00094         $this->_aViewData['similarrecommlist'] = $this->getSimilarRecommLists();
00095         $this->_aViewData['showbacktoshop']    = $this->showBackToShop();
00096 
00097 
00098         return $this->_sThisTemplate;
00099     }
00100 
00106     public function getBasketArticles()
00107     {
00108         if ( $this->_oBasketArticles === null) {
00109             $this->_oBasketArticles = false;
00110 
00111             // passing basket articles
00112             if ( $oBasket = $this->getSession()->getBasket() ) {
00113                 $this->_oBasketArticles = $oBasket->getBasketArticles();
00114             }
00115         }
00116         return $this->_oBasketArticles;
00117     }
00118 
00124     public function getFirstBasketProduct()
00125     {
00126         if ( $this->_oFirstBasketProduct === null ) {
00127             $this->_oFirstBasketProduct = false;
00128 
00129             $aBasketArticles = $this->getBasketArticles();
00130             if ( is_array( $aBasketArticles ) && $oProduct = reset( $aBasketArticles ) ) {
00131                 $this->_oFirstBasketProduct = $oProduct;
00132             }
00133         }
00134         return $this->_oFirstBasketProduct;
00135     }
00136 
00142     public function getBasketSimilarList()
00143     {
00144         if ( $this->_oSimilarList === null) {
00145             $this->_oSimilarList = false;
00146 
00147             // similar product info
00148             if ( $oProduct = $this->getFirstBasketProduct() ) {
00149                 $this->_oSimilarList = $oProduct->getSimilarProducts();
00150             }
00151         }
00152         return $this->_oSimilarList;
00153     }
00154 
00160     public function getSimilarRecommLists()
00161     {
00162         if (!$this->getViewConfig()->getShowListmania()) {
00163             return false;
00164         }
00165 
00166         if ( $this->_oRecommList === null) {
00167             $this->_oRecommList = false;
00168 
00169             if ( $oProduct = $this->getFirstBasketProduct() ) {
00170                 $oRecommList = oxNew('oxrecommlist');
00171                 $this->_oRecommList = $oRecommList->getRecommListsByIds( array( $oProduct->getId() ) );
00172             }
00173         }
00174         return $this->_oRecommList;
00175     }
00176 
00182     public function showBackToShop()
00183     {
00184         return ( $this->getConfig()->getConfigParam( 'iNewBasketItemMessage' ) == 3 && oxSession::hasVar( '_backtoshop' ) );
00185     }
00186 
00192     public function addVoucher()
00193     {
00194         if (!$this->getViewConfig()->getShowVouchers()) {
00195             return;
00196         }
00197 
00198         $oBasket = $this->getSession()->getBasket();
00199         $oBasket->addVoucher( oxConfig::getParameter( 'voucherNr' ) );
00200     }
00201 
00207     public function removeVoucher()
00208     {
00209         if (!$this->getViewConfig()->getShowVouchers()) {
00210             return;
00211         }
00212 
00213         $oBasket = $this->getSession()->getBasket();
00214         $oBasket->removeVoucher( oxConfig::getParameter( 'voucherId' ) );
00215     }
00216 
00224     public function backToShop()
00225     {
00226         if ( $this->getConfig()->getConfigParam( 'iNewBasketItemMessage' ) == 3 ) {
00227             if ( $sBackLink = oxSession::getVar( '_backtoshop' ) ) {
00228                 oxSession::deleteVar( '_backtoshop' );
00229                 return $sBackLink;
00230             }
00231         }
00232     }
00233 
00239     public function getErrorDestination()
00240     {
00241         return 'basket';
00242     }
00243 }