OXID eShop CE  4.9.11
 All Classes Files Functions Variables Pages
oxlocator.php
Go to the documentation of this file.
1 <?php
2 
6 class oxLocator extends oxSuperCfg
7 {
8 
12  protected $_sType = "list";
13 
17  protected $_oNextProduct = null;
18 
22  protected $_oBackProduct = null;
23 
27  protected $_sSearchHandle = null;
28 
32  protected $_sErrorMessage = null;
33 
40  public function __construct($sType = null)
41  {
42  // setting locator type
43  if ($sType) {
44  $this->_sType = trim($sType);
45  }
46  }
47 
54  public function setLocatorData($oCurrArticle, $oLocatorTarget)
55  {
56  $sLocfnc = "_set{$this->_sType}LocatorData";
57  $this->$sLocfnc($oLocatorTarget, $oCurrArticle);
58 
59  // passing list type to view
60  $oLocatorTarget->setListType($this->_sType);
61  }
62 
69  protected function _setListLocatorData($oLocatorTarget, $oCurrArticle)
70  {
71  // if no active category is loaded - lets check for category passed by post/get
72  if (($oCategory = $oLocatorTarget->getActiveCategory())) {
73 
74  $sOrderBy = null;
75  if ($oLocatorTarget->showSorting()) {
76  $sOrderBy = $oLocatorTarget->getSortingSql($oLocatorTarget->getSortIdent());
77  }
78 
79  $oIdList = $this->_loadIdsInList($oCategory, $oCurrArticle, $sOrderBy);
80 
81  //page number
82  $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
83 
84  // setting product position in list, amount of articles etc
85  $oCategory->iCntOfProd = $oIdList->count();
86  $oCategory->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
87 
88  if (oxRegistry::getUtils()->seoIsActive() && $iPage) {
90  $oSeoEncoderCategory = oxRegistry::get("oxSeoEncoderCategory");
91  $oCategory->toListLink = $oSeoEncoderCategory->getCategoryPageUrl($oCategory, $iPage);
92  } else {
93  $oCategory->toListLink = $this->_makeLink($oCategory->getLink(), $this->_getPageNumber($iPage));
94  }
95 
96  $oNextProduct = $this->_oNextProduct;
97  $oBackProduct = $this->_oBackProduct;
98  $oCategory->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), '') : null;
99  $oCategory->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), '') : null;
100 
101  // active category
102  $oLocatorTarget->setActiveCategory($oCategory);
103 
104  // category path
105  if (($oCatTree = $oLocatorTarget->getCategoryTree())) {
106  $oLocatorTarget->setCatTreePath($oCatTree->getPath());
107  }
108  }
109  }
110 
117  protected function _setVendorLocatorData($oLocatorTarget, $oCurrArticle)
118  {
119  if (($oVendor = $oLocatorTarget->getActVendor())) {
120  $sVendorId = $oVendor->getId();
121  $myUtils = oxRegistry::getUtils();
122 
123  $blSeo = $myUtils->seoIsActive();
124 
125  // loading data for article navigation
126  $oIdList = oxNew("oxArticleList");
127  if ($oLocatorTarget->showSorting()) {
128  $oIdList->setCustomSorting($oLocatorTarget->getSortingSql($oLocatorTarget->getSortIdent()));
129  }
130  $oIdList->loadVendorIds($sVendorId);
131 
132  //page number
133  $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
134 
135  $sAdd = null;
136  if (!$blSeo) {
137  $sAdd = 'listtype=vendor&amp;cnid=v_' . $sVendorId;
138  }
139 
140  // setting product position in list, amount of articles etc
141  $oVendor->iCntOfProd = $oIdList->count();
142  $oVendor->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
143 
144  if ($blSeo && $iPage) {
145  $oVendor->toListLink = oxRegistry::get("oxSeoEncoderVendor")->getVendorPageUrl($oVendor, $iPage);
146  } else {
147  $oVendor->toListLink = $this->_makeLink($oVendor->getLink(), $this->_getPageNumber($iPage));
148  }
149 
150  $oNextProduct = $this->_oNextProduct;
151  $oBackProduct = $this->_oBackProduct;
152  $oVendor->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), $sAdd) : null;
153  $oVendor->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), $sAdd) : null;
154  }
155  }
156 
163  protected function _setManufacturerLocatorData($oLocatorTarget, $oCurrArticle)
164  {
165  if (($oManufacturer = $oLocatorTarget->getActManufacturer())) {
166  $sManufacturerId = $oManufacturer->getId();
167  $myUtils = oxRegistry::getUtils();
168 
169  $blSeo = $myUtils->seoIsActive();
170 
171  // loading data for article navigation
172  $oIdList = oxNew("oxarticlelist");
173  if ($oLocatorTarget->showSorting()) {
174  $oIdList->setCustomSorting($oLocatorTarget->getSortingSql($oLocatorTarget->getSortIdent()));
175  }
176  $oIdList->loadManufacturerIds($sManufacturerId);
177 
178  //page number
179  $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
180 
181  $sAdd = null;
182  if (!$blSeo) {
183  $sAdd = 'listtype=manufacturer&amp;mnid=' . $sManufacturerId;
184  }
185 
186  // setting product position in list, amount of articles etc
187  $oManufacturer->iCntOfProd = $oIdList->count();
188  $oManufacturer->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
189 
190  if ($blSeo && $iPage) {
192  $oSeoEncoderManufacturer = oxRegistry::get("oxSeoEncoderManufacturer");
193  $oManufacturer->toListLink = $oSeoEncoderManufacturer->getManufacturerPageUrl($oManufacturer, $iPage);
194  } else {
195  $oManufacturer->toListLink = $this->_makeLink($oManufacturer->getLink(), $this->_getPageNumber($iPage));
196  }
197 
198  $oNextProduct = $this->_oNextProduct;
199  $oBackProduct = $this->_oBackProduct;
200  $oManufacturer->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), $sAdd) : null;
201  $oManufacturer->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), $sAdd) : null;
202 
203  // active Manufacturer
204  $oLocatorTarget->setActiveCategory($oManufacturer);
205 
206  // Manufacturer path
207  if (($oManufacturerTree = $oLocatorTarget->getManufacturerTree())) {
208  $oLocatorTarget->setCatTreePath($oManufacturerTree->getPath());
209  }
210  }
211  }
212 
219  protected function _setSearchLocatorData($oLocatorTarget, $oCurrArticle)
220  {
221  if (($oSearchCat = $oLocatorTarget->getActSearch())) {
222 
223  // #1834/1184M - specialchar search
224  $sSearchParam = oxRegistry::getConfig()->getRequestParameter('searchparam', true);
225  $sSearchFormParam = oxRegistry::getConfig()->getRequestParameter('searchparam');
226  $sSearchLinkParam = rawurlencode($sSearchParam);
227 
228  $sSearchCat = oxRegistry::getConfig()->getRequestParameter('searchcnid');
229  $sSearchCat = $sSearchCat ? rawurldecode($sSearchCat) : $sSearchCat;
230 
231  $sSearchVendor = oxRegistry::getConfig()->getRequestParameter('searchvendor');
232  $sSearchVendor = $sSearchVendor ? rawurldecode($sSearchVendor) : $sSearchVendor;
233 
234  $sSearchManufacturer = oxRegistry::getConfig()->getRequestParameter('searchmanufacturer');
235  $sSearchManufacturer = $sSearchManufacturer ? rawurldecode($sSearchManufacturer) : $sSearchManufacturer;
236 
237  // loading data for article navigation
238  $oIdList = oxNew('oxarticlelist');
239  if ($oLocatorTarget->showSorting()) {
240  $oIdList->setCustomSorting($oLocatorTarget->getSortingSql($oLocatorTarget->getSortIdent()));
241  }
242  $oIdList->loadSearchIds($sSearchParam, $sSearchCat, $sSearchVendor, $sSearchManufacturer);
243 
244  //page number
245  $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
246 
247  $sAddSearch = "searchparam={$sSearchLinkParam}";
248  $sAddSearch .= '&amp;listtype=search';
249 
250  if ($sSearchCat !== null) {
251  $sAddSearch .= "&amp;searchcnid={$sSearchCat}";
252  }
253 
254  if ($sSearchVendor !== null) {
255  $sAddSearch .= "&amp;searchvendor={$sSearchVendor}";
256  }
257 
258  if ($sSearchManufacturer !== null) {
259  $sAddSearch .= "&amp;searchmanufacturer={$sSearchManufacturer}";
260  }
261 
262  // setting product position in list, amount of articles etc
263  $oSearchCat->iCntOfProd = $oIdList->count();
264  $oSearchCat->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
265 
266  $sPageNr = $this->_getPageNumber($iPage);
267  $sParams = $sPageNr . ($sPageNr ? '&amp;' : '') . $sAddSearch;
268  $oSearchCat->toListLink = $this->_makeLink($oSearchCat->link, $sParams);
269  $oNextProd = $this->_oNextProduct;
270  $oBackProd = $this->_oBackProduct;
271  $oSearchCat->nextProductLink = $oNextProd ? $this->_makeLink($oNextProd->getLink(), $sAddSearch) : null;
272  $oSearchCat->prevProductLink = $oBackProd ? $this->_makeLink($oBackProd->getLink(), $sAddSearch) : null;
273 
274  $sFormat = oxRegistry::getLang()->translateString('SEARCH_RESULT');
275  $oLocatorTarget->setSearchTitle(sprintf($sFormat, $sSearchFormParam));
276  $oLocatorTarget->setActiveCategory($oSearchCat);
277  }
278  }
279 
286  protected function _setTagLocatorData($oLocatorTarget, $oCurrArticle)
287  {
288  if (($oTag = $oLocatorTarget->getActTag())) {
289 
290  $myUtils = oxRegistry::getUtils();
291 
292  // loading data for article navigation
293  $oIdList = oxNew('oxarticlelist');
294  $oLang = oxRegistry::getLang();
295 
296  if ($oLocatorTarget->showSorting()) {
297  $oIdList->setCustomSorting($oLocatorTarget->getSortingSql($oLocatorTarget->getSortIdent()));
298  }
299 
300  $oIdList->getTagArticleIds($oTag->sTag, $oLang->getBaseLanguage());
301 
302  //page number
303  $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
304 
305  // setting product position in list, amount of articles etc
306  $oTag->iCntOfProd = $oIdList->count();
307  $oTag->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
308 
309  if (oxRegistry::getUtils()->seoIsActive()) {
310  $oTag->toListLink = oxRegistry::get("oxSeoEncoderTag")->getTagPageUrl($oTag->sTag, $iPage);
311  } else {
312  $sPageNr = $this->_getPageNumber($iPage);
313  $oTag->toListLink = $this->_makeLink($oTag->link, $sPageNr);
314  }
315 
316  $sAddSearch = '';
317  // setting parameters when seo is Off
318  if (!$myUtils->seoIsActive()) {
319  $sSearchTagParameter = oxRegistry::getConfig()->getRequestParameter('searchtag', true);
320  $sAddSearch = 'searchtag=' . rawurlencode($sSearchTagParameter);
321  $sAddSearch .= '&amp;listtype=tag';
322  }
323 
324  $oNextProduct = $this->_oNextProduct;
325  $oBackProduct = $this->_oBackProduct;
326  $oTag->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), $sAddSearch) : null;
327  $oTag->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), $sAddSearch) : null;
328  $oStr = getStr();
329  $sTitle = $oLang->translateString('TAGS') . ' / ' . $oStr->htmlspecialchars($oStr->ucfirst($oTag->sTag));
330  $oLocatorTarget->setSearchTitle($sTitle);
331  $oLocatorTarget->setActiveCategory($oTag);
332  }
333  }
334 
344  protected function _setRecommlistLocatorData($oLocatorTarget, $oCurrArticle)
345  {
346  if (($oRecommList = $oLocatorTarget->getActiveRecommList())) {
347 
348  // loading data for article navigation
349  $oIdList = oxNew('oxarticlelist');
350  $oIdList->loadRecommArticleIds($oRecommList->getId(), null);
351 
352  //page number
353  $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
354 
355  $sSearchRecomm = oxRegistry::getConfig()->getRequestParameter('searchrecomm', true);
356 
357  if ($sSearchRecomm !== null) {
358  $sSearchFormRecomm = oxRegistry::getConfig()->getRequestParameter('searchrecomm');
359  $sSearchLinkRecomm = rawurlencode($sSearchRecomm);
360  $sAddSearch = 'searchrecomm=' . $sSearchLinkRecomm;
361  }
362 
363  // setting product position in list, amount of articles etc
364  $oRecommList->iCntOfProd = $oIdList->count();
365  $oRecommList->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
366  $blSeo = oxRegistry::getUtils()->seoIsActive();
367 
368  if ($blSeo && $iPage) {
370  $oSeoEncoderRecomm = oxRegistry::get("oxSeoEncoderRecomm");
371  $oRecommList->toListLink = $oSeoEncoderRecomm->getRecommPageUrl($oRecommList, $iPage);
372  } else {
373  $oRecommList->toListLink = $this->_makeLink($oRecommList->getLink(), $this->_getPageNumber($iPage));
374  }
375  $oRecommList->toListLink = $this->_makeLink($oRecommList->toListLink, $sAddSearch);
376 
377  $sAdd = '';
378  if (!$blSeo) {
379  $sAdd = 'recommid=' . $oRecommList->getId() . '&amp;listtype=recommlist' . ($sAddSearch ? '&amp;' : '');
380  }
381  $sAdd .= $sAddSearch;
382  $oNextProduct = $this->_oNextProduct;
383  $oBackProduct = $this->_oBackProduct;
384  $oRecommList->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), $sAdd) : null;
385  $oRecommList->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), $sAdd) : null;
386 
387  $oLang = oxRegistry::getLang();
388  $sTitle = $oLang->translateString('RECOMMLIST');
389  if ($sSearchRecomm !== null) {
390  $sTitle .= " / " . $oLang->translateString('RECOMMLIST_SEARCH') . ' "' . $sSearchFormRecomm . '"';
391  }
392  $oLocatorTarget->setSearchTitle($sTitle);
393  $oLocatorTarget->setActiveCategory($oRecommList);
394  }
395  }
396 
406  protected function _loadIdsInList($oCategory, $oCurrArticle, $sOrderBy = null)
407  {
408  $oIdList = oxNew('oxarticlelist');
409  $oIdList->setCustomSorting($sOrderBy);
410 
411  // additionally check if this category is loaded and is price category ?
412  if ($oCategory->isPriceCategory()) {
413  $oIdList->loadPriceIds($oCategory->oxcategories__oxpricefrom->value, $oCategory->oxcategories__oxpriceto->value);
414  } else {
415  $sActCat = $oCategory->getId();
416  $oIdList->loadCategoryIDs($sActCat, oxRegistry::getSession()->getVariable('session_attrfilter'));
417  // if not found - reloading with empty filter
418  if (!isset($oIdList[$oCurrArticle->getId()])) {
419  $oIdList->loadCategoryIDs($sActCat, null);
420  }
421  }
422 
423  return $oIdList;
424  }
425 
434  protected function _makeLink($sLink, $sParams)
435  {
436  if ($sParams) {
437  $sLink .= ((strpos($sLink, '?') !== false) ? '&amp;' : '?') . $sParams;
438  }
439 
440  return $sLink;
441  }
442 
453  protected function _findActPageNumber($iPageNr, $oIdList = null, $oArticle = null)
454  {
455  //page number
456  $iPageNr = (int) $iPageNr;
457 
458  // maybe there is no page number passed, but we still can find the position in id's list
459  if (!$iPageNr && $oIdList && $oArticle) {
460  $iNrofCatArticles = (int) $this->getConfig()->getConfigParam('iNrofCatArticles');
461  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 1;
462  $sParentIdField = 'oxarticles__oxparentid';
463  $sArticleId = $oArticle->$sParentIdField->value ? $oArticle->$sParentIdField->value : $oArticle->getId();
464  $iPos = oxRegistry::getUtils()->arrayStringSearch($sArticleId, $oIdList->arrayKeys());
465  $iPageNr = floor($iPos / $iNrofCatArticles);
466  }
467 
468  return $iPageNr;
469  }
470 
478  protected function _getPageNumber($iPageNr)
479  {
480  //page number
481  $iPageNr = (int) $iPageNr;
482 
483  return (($iPageNr > 0) ? "pgNr=$iPageNr" : '');
484  }
485 
495  protected function _getProductPos($oArticle, $oIdList, $oLocatorTarget)
496  {
497  $iCnt = 1;
498  $iPos = 0;
499 
500  // variant handling
501  $sOxid = $oArticle->oxarticles__oxparentid->value ? $oArticle->oxarticles__oxparentid->value : $oArticle->getId();
502  if ($oIdList->count() && isset($oIdList[$sOxid])) {
503 
504  $aIds = $oIdList->arrayKeys();
505  $iPos = oxRegistry::getUtils()->arrayStringSearch($sOxid, $aIds);
506 
507  if (array_key_exists($iPos - 1, $aIds)) {
508  $oBackProduct = oxNew('oxarticle');
509  $oBackProduct->modifyCacheKey('_locator');
510  $oBackProduct->setNoVariantLoading(true);
511  if ($oBackProduct->load($aIds[$iPos - 1])) {
512  $oBackProduct->setLinkType($oLocatorTarget->getLinkType());
513  $this->_oBackProduct = $oBackProduct;
514  }
515  }
516 
517  if (array_key_exists($iPos + 1, $aIds)) {
518  $oNextProduct = oxNew('oxarticle');
519  $oNextProduct->modifyCacheKey('_locator');
520  $oNextProduct->setNoVariantLoading(true);
521  if ($oNextProduct->load($aIds[$iPos + 1])) {
522  $oNextProduct->setLinkType($oLocatorTarget->getLinkType());
523  $this->_oNextProduct = $oNextProduct;
524  }
525  }
526 
527  return $iPos + 1;
528  }
529 
530  return 0;
531  }
532 
538  public function getErrorMessage()
539  {
540  return $this->_sErrorMessage;
541  }
542 }