OXID eShop CE  4.10.3
 All Classes Namespaces Files Functions Variables Pages
oxcmp_categories.php
Go to the documentation of this file.
1 <?php
2 
8 class oxcmp_categories extends oxView
9 {
10 
16  protected $_oMoreCat = null;
17 
23  protected $_blIsComponent = true;
24 
30  protected $_oCategoryTree = null;
31 
37  protected $_oManufacturerTree = null;
38 
48  public function init()
49  {
50  parent::init();
51 
52  // Performance
53  $myConfig = $this->getConfig();
54  if ($myConfig->getConfigParam('blDisableNavBars') &&
55  $myConfig->getTopActiveView()->getIsOrderStep()
56  ) {
57  return;
58  }
59 
60  $sActCat = $this->_getActCat();
61 
62  if ($myConfig->getConfigParam('bl_perfLoadManufacturerTree')) {
63  // building Manufacturer tree
64  $sActManufacturer = oxRegistry::getConfig()->getRequestParameter('mnid');
65  $this->_loadManufacturerTree($sActManufacturer);
66  }
67 
68  // building category tree for all purposes (nav, search and simple category trees)
69  $this->_loadCategoryTree($sActCat);
70  }
71 
77  public function getProduct()
78  {
79  if (($sActProduct = oxRegistry::getConfig()->getRequestParameter('anid'))) {
80  $oParentView = $this->getParent();
81  if (($oProduct = $oParentView->getViewProduct())) {
82  return $oProduct;
83  } else {
84  $oProduct = oxNew('oxarticle');
85  if ($oProduct->load($sActProduct)) {
86  // storing for reuse
87  $oParentView->setViewProduct($oProduct);
88 
89  return $oProduct;
90  }
91  }
92  }
93  }
94 
100  protected function _getActCat()
101  {
102  $sActManufacturer = oxRegistry::getConfig()->getRequestParameter('mnid');
103  // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
104  $sActTag = oxRegistry::getConfig()->getRequestParameter('searchtag');
105  // END deprecated
106  $sActCat = $sActManufacturer ? null : oxRegistry::getConfig()->getRequestParameter('cnid');
107 
108  // loaded article - then checking additional parameters
109  $oProduct = $this->getProduct();
110  if ($oProduct) {
111  $myConfig = $this->getConfig();
112 
113  $sActManufacturer = $myConfig->getConfigParam('bl_perfLoadManufacturerTree') ? $sActManufacturer : null;
114 
115  $sActVendor = (getStr()->preg_match('/^v_.?/i', $sActCat)) ? $sActCat : null;
116 
117  // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
118  $sActCat = $this->_addAdditionalParams($oProduct, $sActCat, $sActManufacturer, $sActTag, $sActVendor);
119  // END deprecated
120  }
121 
122  // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
123  // Checking for the default category
124  if ($sActCat === null && !$oProduct && !$sActManufacturer && !$sActTag) {
125  // set remote cat
126  $sActCat = $this->getConfig()->getActiveShop()->oxshops__oxdefcat->value;
127  if ($sActCat == 'oxrootid') {
128  // means none selected
129  $sActCat = null;
130  }
131  }
132  // END deprecated
133 
134  return $sActCat;
135  }
136 
142  protected function _loadCategoryTree($sActCat)
143  {
144  $oCategoryTree = oxNew('oxCategoryList');
145  $oCategoryTree->buildTree($sActCat);
146 
147  $oParentView = $this->getParent();
148 
149  // setting active category tree
150  $oParentView->setCategoryTree($oCategoryTree);
151  $this->setCategoryTree($oCategoryTree);
152 
153  // setting active category
154  $oParentView->setActiveCategory($oCategoryTree->getClickCat());
155  }
156 
162  protected function _loadManufacturerTree($sActManufacturer)
163  {
164  $myConfig = $this->getConfig();
165  if ($myConfig->getConfigParam('bl_perfLoadManufacturerTree')) {
166  $oManufacturerTree = oxNew('oxmanufacturerlist');
167  $shopHomeURL = $myConfig->getShopHomeURL();
168  $oManufacturerTree->buildManufacturerTree('manufacturerlist', $sActManufacturer, $shopHomeURL);
169 
170  $oParentView = $this->getParent();
171 
172  // setting active Manufacturer list
173  $oParentView->setManufacturerTree($oManufacturerTree);
174  $this->setManufacturerTree($oManufacturerTree);
175 
176  // setting active Manufacturer
177  if (($oManufacturer = $oManufacturerTree->getClickManufacturer())) {
178  $oParentView->setActManufacturer($oManufacturer);
179  }
180  }
181  }
182 
189  public function render()
190  {
191  parent::render();
192 
193  // Performance
194  $myConfig = $this->getConfig();
195  $oParentView = $this->getParent();
196 
197  if ($myConfig->getConfigParam('bl_perfLoadManufacturerTree') && $this->_oManufacturerTree) {
198  $oParentView->setManufacturerlist($this->_oManufacturerTree);
199  $oParentView->setRootManufacturer($this->_oManufacturerTree->getRootCat());
200  }
201 
202  if ($this->_oCategoryTree) {
203  return $this->_oCategoryTree;
204  }
205  }
206 
220  protected function _addAdditionalParams($oProduct, $sActCat, $sActManufacturer, $sActTag, $sActVendor)
221  {
222  $sSearchPar = oxRegistry::getConfig()->getRequestParameter('searchparam');
223  $sSearchCat = oxRegistry::getConfig()->getRequestParameter('searchcnid');
224  $sSearchVnd = oxRegistry::getConfig()->getRequestParameter('searchvendor');
225  $sSearchMan = oxRegistry::getConfig()->getRequestParameter('searchmanufacturer');
226  $sListType = oxRegistry::getConfig()->getRequestParameter('listtype');
227 
228  // search ?
229  if ((!$sListType || $sListType == 'search') && ($sSearchPar || $sSearchCat || $sSearchVnd || $sSearchMan)) {
230  // setting list type directly
231  $sListType = 'search';
232  } else {
233 
234  // such Manufacturer is available ?
235  if ($sActManufacturer && ($sActManufacturer == $oProduct->getManufacturerId())) {
236  // setting list type directly
237  $sListType = 'manufacturer';
238  $sActCat = $sActManufacturer;
239  } elseif ($sActVendor && (substr($sActVendor, 2) == $oProduct->getVendorId())) {
240  // such vendor is available ?
241  $sListType = 'vendor';
242  $sActCat = $sActVendor;
243  // @deprecated v5.3 (2016-05-04); Tags will be moved to own module.
244  } elseif ($sActTag) {
245  // tag ?
246  $sListType = 'tag';
247  // END deprecated
248  } elseif ($sActCat && $oProduct->isAssignedToCategory($sActCat)) {
249  // category ?
250  } else {
251  list($sListType, $sActCat) = $this->_getDefaultParams($oProduct);
252  }
253  }
254 
255  $oParentView = $this->getParent();
256  //set list type and category id
257  $oParentView->setListType($sListType);
258  $oParentView->setCategoryId($sActCat);
259 
260  return $sActCat;
261  }
262 
270  protected function _getDefaultParams($oProduct)
271  {
272  $sListType = null;
273  $aArticleCats = $oProduct->getCategoryIds(true);
274  if (is_array($aArticleCats) && count($aArticleCats)) {
275  $sActCat = reset($aArticleCats);
276  } elseif (($sActCat = $oProduct->getManufacturerId())) {
277  // not assigned to any category ? maybe it is assigned to Manufacturer ?
278  $sListType = 'manufacturer';
279  } elseif (($sActCat = $oProduct->getVendorId())) {
280  // not assigned to any category ? maybe it is assigned to vendor ?
281  $sListType = 'vendor';
282  } else {
283  $sActCat = null;
284  }
285 
286  return array($sListType, $sActCat);
287  }
288 
294  public function setCategoryTree($oCategoryTree)
295  {
296  $this->_oCategoryTree = $oCategoryTree;
297  }
298 
304  public function setManufacturerTree($oManufacturerTree)
305  {
306  $this->_oManufacturerTree = $oManufacturerTree;
307  }
308 }