OXID eShop CE  4.8.10
 All Classes Files Functions Variables Pages
basket.php
Go to the documentation of this file.
1 <?php
2 
9 class Basket extends oxUBase
10 {
16  protected $_sThisTemplate = 'page/checkout/basket.tpl';
17 
23  protected $_blIsOrderStep = true;
24 
30  protected $_oBasketArticles = null;
31 
37  protected $_oSimilarList = null;
38 
44  protected $_oRecommList = null;
45 
52  protected $_oFirstBasketProduct = null;
53 
60 
66  protected $_oWrappings = null;
67 
73  protected $_oCards = null;
74 
80  protected $_aSimilarRecommListIds = null;
81 
82 
90  public function render()
91  {
92  if ($this->getConfig()->getConfigParam( 'blPsBasketReservationEnabled' )) {
93  $this->getSession()->getBasketReservations()->renewExpiration();
94  }
95 
97 
98  return $this->_sThisTemplate;
99  }
100 
106  public function getBasketArticles()
107  {
108  if ( $this->_oBasketArticles === null) {
109  $this->_oBasketArticles = false;
110 
111  // passing basket articles
112  if ( $oBasket = $this->getSession()->getBasket() ) {
113  $this->_oBasketArticles = $oBasket->getBasketArticles();
114  }
115  }
117  }
118 
124  public function getFirstBasketProduct()
125  {
126  if ( $this->_oFirstBasketProduct === null ) {
127  $this->_oFirstBasketProduct = false;
128 
129  $aBasketArticles = $this->getBasketArticles();
130  if ( is_array( $aBasketArticles ) && $oProduct = reset( $aBasketArticles ) ) {
131  $this->_oFirstBasketProduct = $oProduct;
132  }
133  }
135  }
136 
142  public function getBasketSimilarList()
143  {
144  if ( $this->_oSimilarList === null) {
145  $this->_oSimilarList = false;
146 
147  // similar product info
148  if ( $oProduct = $this->getFirstBasketProduct() ) {
149  $this->_oSimilarList = $oProduct->getSimilarProducts();
150  }
151  }
152  return $this->_oSimilarList;
153  }
154 
160  public function getSimilarRecommListIds()
161  {
162  if ( $this->_aSimilarRecommListIds === null ) {
163  $this->_aSimilarRecommListIds = false;
164 
165  if ( $oProduct = $this->getFirstBasketProduct() ) {
166  $this->_aSimilarRecommListIds = array( $oProduct->getId() );
167  }
168  }
170  }
171 
177  public function showBackToShop()
178  {
179  return ( $this->getConfig()->getConfigParam( 'iNewBasketItemMessage' ) == 3 && oxRegistry::getSession()->getVariable( '_backtoshop' ) );
180  }
181 
187  public function addVoucher()
188  {
189  if (!$this->getViewConfig()->getShowVouchers()) {
190  return;
191  }
192 
193  $oBasket = $this->getSession()->getBasket();
194  $oBasket->addVoucher( oxRegistry::getConfig()->getRequestParameter( 'voucherNr' ) );
195  }
196 
202  public function removeVoucher()
203  {
204  if (!$this->getViewConfig()->getShowVouchers()) {
205  return;
206  }
207 
208  $oBasket = $this->getSession()->getBasket();
209  $oBasket->removeVoucher( oxRegistry::getConfig()->getRequestParameter( 'voucherId' ) );
210  }
211 
219  public function backToShop()
220  {
221  if ( $this->getConfig()->getConfigParam( 'iNewBasketItemMessage' ) == 3 ) {
222  $oSession = oxRegistry::getSession();
223  if ( $sBackLink = $oSession->getVariable( '_backtoshop' ) ) {
224  $oSession->deleteVariable( '_backtoshop' );
225  return $sBackLink;
226  }
227  }
228  }
229 
235  public function getErrorDestination()
236  {
237  return 'basket';
238  }
239 
245  public function isWrapping()
246  {
247  if (!$this->getViewConfig()->getShowGiftWrapping() ) {
248  return false;
249  }
250 
251  if ( $this->_iWrapCnt === null ) {
252  $this->_iWrapCnt = 0;
253 
254  $oWrap = oxNew( 'oxwrapping' );
255  $this->_iWrapCnt += $oWrap->getWrappingCount( 'WRAP' );
256  $this->_iWrapCnt += $oWrap->getWrappingCount( 'CARD' );
257  }
258 
259  return (bool) $this->_iWrapCnt;
260  }
261 
267  public function getWrappingList()
268  {
269  if ( $this->_oWrappings === null ) {
270  $this->_oWrappings = new oxlist();
271 
272  // load wrapping papers
273  if ( $this->getViewConfig()->getShowGiftWrapping() ) {
274  $this->_oWrappings = oxNew( 'oxwrapping' )->getWrappingList( 'WRAP' );
275  }
276  }
277  return $this->_oWrappings;
278  }
279 
285  public function getCardList()
286  {
287  if ( $this->_oCards === null ) {
288  $this->_oCards = new oxlist();
289 
290  // load gift cards
291  if ( $this->getViewConfig()->getShowGiftWrapping() ) {
292  $this->_oCards = oxNew( 'oxwrapping' )->getWrappingList( 'CARD' );
293  }
294  }
295 
296  return $this->_oCards;
297  }
298 
309  public function changeWrapping()
310  {
311  $oConfig = oxRegistry::getConfig();
312 
313  if ( $this->getViewConfig()->getShowGiftWrapping() ) {
314  $oBasket = $this->getSession()->getBasket();
315 
316  $this->_setWrappingInfo($oBasket, $oConfig->getRequestParameter( 'wrapping' ));
317 
318  $oBasket->setCardMessage( $oConfig->getRequestParameter( 'giftmessage' ) );
319  $oBasket->setCardId( $oConfig->getRequestParameter( 'chosencard' ) );
320  $oBasket->onUpdate();
321  }
322  }
323 
329  public function getBreadCrumb()
330  {
331  $aPaths = array();
332  $aPath = array();
333 
334  $aPath['title'] = oxRegistry::getLang()->translateString( 'CART', oxRegistry::getLang()->getBaseLanguage(), false );
335  $aPath['link'] = $this->getLink();
336  $aPaths[] = $aPath;
337 
338  return $aPaths;
339  }
340 
347  {
349  $oBasketContentMarkGenerator = oxNew('oxBasketContentMarkGenerator', $this->getSession()->getBasket());
350 
351  return $oBasketContentMarkGenerator;
352  }
353 
360  protected function _setWrappingInfo($oBasket, $aWrapping)
361  {
362  if ( is_array( $aWrapping ) && count( $aWrapping ) ) {
363  foreach ( $oBasket->getContents() as $sKey => $oBasketItem ) {
364  if ( isset( $aWrapping[$sKey] ) ) {
365  $oBasketItem->setWrapping( $aWrapping[$sKey] );
366  }
367  }
368  }
369  }
370 }