OXID eShop CE  4.10.4
 All Classes Namespaces Files Functions Variables Pages
basket.php
Go to the documentation of this file.
1 <?php
2 
9 class Basket extends oxUBase
10 {
11 
17  protected $_sThisTemplate = 'page/checkout/basket.tpl';
18 
24  protected $_blIsOrderStep = true;
25 
31  protected $_oBasketArticles = null;
32 
38  protected $_oSimilarList = null;
39 
47  protected $_oRecommList = null;
48 
55  protected $_oFirstBasketProduct = null;
56 
63 
69  protected $_oWrappings = null;
70 
76  protected $_oCards = null;
77 
85  protected $_aSimilarRecommListIds = null;
86 
87 
95  public function render()
96  {
97  if ($this->getConfig()->getConfigParam('blPsBasketReservationEnabled')) {
98  $this->getSession()->getBasketReservations()->renewExpiration();
99  }
100 
101  parent::render();
102 
103  return $this->_sThisTemplate;
104  }
105 
111  public function getBasketArticles()
112  {
113  if ($this->_oBasketArticles === null) {
114  $this->_oBasketArticles = false;
115 
116  // passing basket articles
117  if ($oBasket = $this->getSession()->getBasket()) {
118  $this->_oBasketArticles = $oBasket->getBasketArticles();
119  }
120  }
121 
123  }
124 
130  public function getFirstBasketProduct()
131  {
132  if ($this->_oFirstBasketProduct === null) {
133  $this->_oFirstBasketProduct = false;
134 
135  $aBasketArticles = $this->getBasketArticles();
136  if (is_array($aBasketArticles) && $oProduct = reset($aBasketArticles)) {
137  $this->_oFirstBasketProduct = $oProduct;
138  }
139  }
140 
142  }
143 
149  public function getBasketSimilarList()
150  {
151  if ($this->_oSimilarList === null) {
152  $this->_oSimilarList = false;
153 
154  // similar product info
155  if ($oProduct = $this->getFirstBasketProduct()) {
156  $this->_oSimilarList = $oProduct->getSimilarProducts();
157  }
158  }
159 
160  return $this->_oSimilarList;
161  }
162 
170  public function getSimilarRecommListIds()
171  {
172  if ($this->_aSimilarRecommListIds === null) {
173  $this->_aSimilarRecommListIds = false;
174 
175  if ($oProduct = $this->getFirstBasketProduct()) {
176  $this->_aSimilarRecommListIds = array($oProduct->getId());
177  }
178  }
179 
181  }
182 
188  public function showBackToShop()
189  {
190  $iNewBasketItemMessage = $this->getConfig()->getConfigParam('iNewBasketItemMessage');
191  $sBackToShop = oxRegistry::getSession()->getVariable('_backtoshop');
192 
193  return ($iNewBasketItemMessage == 3 && $sBackToShop);
194  }
195 
201  public function addVoucher()
202  {
203  if (!$this->getViewConfig()->getShowVouchers()) {
204  return;
205  }
206 
207  $oBasket = $this->getSession()->getBasket();
208  $oBasket->addVoucher(oxRegistry::getConfig()->getRequestParameter('voucherNr'));
209  }
210 
216  public function removeVoucher()
217  {
218  if (!$this->getViewConfig()->getShowVouchers()) {
219  return;
220  }
221 
222  $oBasket = $this->getSession()->getBasket();
223  $oBasket->removeVoucher(oxRegistry::getConfig()->getRequestParameter('voucherId'));
224  }
225 
233  public function backToShop()
234  {
235  if ($this->getConfig()->getConfigParam('iNewBasketItemMessage') == 3) {
236  $oSession = oxRegistry::getSession();
237  if ($sBackLink = $oSession->getVariable('_backtoshop')) {
238  $oSession->deleteVariable('_backtoshop');
239 
240  return $sBackLink;
241  }
242  }
243  }
244 
250  public function getErrorDestination()
251  {
252  return 'basket';
253  }
254 
260  public function isWrapping()
261  {
262  if (!$this->getViewConfig()->getShowGiftWrapping()) {
263  return false;
264  }
265 
266  if ($this->_iWrapCnt === null) {
267  $this->_iWrapCnt = 0;
268 
269  $oWrap = oxNew('oxwrapping');
270  $this->_iWrapCnt += $oWrap->getWrappingCount('WRAP');
271  $this->_iWrapCnt += $oWrap->getWrappingCount('CARD');
272  }
273 
274  return (bool) $this->_iWrapCnt;
275  }
276 
282  public function getWrappingList()
283  {
284  if ($this->_oWrappings === null) {
285  $this->_oWrappings = new oxlist();
286 
287  // load wrapping papers
288  if ($this->getViewConfig()->getShowGiftWrapping()) {
289  $this->_oWrappings = oxNew('oxwrapping')->getWrappingList('WRAP');
290  }
291  }
292 
293  return $this->_oWrappings;
294  }
295 
301  public function getCardList()
302  {
303  if ($this->_oCards === null) {
304  $this->_oCards = new oxlist();
305 
306  // load gift cards
307  if ($this->getViewConfig()->getShowGiftWrapping()) {
308  $this->_oCards = oxNew('oxwrapping')->getWrappingList('CARD');
309  }
310  }
311 
312  return $this->_oCards;
313  }
314 
323  public function changeWrapping()
324  {
325  $oConfig = oxRegistry::getConfig();
326 
327  if ($this->getViewConfig()->getShowGiftWrapping()) {
328  $oBasket = $this->getSession()->getBasket();
329 
330  $this->_setWrappingInfo($oBasket, $oConfig->getRequestParameter('wrapping'));
331 
332  $oBasket->setCardMessage($oConfig->getRequestParameter('giftmessage'));
333  $oBasket->setCardId($oConfig->getRequestParameter('chosencard'));
334  $oBasket->onUpdate();
335  }
336  }
337 
343  public function getBreadCrumb()
344  {
345  $aPaths = array();
346  $aPath = array();
347 
348  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
349  $aPath['title'] = oxRegistry::getLang()->translateString('CART', $iBaseLanguage, false);
350  $aPath['link'] = $this->getLink();
351  $aPaths[] = $aPath;
352 
353  return $aPaths;
354  }
355 
362  {
364  $oBasketContentMarkGenerator = oxNew('oxBasketContentMarkGenerator', $this->getSession()->getBasket());
365 
366  return $oBasketContentMarkGenerator;
367  }
368 
375  protected function _setWrappingInfo($oBasket, $aWrapping)
376  {
377  if (is_array($aWrapping) && count($aWrapping)) {
378  foreach ($oBasket->getContents() as $sKey => $oBasketItem) {
379  if (isset($aWrapping[$sKey])) {
380  $oBasketItem->setWrapping($aWrapping[$sKey]);
381  }
382  }
383  }
384  }
385 }