basket.php

Go to the documentation of this file.
00001 <?php
00002 
00009 class Basket extends oxUBase
00010 {
00011 
00017     protected $_sThisTemplate = 'page/checkout/basket.tpl';
00018 
00024     protected $_blIsOrderStep = true;
00025 
00031     protected $_oBasketArticles = null;
00032 
00038     protected $_oSimilarList = null;
00039 
00045     protected $_oRecommList = null;
00046 
00053     protected $_oFirstBasketProduct = null;
00054 
00060     protected $_iViewIndexState = VIEW_INDEXSTATE_NOINDEXNOFOLLOW;
00061 
00067     protected $_oWrappings = null;
00068 
00074     protected $_oCards = null;
00075 
00081     protected $_aSimilarRecommListIds = null;
00082 
00083 
00091     public function render()
00092     {
00093         if ($this->getConfig()->getConfigParam('blPsBasketReservationEnabled')) {
00094             $this->getSession()->getBasketReservations()->renewExpiration();
00095         }
00096 
00097         parent::render();
00098 
00099         return $this->_sThisTemplate;
00100     }
00101 
00107     public function getBasketArticles()
00108     {
00109         if ($this->_oBasketArticles === null) {
00110             $this->_oBasketArticles = false;
00111 
00112             // passing basket articles
00113             if ($oBasket = $this->getSession()->getBasket()) {
00114                 $this->_oBasketArticles = $oBasket->getBasketArticles();
00115             }
00116         }
00117 
00118         return $this->_oBasketArticles;
00119     }
00120 
00126     public function getFirstBasketProduct()
00127     {
00128         if ($this->_oFirstBasketProduct === null) {
00129             $this->_oFirstBasketProduct = false;
00130 
00131             $aBasketArticles = $this->getBasketArticles();
00132             if (is_array($aBasketArticles) && $oProduct = reset($aBasketArticles)) {
00133                 $this->_oFirstBasketProduct = $oProduct;
00134             }
00135         }
00136 
00137         return $this->_oFirstBasketProduct;
00138     }
00139 
00145     public function getBasketSimilarList()
00146     {
00147         if ($this->_oSimilarList === null) {
00148             $this->_oSimilarList = false;
00149 
00150             // similar product info
00151             if ($oProduct = $this->getFirstBasketProduct()) {
00152                 $this->_oSimilarList = $oProduct->getSimilarProducts();
00153             }
00154         }
00155 
00156         return $this->_oSimilarList;
00157     }
00158 
00164     public function getSimilarRecommListIds()
00165     {
00166         if ($this->_aSimilarRecommListIds === null) {
00167             $this->_aSimilarRecommListIds = false;
00168 
00169             if ($oProduct = $this->getFirstBasketProduct()) {
00170                 $this->_aSimilarRecommListIds = array($oProduct->getId());
00171             }
00172         }
00173 
00174         return $this->_aSimilarRecommListIds;
00175     }
00176 
00182     public function showBackToShop()
00183     {
00184         $iNewBasketItemMessage = $this->getConfig()->getConfigParam('iNewBasketItemMessage');
00185         $sBackToShop = oxRegistry::getSession()->getVariable('_backtoshop');
00186 
00187         return ($iNewBasketItemMessage == 3 && $sBackToShop);
00188     }
00189 
00195     public function addVoucher()
00196     {
00197         if (!$this->getViewConfig()->getShowVouchers()) {
00198             return;
00199         }
00200 
00201         $oBasket = $this->getSession()->getBasket();
00202         $oBasket->addVoucher(oxRegistry::getConfig()->getRequestParameter('voucherNr'));
00203     }
00204 
00210     public function removeVoucher()
00211     {
00212         if (!$this->getViewConfig()->getShowVouchers()) {
00213             return;
00214         }
00215 
00216         $oBasket = $this->getSession()->getBasket();
00217         $oBasket->removeVoucher(oxRegistry::getConfig()->getRequestParameter('voucherId'));
00218     }
00219 
00227     public function backToShop()
00228     {
00229         if ($this->getConfig()->getConfigParam('iNewBasketItemMessage') == 3) {
00230             $oSession = oxRegistry::getSession();
00231             if ($sBackLink = $oSession->getVariable('_backtoshop')) {
00232                 $oSession->deleteVariable('_backtoshop');
00233 
00234                 return $sBackLink;
00235             }
00236         }
00237     }
00238 
00244     public function getErrorDestination()
00245     {
00246         return 'basket';
00247     }
00248 
00254     public function isWrapping()
00255     {
00256         if (!$this->getViewConfig()->getShowGiftWrapping()) {
00257             return false;
00258         }
00259 
00260         if ($this->_iWrapCnt === null) {
00261             $this->_iWrapCnt = 0;
00262 
00263             $oWrap = oxNew('oxwrapping');
00264             $this->_iWrapCnt += $oWrap->getWrappingCount('WRAP');
00265             $this->_iWrapCnt += $oWrap->getWrappingCount('CARD');
00266         }
00267 
00268         return (bool) $this->_iWrapCnt;
00269     }
00270 
00276     public function getWrappingList()
00277     {
00278         if ($this->_oWrappings === null) {
00279             $this->_oWrappings = new oxlist();
00280 
00281             // load wrapping papers
00282             if ($this->getViewConfig()->getShowGiftWrapping()) {
00283                 $this->_oWrappings = oxNew('oxwrapping')->getWrappingList('WRAP');
00284             }
00285         }
00286 
00287         return $this->_oWrappings;
00288     }
00289 
00295     public function getCardList()
00296     {
00297         if ($this->_oCards === null) {
00298             $this->_oCards = new oxlist();
00299 
00300             // load gift cards
00301             if ($this->getViewConfig()->getShowGiftWrapping()) {
00302                 $this->_oCards = oxNew('oxwrapping')->getWrappingList('CARD');
00303             }
00304         }
00305 
00306         return $this->_oCards;
00307     }
00308 
00317     public function changeWrapping()
00318     {
00319         $oConfig = oxRegistry::getConfig();
00320 
00321         if ($this->getViewConfig()->getShowGiftWrapping()) {
00322             $oBasket = $this->getSession()->getBasket();
00323 
00324             $this->_setWrappingInfo($oBasket, $oConfig->getRequestParameter('wrapping'));
00325 
00326             $oBasket->setCardMessage($oConfig->getRequestParameter('giftmessage'));
00327             $oBasket->setCardId($oConfig->getRequestParameter('chosencard'));
00328             $oBasket->onUpdate();
00329         }
00330     }
00331 
00337     public function getBreadCrumb()
00338     {
00339         $aPaths = array();
00340         $aPath = array();
00341 
00342         $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
00343         $aPath['title'] = oxRegistry::getLang()->translateString('CART', $iBaseLanguage, false);
00344         $aPath['link']  = $this->getLink();
00345         $aPaths[] = $aPath;
00346 
00347         return $aPaths;
00348     }
00349 
00355     public function getBasketContentMarkGenerator()
00356     {
00358         $oBasketContentMarkGenerator = oxNew('oxBasketContentMarkGenerator', $this->getSession()->getBasket());
00359 
00360         return $oBasketContentMarkGenerator;
00361     }
00362 
00369     protected function _setWrappingInfo($oBasket, $aWrapping)
00370     {
00371         if (is_array($aWrapping) && count($aWrapping)) {
00372             foreach ($oBasket->getContents() as $sKey => $oBasketItem) {
00373                 if (isset($aWrapping[$sKey])) {
00374                     $oBasketItem->setWrapping($aWrapping[$sKey]);
00375                 }
00376             }
00377         }
00378     }
00379 }