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 $_blIsOrderStep = true;
00024 
00030     protected $_oBasketArticles = null;
00031 
00037     protected $_oSimilarList = null;
00038 
00044     protected $_oRecommList = null;
00045 
00052     protected $_oFirstBasketProduct = null;
00053 
00059     protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00060 
00066     protected $_oWrappings = null;
00067 
00073     protected $_oCards = null;
00074 
00080     protected $_aSimilarRecommListIds = null;
00081 
00082 
00090     public function render()
00091     {
00092         if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
00093             $this->getSession()->getBasketReservations()->renewExpiration();
00094         }
00095 
00096         parent::render();
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 getSimilarRecommListIds()
00161     {
00162         if ( $this->_aSimilarRecommListIds === null ) {
00163             $this->_aSimilarRecommListIds = false;
00164 
00165             if ( $oProduct = $this->getFirstBasketProduct() ) {
00166                 $this->_aSimilarRecommListIds = array( $oProduct->getId() );
00167             }
00168         }
00169         return $this->_aSimilarRecommListIds;
00170     }
00171 
00177     public function showBackToShop()
00178     {
00179         return ( $this->getConfig()->getConfigParam( 'iNewBasketItemMessage' ) == 3 && oxRegistry::getSession()->getVariable( '_backtoshop' ) );
00180     }
00181 
00187     public function addVoucher()
00188     {
00189         if (!$this->getViewConfig()->getShowVouchers()) {
00190             return;
00191         }
00192 
00193         $oBasket = $this->getSession()->getBasket();
00194         $oBasket->addVoucher( oxRegistry::getConfig()->getRequestParameter( 'voucherNr' ) );
00195     }
00196 
00202     public function removeVoucher()
00203     {
00204         if (!$this->getViewConfig()->getShowVouchers()) {
00205             return;
00206         }
00207 
00208         $oBasket = $this->getSession()->getBasket();
00209         $oBasket->removeVoucher( oxRegistry::getConfig()->getRequestParameter( 'voucherId' ) );
00210     }
00211 
00219     public function backToShop()
00220     {
00221         if ( $this->getConfig()->getConfigParam( 'iNewBasketItemMessage' ) == 3 ) {
00222             $oSession = oxRegistry::getSession();
00223             if ( $sBackLink = $oSession->getVariable( '_backtoshop' ) ) {
00224                 $oSession->deleteVariable( '_backtoshop' );
00225                 return $sBackLink;
00226             }
00227         }
00228     }
00229 
00235     public function getErrorDestination()
00236     {
00237         return 'basket';
00238     }
00239 
00245     public function isWrapping()
00246     {
00247         if (!$this->getViewConfig()->getShowGiftWrapping() ) {
00248             return false;
00249         }
00250 
00251         if ( $this->_iWrapCnt === null ) {
00252             $this->_iWrapCnt = 0;
00253 
00254             $oWrap = oxNew( 'oxwrapping' );
00255             $this->_iWrapCnt += $oWrap->getWrappingCount( 'WRAP' );
00256             $this->_iWrapCnt += $oWrap->getWrappingCount( 'CARD' );
00257         }
00258 
00259         return (bool) $this->_iWrapCnt;
00260     }
00261 
00267     public function getWrappingList()
00268     {
00269         if ( $this->_oWrappings === null ) {
00270             $this->_oWrappings = new oxlist();
00271 
00272             // load wrapping papers
00273             if ( $this->getViewConfig()->getShowGiftWrapping() ) {
00274                 $this->_oWrappings = oxNew( 'oxwrapping' )->getWrappingList( 'WRAP' );
00275             }
00276         }
00277         return $this->_oWrappings;
00278     }
00279 
00285     public function getCardList()
00286     {
00287         if ( $this->_oCards === null ) {
00288             $this->_oCards = new oxlist();
00289 
00290             // load gift cards
00291             if ( $this->getViewConfig()->getShowGiftWrapping() ) {
00292                 $this->_oCards = oxNew( 'oxwrapping' )->getWrappingList( 'CARD' );
00293             }
00294         }
00295 
00296         return $this->_oCards;
00297     }
00298 
00309     public function changeWrapping()
00310     {
00311         $oConfig = oxRegistry::getConfig();
00312 
00313         if ( $this->getViewConfig()->getShowGiftWrapping() ) {
00314             $oBasket = $this->getSession()->getBasket();
00315 
00316             $this->_setWrappingInfo($oBasket, $oConfig->getRequestParameter( 'wrapping' ));
00317 
00318             $oBasket->setCardMessage( $oConfig->getRequestParameter( 'giftmessage' ) );
00319             $oBasket->setCardId( $oConfig->getRequestParameter( 'chosencard' ) );
00320             $oBasket->onUpdate();
00321         }
00322     }
00323 
00329     public function getBreadCrumb()
00330     {
00331         $aPaths = array();
00332         $aPath = array();
00333 
00334         $aPath['title'] = oxRegistry::getLang()->translateString( 'CART', oxRegistry::getLang()->getBaseLanguage(), false );
00335         $aPath['link']  = $this->getLink();
00336         $aPaths[] = $aPath;
00337 
00338         return $aPaths;
00339     }
00340 
00346     public function getBasketContentMarkGenerator()
00347     {
00349         $oBasketContentMarkGenerator = oxNew('oxBasketContentMarkGenerator', $this->getSession()->getBasket());
00350 
00351         return $oBasketContentMarkGenerator;
00352     }
00353 
00360     protected function _setWrappingInfo($oBasket, $aWrapping)
00361     {
00362         if ( is_array( $aWrapping ) && count( $aWrapping ) ) {
00363             foreach ( $oBasket->getContents() as $sKey => $oBasketItem ) {
00364                 if ( isset( $aWrapping[$sKey] ) ) {
00365                     $oBasketItem->setWrapping( $aWrapping[$sKey] );
00366                 }
00367             }
00368         }
00369     }
00370 }