OXID eShop CE  4.9.7
 All Classes 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 
45  protected $_oRecommList = null;
46 
53  protected $_oFirstBasketProduct = null;
54 
61 
67  protected $_oWrappings = null;
68 
74  protected $_oCards = null;
75 
81  protected $_aSimilarRecommListIds = null;
82 
83 
91  public function render()
92  {
93  if ($this->getConfig()->getConfigParam('blPsBasketReservationEnabled')) {
94  $this->getSession()->getBasketReservations()->renewExpiration();
95  }
96 
98 
99  return $this->_sThisTemplate;
100  }
101 
107  public function getBasketArticles()
108  {
109  if ($this->_oBasketArticles === null) {
110  $this->_oBasketArticles = false;
111 
112  // passing basket articles
113  if ($oBasket = $this->getSession()->getBasket()) {
114  $this->_oBasketArticles = $oBasket->getBasketArticles();
115  }
116  }
117 
119  }
120 
126  public function getFirstBasketProduct()
127  {
128  if ($this->_oFirstBasketProduct === null) {
129  $this->_oFirstBasketProduct = false;
130 
131  $aBasketArticles = $this->getBasketArticles();
132  if (is_array($aBasketArticles) && $oProduct = reset($aBasketArticles)) {
133  $this->_oFirstBasketProduct = $oProduct;
134  }
135  }
136 
138  }
139 
145  public function getBasketSimilarList()
146  {
147  if ($this->_oSimilarList === null) {
148  $this->_oSimilarList = false;
149 
150  // similar product info
151  if ($oProduct = $this->getFirstBasketProduct()) {
152  $this->_oSimilarList = $oProduct->getSimilarProducts();
153  }
154  }
155 
156  return $this->_oSimilarList;
157  }
158 
164  public function getSimilarRecommListIds()
165  {
166  if ($this->_aSimilarRecommListIds === null) {
167  $this->_aSimilarRecommListIds = false;
168 
169  if ($oProduct = $this->getFirstBasketProduct()) {
170  $this->_aSimilarRecommListIds = array($oProduct->getId());
171  }
172  }
173 
175  }
176 
182  public function showBackToShop()
183  {
184  $iNewBasketItemMessage = $this->getConfig()->getConfigParam('iNewBasketItemMessage');
185  $sBackToShop = oxRegistry::getSession()->getVariable('_backtoshop');
186 
187  return ($iNewBasketItemMessage == 3 && $sBackToShop);
188  }
189 
195  public function addVoucher()
196  {
197  if (!$this->getViewConfig()->getShowVouchers()) {
198  return;
199  }
200 
201  $oBasket = $this->getSession()->getBasket();
202  $oBasket->addVoucher(oxRegistry::getConfig()->getRequestParameter('voucherNr'));
203  }
204 
210  public function removeVoucher()
211  {
212  if (!$this->getViewConfig()->getShowVouchers()) {
213  return;
214  }
215 
216  $oBasket = $this->getSession()->getBasket();
217  $oBasket->removeVoucher(oxRegistry::getConfig()->getRequestParameter('voucherId'));
218  }
219 
227  public function backToShop()
228  {
229  if ($this->getConfig()->getConfigParam('iNewBasketItemMessage') == 3) {
230  $oSession = oxRegistry::getSession();
231  if ($sBackLink = $oSession->getVariable('_backtoshop')) {
232  $oSession->deleteVariable('_backtoshop');
233 
234  return $sBackLink;
235  }
236  }
237  }
238 
244  public function getErrorDestination()
245  {
246  return 'basket';
247  }
248 
254  public function isWrapping()
255  {
256  if (!$this->getViewConfig()->getShowGiftWrapping()) {
257  return false;
258  }
259 
260  if ($this->_iWrapCnt === null) {
261  $this->_iWrapCnt = 0;
262 
263  $oWrap = oxNew('oxwrapping');
264  $this->_iWrapCnt += $oWrap->getWrappingCount('WRAP');
265  $this->_iWrapCnt += $oWrap->getWrappingCount('CARD');
266  }
267 
268  return (bool) $this->_iWrapCnt;
269  }
270 
276  public function getWrappingList()
277  {
278  if ($this->_oWrappings === null) {
279  $this->_oWrappings = new oxlist();
280 
281  // load wrapping papers
282  if ($this->getViewConfig()->getShowGiftWrapping()) {
283  $this->_oWrappings = oxNew('oxwrapping')->getWrappingList('WRAP');
284  }
285  }
286 
287  return $this->_oWrappings;
288  }
289 
295  public function getCardList()
296  {
297  if ($this->_oCards === null) {
298  $this->_oCards = new oxlist();
299 
300  // load gift cards
301  if ($this->getViewConfig()->getShowGiftWrapping()) {
302  $this->_oCards = oxNew('oxwrapping')->getWrappingList('CARD');
303  }
304  }
305 
306  return $this->_oCards;
307  }
308 
317  public function changeWrapping()
318  {
319  $oConfig = oxRegistry::getConfig();
320 
321  if ($this->getViewConfig()->getShowGiftWrapping()) {
322  $oBasket = $this->getSession()->getBasket();
323 
324  $this->_setWrappingInfo($oBasket, $oConfig->getRequestParameter('wrapping'));
325 
326  $oBasket->setCardMessage($oConfig->getRequestParameter('giftmessage'));
327  $oBasket->setCardId($oConfig->getRequestParameter('chosencard'));
328  $oBasket->onUpdate();
329  }
330  }
331 
337  public function getBreadCrumb()
338  {
339  $aPaths = array();
340  $aPath = array();
341 
342  $iBaseLanguage = oxRegistry::getLang()->getBaseLanguage();
343  $aPath['title'] = oxRegistry::getLang()->translateString('CART', $iBaseLanguage, false);
344  $aPath['link'] = $this->getLink();
345  $aPaths[] = $aPath;
346 
347  return $aPaths;
348  }
349 
356  {
358  $oBasketContentMarkGenerator = oxNew('oxBasketContentMarkGenerator', $this->getSession()->getBasket());
359 
360  return $oBasketContentMarkGenerator;
361  }
362 
369  protected function _setWrappingInfo($oBasket, $aWrapping)
370  {
371  if (is_array($aWrapping) && count($aWrapping)) {
372  foreach ($oBasket->getContents() as $sKey => $oBasketItem) {
373  if (isset($aWrapping[$sKey])) {
374  $oBasketItem->setWrapping($aWrapping[$sKey]);
375  }
376  }
377  }
378  }
379 }