OXID eShop CE  4.9.10
 All Classes Files Functions Variables Pages
compare.php
Go to the documentation of this file.
1 <?php
2 
7 class Compare extends oxUBase
8 {
9 
15  protected $_iCntPages = 1;
16 
22  protected $_iOrderCnt = null;
23 
29  protected $_iArticlesPerPage = 3;
30 
36  protected $_iCompItemsCnt = null;
37 
43  protected $_aCompItems = null;
44 
50  protected $_oArtList = null;
51 
57  protected $_oAttributeList = null;
58 
64  protected $_oRecommList = null;
65 
71  protected $_oPageNavigation = null;
72 
78  protected $_blBargainAction = true;
79 
85  protected $_blShowTagCloud = false;
86 
87 
93  protected $_sThisTemplate = 'page/compare/compare.tpl';
94 
100  protected $_aSimilarRecommListIds = null;
101 
102 
106  public function moveLeft() //#777C
107  {
108  $sArticleId = oxRegistry::getConfig()->getRequestParameter('aid');
109  if ($sArticleId && ($aItems = $this->getCompareItems())) {
110  $sPrevArticleId = null;
111 
112  $blFound = false;
113  foreach ($aItems as $sOxid => $sVal) {
114  if ($sOxid == $sArticleId) {
115  $blFound = true;
116  }
117  if (!$blFound) {
118  $sPrevArticleId = $sOxid;
119  }
120  }
121 
122  if ($sPrevArticleId) {
123 
124  $aNewItems = array();
125  foreach ($aItems as $sOxid => $sVal) {
126  if ($sOxid == $sPrevArticleId) {
127  $aNewItems[$sArticleId] = true;
128  } elseif ($sOxid == $sArticleId) {
129  $aNewItems[$sPrevArticleId] = true;
130  } else {
131  $aNewItems[$sOxid] = true;
132  }
133  }
134 
135  $this->setCompareItems($aNewItems);
136  }
137  }
138  }
139 
143  public function moveRight() //#777C
144  {
145  $sArticleId = oxRegistry::getConfig()->getRequestParameter('aid');
146  if ($sArticleId && ($aItems = $this->getCompareItems())) {
147  $sNextArticleId = 0;
148 
149  $blFound = false;
150  foreach ($aItems as $sOxid => $sVal) {
151  if ($blFound) {
152  $sNextArticleId = $sOxid;
153  $blFound = false;
154  }
155  if ($sOxid == $sArticleId) {
156  $blFound = true;
157  }
158  }
159 
160  if ($sNextArticleId) {
161 
162  $aNewItems = array();
163  foreach ($aItems as $sOxid => $sVal) {
164  if ($sOxid == $sArticleId) {
165  $aNewItems[$sNextArticleId] = true;
166  } elseif ($sOxid == $sNextArticleId) {
167  $aNewItems[$sArticleId] = true;
168  } else {
169  $aNewItems[$sOxid] = true;
170  }
171  }
172  $this->setCompareItems($aNewItems);
173  }
174  }
175  }
176 
180  public function inPopup() // #777C
181  {
182  $this->_sThisTemplate = 'compare_popup.tpl';
183  $this->_iArticlesPerPage = -1;
184  }
185 
191  public function setCompareItemsCnt($iCount)
192  {
193  $this->_iCompItemsCnt = $iCount;
194  }
195 
201  public function getCompareItemsCnt()
202  {
203  if ($this->_iCompItemsCnt === null) {
204  $this->_iCompItemsCnt = 0;
205  if ($aItems = $this->getCompareItems()) {
206  $this->_iCompItemsCnt = count($aItems);
207  }
208  }
209 
210  return $this->_iCompItemsCnt;
211  }
212 
218  public function getCompareItems()
219  {
220  if ($this->_aCompItems === null) {
221  $aItems = oxRegistry::getSession()->getVariable('aFiltcompproducts');
222  if (is_array($aItems) && count($aItems)) {
223  $this->_aCompItems = $aItems;
224  }
225  }
226 
227  return $this->_aCompItems;
228  }
229 
235  public function setCompareItems($aItems)
236  {
237  $this->_aCompItems = $aItems;
238  oxRegistry::getSession()->setVariable('aFiltcompproducts', $aItems);
239  }
240 
246  protected function _setArticlesPerPage($iNumber)
247  {
248  $this->_iArticlesPerPage = $iNumber;
249  }
250 
254  public function setNoPaging()
255  {
256  $this->_setArticlesPerPage(0);
257  }
258 
259 
266  public function getCompArtList()
267  {
268  if ($this->_oArtList === null) {
269  if (($aItems = $this->getCompareItems())) {
270  // counts how many pages
271  $oList = oxNew('oxarticlelist');
272  $oList->loadIds(array_keys($aItems));
273 
274  // cut page articles
275  if ($this->_iArticlesPerPage > 0) {
276  $this->_iCntPages = round($oList->count() / $this->_iArticlesPerPage + 0.49);
277  $aItems = $this->_removeArticlesFromPage($aItems, $oList);
278  }
279 
280  $this->_oArtList = $this->_changeArtListOrder($aItems, $oList);
281  }
282  }
283 
284  return $this->_oArtList;
285  }
286 
292  public function getAttributeList()
293  {
294  if ($this->_oAttributeList === null) {
295  $this->_oAttributeList = false;
296  if ($oArtList = $this->getCompArtList()) {
297  $oAttributeList = oxNew('oxattributelist');
298  $this->_oAttributeList = $oAttributeList->loadAttributesByIds(array_keys($oArtList));
299  }
300  }
301 
302  return $this->_oAttributeList;
303  }
304 
310  public function getSimilarRecommListIds()
311  {
312  if ($this->_aSimilarRecommListIds === null) {
313  $this->_aSimilarRecommListIds = false;
314 
315  if ($oArtList = $this->getCompArtList()) {
316  $this->_aSimilarRecommListIds = array_keys($oArtList);
317  }
318  }
319 
321  }
322 
328  public function getPageNavigation()
329  {
330  if ($this->_oPageNavigation === null) {
331  $this->_oPageNavigation = false;
332  $this->_oPageNavigation = $this->generatePageNavigation();
333  }
334 
336  }
337 
346  protected function _removeArticlesFromPage($aItems, $oList)
347  {
348  //#1106S $aItems changed to $oList.
349  //2006-08-10 Alfonsas, compare arrows fixed, array position is very important here, preserve it.
350  $aListKeys = $oList->arrayKeys();
351  $aItemKeys = array_keys($aItems);
352  $aKeys = array_intersect($aItemKeys, $aListKeys);
353  $aNewItems = array();
354  $iActPage = $this->getActPage();
355  for ($i = $this->_iArticlesPerPage * $iActPage; $i < $this->_iArticlesPerPage * $iActPage + $this->_iArticlesPerPage; $i++) {
356  if (!isset($aKeys[$i])) {
357  break;
358  }
359  $aNewItems[$aKeys[$i]] = & $aItems[$aKeys[$i]];
360  }
361 
362  return $aNewItems;
363  }
364 
373  protected function _changeArtListOrder($aItems, $oList)
374  {
375  // #777C changing order of list elements, according to $aItems
376  $oNewList = array();
377  $iCnt = 0;
378  $iActPage = $this->getActPage();
379  foreach ($aItems as $sOxid => $sVal) {
380 
381  //#4391T, skipping non loaded products
382  if (!isset ($oList[$sOxid])) {
383  continue;
384  }
385 
386  $iCnt++;
387  $oNewList[$sOxid] = $oList[$sOxid];
388 
389  // hide arrow if article is first in the list
390  $oNewList[$sOxid]->hidePrev = false;
391  if ($iActPage == 0 && $iCnt == 1) {
392  $oNewList[$sOxid]->hidePrev = true;
393  }
394 
395  // hide arrow if article is last in the list
396  $oNewList[$sOxid]->hideNext = false;
397  if (($iActPage + 1) == $this->_iCntPages && $iCnt == count($aItems)) {
398  $oNewList[$sOxid]->hideNext = true;
399  }
400  }
401 
402  return $oNewList;
403  }
404 
410  public function getOrderCnt()
411  {
412  if ($this->_iOrderCnt === null) {
413  $this->_iOrderCnt = 0;
414  if ($oUser = $this->getUser()) {
415  $this->_iOrderCnt = $oUser->getOrderCount();
416  }
417  }
418 
419  return $this->_iOrderCnt;
420  }
421 
427  public function getBreadCrumb()
428  {
429  $aPaths = array();
430  $aPath = array();
431 
432  $aPath['title'] = oxRegistry::getLang()->translateString('MY_ACCOUNT', oxRegistry::getLang()->getBaseLanguage(), false);
433  $aPath['link'] = oxRegistry::get("oxSeoEncoder")->getStaticUrl($this->getViewConfig()->getSelfLink() . 'cl=account');
434  $aPaths[] = $aPath;
435 
436  $aPath['title'] = oxRegistry::getLang()->translateString('PRODUCT_COMPARISON', oxRegistry::getLang()->getBaseLanguage(), false);
437  $aPath['link'] = $this->getLink();
438  $aPaths[] = $aPath;
439 
440  return $aPaths;
441  }
442 }