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 
00087     protected $_aSimilarRecommListIds = null;
00088 
00089 
00097     public function render()
00098     {
00099         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00100             $this->getSession()->getBasketReservations()->renewExpiration();
00101         }
00102 
00103         parent::render();
00104 
00105         // checks if current http client is SE and skips basket preview on success
00106         if ( oxRegistry::getUtils()->isSearchEngine() ) {
00107             return $this->_sThisTemplate = $this->_sThisAltTemplate;
00108         }
00109 
00110         return $this->_sThisTemplate;
00111     }
00112 
00118     public function getBasketArticles()
00119     {
00120         if ( $this->_oBasketArticles === null) {
00121             $this->_oBasketArticles = false;
00122 
00123             // passing basket articles
00124             if ( $oBasket = $this->getSession()->getBasket() ) {
00125                 $this->_oBasketArticles = $oBasket->getBasketArticles();
00126             }
00127         }
00128         return $this->_oBasketArticles;
00129     }
00130 
00136     public function getFirstBasketProduct()
00137     {
00138         if ( $this->_oFirstBasketProduct === null ) {
00139             $this->_oFirstBasketProduct = false;
00140 
00141             $aBasketArticles = $this->getBasketArticles();
00142             if ( is_array( $aBasketArticles ) && $oProduct = reset( $aBasketArticles ) ) {
00143                 $this->_oFirstBasketProduct = $oProduct;
00144             }
00145         }
00146         return $this->_oFirstBasketProduct;
00147     }
00148 
00154     public function getBasketSimilarList()
00155     {
00156         if ( $this->_oSimilarList === null) {
00157             $this->_oSimilarList = false;
00158 
00159             // similar product info
00160             if ( $oProduct = $this->getFirstBasketProduct() ) {
00161                 $this->_oSimilarList = $oProduct->getSimilarProducts();
00162             }
00163         }
00164         return $this->_oSimilarList;
00165     }
00166 
00172     public function getSimilarRecommListIds()
00173     {
00174         if ( $this->_aSimilarRecommListIds === null ) {
00175             $this->_aSimilarRecommListIds = false;
00176 
00177             if ( $oProduct = $this->getFirstBasketProduct() ) {
00178                 $this->_aSimilarRecommListIds = array( $oProduct->getId() );
00179             }
00180         }
00181         return $this->_aSimilarRecommListIds;
00182     }
00183 
00189     public function showBackToShop()
00190     {
00191         return ( $this->getConfig()->getConfigParam( 'iNewBasketItemMessage' ) == 3 && oxSession::hasVar( '_backtoshop' ) );
00192     }
00193 
00199     public function addVoucher()
00200     {
00201         if (!$this->getViewConfig()->getShowVouchers()) {
00202             return;
00203         }
00204 
00205         $oBasket = $this->getSession()->getBasket();
00206         $oBasket->addVoucher( oxConfig::getParameter( 'voucherNr' ) );
00207     }
00208 
00214     public function removeVoucher()
00215     {
00216         if (!$this->getViewConfig()->getShowVouchers()) {
00217             return;
00218         }
00219 
00220         $oBasket = $this->getSession()->getBasket();
00221         $oBasket->removeVoucher( oxConfig::getParameter( 'voucherId' ) );
00222     }
00223 
00231     public function backToShop()
00232     {
00233         if ( $this->getConfig()->getConfigParam( 'iNewBasketItemMessage' ) == 3 ) {
00234             if ( $sBackLink = oxSession::getVar( '_backtoshop' ) ) {
00235                 oxSession::deleteVar( '_backtoshop' );
00236                 return $sBackLink;
00237             }
00238         }
00239     }
00240 
00246     public function getErrorDestination()
00247     {
00248         return 'basket';
00249     }
00250 
00256     public function isWrapping()
00257     {
00258         if (!$this->getViewConfig()->getShowGiftWrapping() ) {
00259             return false;
00260         }
00261 
00262         if ( $this->_iWrapCnt === null ) {
00263             $this->_iWrapCnt = 0;
00264 
00265             $oWrap = oxNew( 'oxwrapping' );
00266             $this->_iWrapCnt += $oWrap->getWrappingCount( 'WRAP' );
00267             $this->_iWrapCnt += $oWrap->getWrappingCount( 'CARD' );
00268         }
00269 
00270         return (bool) $this->_iWrapCnt;
00271     }
00272 
00278     public function getWrappingList()
00279     {
00280         if ( $this->_oWrappings === null ) {
00281             $this->_oWrappings = new oxlist();
00282 
00283             // load wrapping papers
00284             if ( $this->getViewConfig()->getShowGiftWrapping() ) {
00285                 $this->_oWrappings = oxNew( 'oxwrapping' )->getWrappingList( 'WRAP' );
00286             }
00287         }
00288         return $this->_oWrappings;
00289     }
00290 
00296     public function getCardList()
00297     {
00298         if ( $this->_oCards === null ) {
00299             $this->_oCards = new oxlist();
00300 
00301             // load gift cards
00302             if ( $this->getViewConfig()->getShowGiftWrapping() ) {
00303                 $this->_oCards = oxNew( 'oxwrapping' )->getWrappingList( 'CARD' );
00304             }
00305         }
00306 
00307         return $this->_oCards;
00308     }
00309 
00320     public function changeWrapping()
00321     {
00322         $aWrapping = oxConfig::getParameter( 'wrapping' );
00323 
00324         if ( $this->getViewConfig()->getShowGiftWrapping() ) {
00325             $oBasket = $this->getSession()->getBasket();
00326             // setting wrapping info
00327             if ( is_array( $aWrapping ) && count( $aWrapping ) ) {
00328                 foreach ( $oBasket->getContents() as $sKey => $oBasketItem ) {
00329                     // wrapping ?
00330                     if ( isset( $aWrapping[$sKey] ) ) {
00331                         $oBasketItem->setWrapping( $aWrapping[$sKey] );
00332                     }
00333                 }
00334             }
00335 
00336             $oBasket->setCardMessage( oxConfig::getParameter( 'giftmessage' ) );
00337             $oBasket->setCardId( oxConfig::getParameter( 'chosencard' ) );
00338             $oBasket->onUpdate();
00339         }
00340     }
00341 
00347     public function getBreadCrumb()
00348     {
00349         $aPaths = array();
00350         $aPath = array();
00351 
00352 
00353         $aPath['title'] = oxRegistry::getLang()->translateString( 'PAGE_CHECKOUT_VIEWCART', oxRegistry::getLang()->getBaseLanguage(), false );
00354         $aPath['link']  = $this->getLink();
00355         $aPaths[] = $aPath;
00356 
00357         return $aPaths;
00358     }
00359 }