OXID eShop CE  4.10.7
 All Classes Namespaces 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  $sOrderBy = $oLocatorTarget->getSortingSql($oLocatorTarget->getSortIdent());
74  $oIdList = $this->_loadIdsInList($oCategory, $oCurrArticle, $sOrderBy);
75 
76  //page number
77  $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
78 
79  // setting product position in list, amount of articles etc
80  $oCategory->iCntOfProd = $oIdList->count();
81  $oCategory->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
82 
83  if (oxRegistry::getUtils()->seoIsActive() && $iPage) {
85  $oSeoEncoderCategory = oxRegistry::get("oxSeoEncoderCategory");
86  $oCategory->toListLink = $oSeoEncoderCategory->getCategoryPageUrl($oCategory, $iPage);
87  } else {
88  $oCategory->toListLink = $this->_makeLink($oCategory->getLink(), $this->_getPageNumber($iPage));
89  }
90 
91  $oNextProduct = $this->_oNextProduct;
92  $oBackProduct = $this->_oBackProduct;
93  $oCategory->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), '') : null;
94  $oCategory->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), '') : null;
95 
96  // active category
97  $oLocatorTarget->setActiveCategory($oCategory);
98 
99  // category path
100  if (($oCatTree = $oLocatorTarget->getCategoryTree())) {
101  $oLocatorTarget->setCatTreePath($oCatTree->getPath());
102  }
103  }
104  }
105 
112  protected function _setVendorLocatorData($oLocatorTarget, $oCurrArticle)
113  {
114  if (($oVendor = $oLocatorTarget->getActVendor())) {
115  $sVendorId = $oVendor->getId();
116  $myUtils = oxRegistry::getUtils();
117 
118  $blSeo = $myUtils->seoIsActive();
119 
120  // loading data for article navigation
121  $oIdList = oxNew("oxArticleList");
122  $oIdList->setCustomSorting($oLocatorTarget->getSortingSql($oLocatorTarget->getSortIdent()));
123  $oIdList->loadVendorIds($sVendorId);
124 
125  //page number
126  $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
127 
128  $sAdd = null;
129  if (!$blSeo) {
130  $sAdd = 'listtype=vendor&amp;cnid=v_' . $sVendorId;
131  }
132 
133  // setting product position in list, amount of articles etc
134  $oVendor->iCntOfProd = $oIdList->count();
135  $oVendor->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
136 
137  if ($blSeo && $iPage) {
138  $oVendor->toListLink = oxRegistry::get("oxSeoEncoderVendor")->getVendorPageUrl($oVendor, $iPage);
139  } else {
140  $oVendor->toListLink = $this->_makeLink($oVendor->getLink(), $this->_getPageNumber($iPage));
141  }
142 
143  $oNextProduct = $this->_oNextProduct;
144  $oBackProduct = $this->_oBackProduct;
145  $oVendor->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), $sAdd) : null;
146  $oVendor->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), $sAdd) : null;
147  }
148  }
149 
156  protected function _setManufacturerLocatorData($oLocatorTarget, $oCurrArticle)
157  {
158  if (($oManufacturer = $oLocatorTarget->getActManufacturer())) {
159  $sManufacturerId = $oManufacturer->getId();
160  $myUtils = oxRegistry::getUtils();
161 
162  $blSeo = $myUtils->seoIsActive();
163 
164  // loading data for article navigation
165  $oIdList = oxNew("oxarticlelist");
166  $oIdList->setCustomSorting($oLocatorTarget->getSortingSql($oLocatorTarget->getSortIdent()));
167  $oIdList->loadManufacturerIds($sManufacturerId);
168 
169  //page number
170  $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
171 
172  $sAdd = null;
173  if (!$blSeo) {
174  $sAdd = 'listtype=manufacturer&amp;mnid=' . $sManufacturerId;
175  }
176 
177  // setting product position in list, amount of articles etc
178  $oManufacturer->iCntOfProd = $oIdList->count();
179  $oManufacturer->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
180 
181  if ($blSeo && $iPage) {
183  $oSeoEncoderManufacturer = oxRegistry::get("oxSeoEncoderManufacturer");
184  $oManufacturer->toListLink = $oSeoEncoderManufacturer->getManufacturerPageUrl($oManufacturer, $iPage);
185  } else {
186  $oManufacturer->toListLink = $this->_makeLink($oManufacturer->getLink(), $this->_getPageNumber($iPage));
187  }
188 
189  $oNextProduct = $this->_oNextProduct;
190  $oBackProduct = $this->_oBackProduct;
191  $oManufacturer->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), $sAdd) : null;
192  $oManufacturer->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), $sAdd) : null;
193 
194  // active Manufacturer
195  $oLocatorTarget->setActiveCategory($oManufacturer);
196 
197  // Manufacturer path
198  if (($oManufacturerTree = $oLocatorTarget->getManufacturerTree())) {
199  $oLocatorTarget->setCatTreePath($oManufacturerTree->getPath());
200  }
201  }
202  }
203 
210  protected function _setSearchLocatorData($oLocatorTarget, $oCurrArticle)
211  {
212  if (($oSearchCat = $oLocatorTarget->getActSearch())) {
213 
214  // #1834/1184M - specialchar search
215  $sSearchParam = oxRegistry::getConfig()->getRequestParameter('searchparam', true);
216  $sSearchFormParam = oxRegistry::getConfig()->getRequestParameter('searchparam');
217  $sSearchLinkParam = rawurlencode($sSearchParam);
218 
219  $sSearchCat = oxRegistry::getConfig()->getRequestParameter('searchcnid');
220  $sSearchCat = $sSearchCat ? rawurldecode($sSearchCat) : $sSearchCat;
221 
222  $sSearchVendor = oxRegistry::getConfig()->getRequestParameter('searchvendor');
223  $sSearchVendor = $sSearchVendor ? rawurldecode($sSearchVendor) : $sSearchVendor;
224 
225  $sSearchManufacturer = oxRegistry::getConfig()->getRequestParameter('searchmanufacturer');
226  $sSearchManufacturer = $sSearchManufacturer ? rawurldecode($sSearchManufacturer) : $sSearchManufacturer;
227 
228  // loading data for article navigation
229  $oIdList = oxNew('oxarticlelist');
230  $oIdList->setCustomSorting($oLocatorTarget->getSortingSql($oLocatorTarget->getSortIdent()));
231  $oIdList->loadSearchIds($sSearchParam, $sSearchCat, $sSearchVendor, $sSearchManufacturer);
232 
233  //page number
234  $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
235 
236  $sAddSearch = "searchparam={$sSearchLinkParam}";
237  $sAddSearch .= '&amp;listtype=search';
238 
239  if ($sSearchCat !== null) {
240  $sAddSearch .= "&amp;searchcnid={$sSearchCat}";
241  }
242 
243  if ($sSearchVendor !== null) {
244  $sAddSearch .= "&amp;searchvendor={$sSearchVendor}";
245  }
246 
247  if ($sSearchManufacturer !== null) {
248  $sAddSearch .= "&amp;searchmanufacturer={$sSearchManufacturer}";
249  }
250 
251  // setting product position in list, amount of articles etc
252  $oSearchCat->iCntOfProd = $oIdList->count();
253  $oSearchCat->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
254 
255  $sPageNr = $this->_getPageNumber($iPage);
256  $sParams = $sPageNr . ($sPageNr ? '&amp;' : '') . $sAddSearch;
257  $oSearchCat->toListLink = $this->_makeLink($oSearchCat->link, $sParams);
258  $oNextProd = $this->_oNextProduct;
259  $oBackProd = $this->_oBackProduct;
260  $oSearchCat->nextProductLink = $oNextProd ? $this->_makeLink($oNextProd->getLink(), $sAddSearch) : null;
261  $oSearchCat->prevProductLink = $oBackProd ? $this->_makeLink($oBackProd->getLink(), $sAddSearch) : null;
262 
263  $sFormat = oxRegistry::getLang()->translateString('SEARCH_RESULT');
264  $oLocatorTarget->setSearchTitle(sprintf($sFormat, $sSearchFormParam));
265  $oLocatorTarget->setActiveCategory($oSearchCat);
266  }
267  }
268 
277  protected function _setTagLocatorData($oLocatorTarget, $oCurrArticle)
278  {
279  if (($oTag = $oLocatorTarget->getActTag())) {
280 
281  $myUtils = oxRegistry::getUtils();
282 
283  // loading data for article navigation
284  $oIdList = oxNew('oxarticlelist');
285  $oLang = oxRegistry::getLang();
286 
287  if ($oLocatorTarget->showSorting()) {
288  $oIdList->setCustomSorting($oLocatorTarget->getSortingSql($oLocatorTarget->getSortIdent()));
289  }
290 
291  $oIdList->getTagArticleIds($oTag->sTag, $oLang->getBaseLanguage());
292 
293  //page number
294  $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
295 
296  // setting product position in list, amount of articles etc
297  $oTag->iCntOfProd = $oIdList->count();
298  $oTag->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
299 
300  if (oxRegistry::getUtils()->seoIsActive()) {
301  $oTag->toListLink = oxRegistry::get("oxSeoEncoderTag")->getTagPageUrl($oTag->sTag, $iPage);
302  } else {
303  $sPageNr = $this->_getPageNumber($iPage);
304  $oTag->toListLink = $this->_makeLink($oTag->link, $sPageNr);
305  }
306 
307  $sAddSearch = '';
308  // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
309  // setting parameters when seo is Off
310  if (!$myUtils->seoIsActive()) {
311  $sSearchTagParameter = oxRegistry::getConfig()->getRequestParameter('searchtag', true);
312  $sAddSearch = 'searchtag=' . rawurlencode($sSearchTagParameter);
313  $sAddSearch .= '&amp;listtype=tag';
314  }
315  // END deprecated
316 
317  $oNextProduct = $this->_oNextProduct;
318  $oBackProduct = $this->_oBackProduct;
319  $oTag->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), $sAddSearch) : null;
320  $oTag->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), $sAddSearch) : null;
321  $oStr = getStr();
322  $sTitle = $oLang->translateString('TAGS') . ' / ' . $oStr->htmlspecialchars($oStr->ucfirst($oTag->sTag));
323  $oLocatorTarget->setSearchTitle($sTitle);
324  $oLocatorTarget->setActiveCategory($oTag);
325  }
326  }
327 
339  protected function _setRecommlistLocatorData($oLocatorTarget, $oCurrArticle)
340  {
341  if (($oRecommList = $oLocatorTarget->getActiveRecommList())) {
342 
343  // loading data for article navigation
344  $oIdList = oxNew('oxarticlelist');
345  $oIdList->loadRecommArticleIds($oRecommList->getId(), null);
346 
347  //page number
348  $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
349 
350  $sSearchRecomm = oxRegistry::getConfig()->getRequestParameter('searchrecomm', true);
351 
352  if ($sSearchRecomm !== null) {
353  $sSearchFormRecomm = oxRegistry::getConfig()->getRequestParameter('searchrecomm');
354  $sSearchLinkRecomm = rawurlencode($sSearchRecomm);
355  $sAddSearch = 'searchrecomm=' . $sSearchLinkRecomm;
356  }
357 
358  // setting product position in list, amount of articles etc
359  $oRecommList->iCntOfProd = $oIdList->count();
360  $oRecommList->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
361  $blSeo = oxRegistry::getUtils()->seoIsActive();
362 
363  if ($blSeo && $iPage) {
365  $oSeoEncoderRecomm = oxRegistry::get("oxSeoEncoderRecomm");
366  $oRecommList->toListLink = $oSeoEncoderRecomm->getRecommPageUrl($oRecommList, $iPage);
367  } else {
368  $oRecommList->toListLink = $this->_makeLink($oRecommList->getLink(), $this->_getPageNumber($iPage));
369  }
370  $oRecommList->toListLink = $this->_makeLink($oRecommList->toListLink, $sAddSearch);
371 
372  $sAdd = '';
373  if (!$blSeo) {
374  $sAdd = 'recommid=' . $oRecommList->getId() . '&amp;listtype=recommlist' . ($sAddSearch ? '&amp;' : '');
375  }
376  $sAdd .= $sAddSearch;
377  $oNextProduct = $this->_oNextProduct;
378  $oBackProduct = $this->_oBackProduct;
379  $oRecommList->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), $sAdd) : null;
380  $oRecommList->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), $sAdd) : null;
381 
382  $oLang = oxRegistry::getLang();
383  $sTitle = $oLang->translateString('RECOMMLIST');
384  if ($sSearchRecomm !== null) {
385  $sTitle .= " / " . $oLang->translateString('RECOMMLIST_SEARCH') . ' "' . $sSearchFormRecomm . '"';
386  }
387  $oLocatorTarget->setSearchTitle($sTitle);
388  $oLocatorTarget->setActiveCategory($oRecommList);
389  }
390  }
391 
401  protected function _loadIdsInList($oCategory, $oCurrArticle, $sOrderBy = null)
402  {
403  $oIdList = oxNew('oxarticlelist');
404  $oIdList->setCustomSorting($sOrderBy);
405 
406  // additionally check if this category is loaded and is price category ?
407  if ($oCategory->isPriceCategory()) {
408  $oIdList->loadPriceIds($oCategory->oxcategories__oxpricefrom->value, $oCategory->oxcategories__oxpriceto->value);
409  } else {
410  $sActCat = $oCategory->getId();
411  $oIdList->loadCategoryIDs($sActCat, oxRegistry::getSession()->getVariable('session_attrfilter'));
412  // if not found - reloading with empty filter
413  if (!isset($oIdList[$oCurrArticle->getId()])) {
414  $oIdList->loadCategoryIDs($sActCat, null);
415  }
416  }
417 
418  return $oIdList;
419  }
420 
429  protected function _makeLink($sLink, $sParams)
430  {
431  if ($sParams) {
432  $sLink .= ((strpos($sLink, '?') !== false) ? '&amp;' : '?') . $sParams;
433  }
434 
435  return $sLink;
436  }
437 
448  protected function _findActPageNumber($iPageNr, $oIdList = null, $oArticle = null)
449  {
450  //page number
451  $iPageNr = (int) $iPageNr;
452 
453  // maybe there is no page number passed, but we still can find the position in id's list
454  if (!$iPageNr && $oIdList && $oArticle) {
455  $iNrofCatArticles = (int) $this->getConfig()->getConfigParam('iNrofCatArticles');
456  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 1;
457  $sParentIdField = 'oxarticles__oxparentid';
458  $sArticleId = $oArticle->$sParentIdField->value ? $oArticle->$sParentIdField->value : $oArticle->getId();
459  $iPos = oxRegistry::getUtils()->arrayStringSearch($sArticleId, $oIdList->arrayKeys());
460  $iPageNr = floor($iPos / $iNrofCatArticles);
461  }
462 
463  return $iPageNr;
464  }
465 
473  protected function _getPageNumber($iPageNr)
474  {
475  //page number
476  $iPageNr = (int) $iPageNr;
477 
478  return (($iPageNr > 0) ? "pgNr=$iPageNr" : '');
479  }
480 
490  protected function _getProductPos($oArticle, $oIdList, $oLocatorTarget)
491  {
492  $iCnt = 1;
493  $iPos = 0;
494 
495  // variant handling
496  $sOxid = $oArticle->oxarticles__oxparentid->value ? $oArticle->oxarticles__oxparentid->value : $oArticle->getId();
497  if ($oIdList->count() && isset($oIdList[$sOxid])) {
498 
499  $aIds = $oIdList->arrayKeys();
500  $iPos = oxRegistry::getUtils()->arrayStringSearch($sOxid, $aIds);
501 
502  if (array_key_exists($iPos - 1, $aIds)) {
503  $oBackProduct = oxNew('oxarticle');
504  $oBackProduct->modifyCacheKey('_locator');
505  $oBackProduct->setNoVariantLoading(true);
506  if ($oBackProduct->load($aIds[$iPos - 1])) {
507  $oBackProduct->setLinkType($oLocatorTarget->getLinkType());
508  $this->_oBackProduct = $oBackProduct;
509  }
510  }
511 
512  if (array_key_exists($iPos + 1, $aIds)) {
513  $oNextProduct = oxNew('oxarticle');
514  $oNextProduct->modifyCacheKey('_locator');
515  $oNextProduct->setNoVariantLoading(true);
516  if ($oNextProduct->load($aIds[$iPos + 1])) {
517  $oNextProduct->setLinkType($oLocatorTarget->getLinkType());
518  $this->_oNextProduct = $oNextProduct;
519  }
520  }
521 
522  return $iPos + 1;
523  }
524 
525  return 0;
526  }
527 
533  public function getErrorMessage()
534  {
535  return $this->_sErrorMessage;
536  }
537 }