basket.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Basket extends oxUBase
00010 {
00016     protected $_sThisTemplate = 'page/checkout/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 
00073     protected $_oWrappings = null;
00074 
00080     protected $_oCards = null;
00081 
00089     public function render()
00090     {
00091         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00092             $this->getSession()->getBasketReservations()->renewExpiration();
00093         }
00094 
00095         parent::render();
00096 
00097         // checks if current http client is SE and skips basket preview on success
00098         if ( oxUtils::getInstance()->isSearchEngine() ) {
00099             return $this->_sThisTemplate = $this->_sThisAltTemplate;
00100         }
00101 
00102         return $this->_sThisTemplate;
00103     }
00104 
00110     public function getBasketArticles()
00111     {
00112         if ( $this->_oBasketArticles === null) {
00113             $this->_oBasketArticles = false;
00114 
00115             // passing basket articles
00116             if ( $oBasket = $this->getSession()->getBasket() ) {
00117                 $this->_oBasketArticles = $oBasket->getBasketArticles();
00118             }
00119         }
00120         return $this->_oBasketArticles;
00121     }
00122 
00128     public function getFirstBasketProduct()
00129     {
00130         if ( $this->_oFirstBasketProduct === null ) {
00131             $this->_oFirstBasketProduct = false;
00132 
00133             $aBasketArticles = $this->getBasketArticles();
00134             if ( is_array( $aBasketArticles ) && $oProduct = reset( $aBasketArticles ) ) {
00135                 $this->_oFirstBasketProduct = $oProduct;
00136             }
00137         }
00138         return $this->_oFirstBasketProduct;
00139     }
00140 
00146     public function getBasketSimilarList()
00147     {
00148         if ( $this->_oSimilarList === null) {
00149             $this->_oSimilarList = false;
00150 
00151             // similar product info
00152             if ( $oProduct = $this->getFirstBasketProduct() ) {
00153                 $this->_oSimilarList = $oProduct->getSimilarProducts();
00154             }
00155         }
00156         return $this->_oSimilarList;
00157     }
00158 
00164     public function getSimilarRecommLists()
00165     {
00166         if (!$this->getViewConfig()->getShowListmania()) {
00167             return false;
00168         }
00169 
00170         if ( $this->_oRecommList === null) {
00171             $this->_oRecommList = false;
00172 
00173             if ( $oProduct = $this->getFirstBasketProduct() ) {
00174                 $oRecommList = oxNew('oxrecommlist');
00175                 $this->_oRecommList = $oRecommList->getRecommListsByIds( array( $oProduct->getId() ) );
00176             }
00177         }
00178         return $this->_oRecommList;
00179     }
00180 
00186     public function showBackToShop()
00187     {
00188         return ( $this->getConfig()->getConfigParam( 'iNewBasketItemMessage' ) == 3 && oxSession::hasVar( '_backtoshop' ) );
00189     }
00190 
00196     public function addVoucher()
00197     {
00198         if (!$this->getViewConfig()->getShowVouchers()) {
00199             return;
00200         }
00201 
00202         $oBasket = $this->getSession()->getBasket();
00203         $oBasket->addVoucher( oxConfig::getParameter( 'voucherNr' ) );
00204     }
00205 
00211     public function removeVoucher()
00212     {
00213         if (!$this->getViewConfig()->getShowVouchers()) {
00214             return;
00215         }
00216 
00217         $oBasket = $this->getSession()->getBasket();
00218         $oBasket->removeVoucher( oxConfig::getParameter( 'voucherId' ) );
00219     }
00220 
00228     public function backToShop()
00229     {
00230         if ( $this->getConfig()->getConfigParam( 'iNewBasketItemMessage' ) == 3 ) {
00231             if ( $sBackLink = oxSession::getVar( '_backtoshop' ) ) {
00232                 oxSession::deleteVar( '_backtoshop' );
00233                 return $sBackLink;
00234             }
00235         }
00236     }
00237 
00243     public function getErrorDestination()
00244     {
00245         return 'basket';
00246     }
00247 
00253     public function isWrapping()
00254     {
00255         if (!$this->getViewConfig()->getShowGiftWrapping() ) {
00256             return false;
00257         }
00258 
00259         if ( $this->_iWrapCnt === null ) {
00260             $this->_iWrapCnt = 0;
00261 
00262             $oWrap = oxNew( 'oxwrapping' );
00263             $this->_iWrapCnt += $oWrap->getWrappingCount( 'WRAP' );
00264             $this->_iWrapCnt += $oWrap->getWrappingCount( 'CARD' );
00265         }
00266 
00267         return (bool) $this->_iWrapCnt;
00268     }
00269 
00275     public function getWrappingList()
00276     {
00277         if ( $this->_oWrappings === null ) {
00278             $this->_oWrappings = new oxlist();
00279 
00280             // load wrapping papers
00281             if ( $this->getViewConfig()->getShowGiftWrapping() ) {
00282                 $this->_oWrappings = oxNew( 'oxwrapping' )->getWrappingList( 'WRAP' );
00283             }
00284         }
00285         return $this->_oWrappings;
00286     }
00287 
00293     public function getCardList()
00294     {
00295         if ( $this->_oCards === null ) {
00296             $this->_oCards = new oxlist();
00297 
00298             // load gift cards
00299             if ( $this->getViewConfig()->getShowGiftWrapping() ) {
00300                 $this->_oCards = oxNew( 'oxwrapping' )->getWrappingList( 'CARD' );
00301             }
00302         }
00303 
00304         return $this->_oCards;
00305     }
00306 
00317     public function changeWrapping()
00318     {
00319         $aWrapping = oxConfig::getParameter( 'wrapping' );
00320 
00321         if ( $this->getViewConfig()->getShowGiftWrapping() ) {
00322             $oBasket = $this->getSession()->getBasket();
00323             // setting wrapping info
00324             if ( is_array( $aWrapping ) && count( $aWrapping ) ) {
00325                 foreach ( $oBasket->getContents() as $sKey => $oBasketItem ) {
00326                     // wrapping ?
00327                     if ( isset( $aWrapping[$sKey] ) ) {
00328                         $oBasketItem->setWrapping( $aWrapping[$sKey] );
00329                     }
00330                 }
00331             }
00332 
00333             $oBasket->setCardMessage( oxConfig::getParameter( 'giftmessage' ) );
00334             $oBasket->setCardId( oxConfig::getParameter( 'chosencard' ) );
00335             $oBasket->onUpdate();
00336         }
00337     }
00338 
00344     public function getBreadCrumb()
00345     {
00346         $aPaths = array();
00347         $aPath = array();
00348 
00349 
00350         $aPath['title'] = oxLang::getInstance()->translateString( 'PAGE_CHECKOUT_VIEWCART', oxLang::getInstance()->getBaseLanguage(), false );
00351         $aPath['link']  = $this->getLink();
00352         $aPaths[] = $aPath;
00353 
00354         return $aPaths;
00355     }
00356 }