OXID eShop CE  4.10.1
 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 
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 
288  protected function _setTagLocatorData($oLocatorTarget, $oCurrArticle)
289  {
290  if (($oTag = $oLocatorTarget->getActTag())) {
291 
292  $myUtils = oxRegistry::getUtils();
293 
294  // loading data for article navigation
295  $oIdList = oxNew('oxarticlelist');
296  $oLang = oxRegistry::getLang();
297 
298  if ($oLocatorTarget->showSorting()) {
299  $oIdList->setCustomSorting($oLocatorTarget->getSortingSql($oLocatorTarget->getSortIdent()));
300  }
301 
302  $oIdList->getTagArticleIds($oTag->sTag, $oLang->getBaseLanguage());
303 
304  //page number
305  $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
306 
307  // setting product position in list, amount of articles etc
308  $oTag->iCntOfProd = $oIdList->count();
309  $oTag->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
310 
311  if (oxRegistry::getUtils()->seoIsActive()) {
312  $oTag->toListLink = oxRegistry::get("oxSeoEncoderTag")->getTagPageUrl($oTag->sTag, $iPage);
313  } else {
314  $sPageNr = $this->_getPageNumber($iPage);
315  $oTag->toListLink = $this->_makeLink($oTag->link, $sPageNr);
316  }
317 
318  $sAddSearch = '';
319  // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
320  // setting parameters when seo is Off
321  if (!$myUtils->seoIsActive()) {
322  $sSearchTagParameter = oxRegistry::getConfig()->getRequestParameter('searchtag', true);
323  $sAddSearch = 'searchtag=' . rawurlencode($sSearchTagParameter);
324  $sAddSearch .= '&amp;listtype=tag';
325  }
326  // END deprecated
327 
328  $oNextProduct = $this->_oNextProduct;
329  $oBackProduct = $this->_oBackProduct;
330  $oTag->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), $sAddSearch) : null;
331  $oTag->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), $sAddSearch) : null;
332  $oStr = getStr();
333  $sTitle = $oLang->translateString('TAGS') . ' / ' . $oStr->htmlspecialchars($oStr->ucfirst($oTag->sTag));
334  $oLocatorTarget->setSearchTitle($sTitle);
335  $oLocatorTarget->setActiveCategory($oTag);
336  }
337  }
338 
350  protected function _setRecommlistLocatorData($oLocatorTarget, $oCurrArticle)
351  {
352  if (($oRecommList = $oLocatorTarget->getActiveRecommList())) {
353 
354  // loading data for article navigation
355  $oIdList = oxNew('oxarticlelist');
356  $oIdList->loadRecommArticleIds($oRecommList->getId(), null);
357 
358  //page number
359  $iPage = $this->_findActPageNumber($oLocatorTarget->getActPage(), $oIdList, $oCurrArticle);
360 
361  $sSearchRecomm = oxRegistry::getConfig()->getRequestParameter('searchrecomm', true);
362 
363  if ($sSearchRecomm !== null) {
364  $sSearchFormRecomm = oxRegistry::getConfig()->getRequestParameter('searchrecomm');
365  $sSearchLinkRecomm = rawurlencode($sSearchRecomm);
366  $sAddSearch = 'searchrecomm=' . $sSearchLinkRecomm;
367  }
368 
369  // setting product position in list, amount of articles etc
370  $oRecommList->iCntOfProd = $oIdList->count();
371  $oRecommList->iProductPos = $this->_getProductPos($oCurrArticle, $oIdList, $oLocatorTarget);
372  $blSeo = oxRegistry::getUtils()->seoIsActive();
373 
374  if ($blSeo && $iPage) {
376  $oSeoEncoderRecomm = oxRegistry::get("oxSeoEncoderRecomm");
377  $oRecommList->toListLink = $oSeoEncoderRecomm->getRecommPageUrl($oRecommList, $iPage);
378  } else {
379  $oRecommList->toListLink = $this->_makeLink($oRecommList->getLink(), $this->_getPageNumber($iPage));
380  }
381  $oRecommList->toListLink = $this->_makeLink($oRecommList->toListLink, $sAddSearch);
382 
383  $sAdd = '';
384  if (!$blSeo) {
385  $sAdd = 'recommid=' . $oRecommList->getId() . '&amp;listtype=recommlist' . ($sAddSearch ? '&amp;' : '');
386  }
387  $sAdd .= $sAddSearch;
388  $oNextProduct = $this->_oNextProduct;
389  $oBackProduct = $this->_oBackProduct;
390  $oRecommList->nextProductLink = $oNextProduct ? $this->_makeLink($oNextProduct->getLink(), $sAdd) : null;
391  $oRecommList->prevProductLink = $oBackProduct ? $this->_makeLink($oBackProduct->getLink(), $sAdd) : null;
392 
393  $oLang = oxRegistry::getLang();
394  $sTitle = $oLang->translateString('RECOMMLIST');
395  if ($sSearchRecomm !== null) {
396  $sTitle .= " / " . $oLang->translateString('RECOMMLIST_SEARCH') . ' "' . $sSearchFormRecomm . '"';
397  }
398  $oLocatorTarget->setSearchTitle($sTitle);
399  $oLocatorTarget->setActiveCategory($oRecommList);
400  }
401  }
402 
412  protected function _loadIdsInList($oCategory, $oCurrArticle, $sOrderBy = null)
413  {
414  $oIdList = oxNew('oxarticlelist');
415  $oIdList->setCustomSorting($sOrderBy);
416 
417  // additionally check if this category is loaded and is price category ?
418  if ($oCategory->isPriceCategory()) {
419  $oIdList->loadPriceIds($oCategory->oxcategories__oxpricefrom->value, $oCategory->oxcategories__oxpriceto->value);
420  } else {
421  $sActCat = $oCategory->getId();
422  $oIdList->loadCategoryIDs($sActCat, oxRegistry::getSession()->getVariable('session_attrfilter'));
423  // if not found - reloading with empty filter
424  if (!isset($oIdList[$oCurrArticle->getId()])) {
425  $oIdList->loadCategoryIDs($sActCat, null);
426  }
427  }
428 
429  return $oIdList;
430  }
431 
440  protected function _makeLink($sLink, $sParams)
441  {
442  if ($sParams) {
443  $sLink .= ((strpos($sLink, '?') !== false) ? '&amp;' : '?') . $sParams;
444  }
445 
446  return $sLink;
447  }
448 
459  protected function _findActPageNumber($iPageNr, $oIdList = null, $oArticle = null)
460  {
461  //page number
462  $iPageNr = (int) $iPageNr;
463 
464  // maybe there is no page number passed, but we still can find the position in id's list
465  if (!$iPageNr && $oIdList && $oArticle) {
466  $iNrofCatArticles = (int) $this->getConfig()->getConfigParam('iNrofCatArticles');
467  $iNrofCatArticles = $iNrofCatArticles ? $iNrofCatArticles : 1;
468  $sParentIdField = 'oxarticles__oxparentid';
469  $sArticleId = $oArticle->$sParentIdField->value ? $oArticle->$sParentIdField->value : $oArticle->getId();
470  $iPos = oxRegistry::getUtils()->arrayStringSearch($sArticleId, $oIdList->arrayKeys());
471  $iPageNr = floor($iPos / $iNrofCatArticles);
472  }
473 
474  return $iPageNr;
475  }
476 
484  protected function _getPageNumber($iPageNr)
485  {
486  //page number
487  $iPageNr = (int) $iPageNr;
488 
489  return (($iPageNr > 0) ? "pgNr=$iPageNr" : '');
490  }
491 
501  protected function _getProductPos($oArticle, $oIdList, $oLocatorTarget)
502  {
503  $iCnt = 1;
504  $iPos = 0;
505 
506  // variant handling
507  $sOxid = $oArticle->oxarticles__oxparentid->value ? $oArticle->oxarticles__oxparentid->value : $oArticle->getId();
508  if ($oIdList->count() && isset($oIdList[$sOxid])) {
509 
510  $aIds = $oIdList->arrayKeys();
511  $iPos = oxRegistry::getUtils()->arrayStringSearch($sOxid, $aIds);
512 
513  if (array_key_exists($iPos - 1, $aIds)) {
514  $oBackProduct = oxNew('oxarticle');
515  $oBackProduct->modifyCacheKey('_locator');
516  $oBackProduct->setNoVariantLoading(true);
517  if ($oBackProduct->load($aIds[$iPos - 1])) {
518  $oBackProduct->setLinkType($oLocatorTarget->getLinkType());
519  $this->_oBackProduct = $oBackProduct;
520  }
521  }
522 
523  if (array_key_exists($iPos + 1, $aIds)) {
524  $oNextProduct = oxNew('oxarticle');
525  $oNextProduct->modifyCacheKey('_locator');
526  $oNextProduct->setNoVariantLoading(true);
527  if ($oNextProduct->load($aIds[$iPos + 1])) {
528  $oNextProduct->setLinkType($oLocatorTarget->getLinkType());
529  $this->_oNextProduct = $oNextProduct;
530  }
531  }
532 
533  return $iPos + 1;
534  }
535 
536  return 0;
537  }
538 
544  public function getErrorMessage()
545  {
546  return $this->_sErrorMessage;
547  }
548 }