OXID eShop CE  4.9.10
 All Classes 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  $sActTag = oxRegistry::getConfig()->getRequestParameter('searchtag');
104  $sActCat = $sActManufacturer ? null : oxRegistry::getConfig()->getRequestParameter('cnid');
105 
106  // loaded article - then checking additional parameters
107  $oProduct = $this->getProduct();
108  if ($oProduct) {
109  $myConfig = $this->getConfig();
110 
111  $sActManufacturer = $myConfig->getConfigParam('bl_perfLoadManufacturerTree') ? $sActManufacturer : null;
112 
113  $sActVendor = (getStr()->preg_match('/^v_.?/i', $sActCat)) ? $sActCat : null;
114 
115  $sActCat = $this->_addAdditionalParams($oProduct, $sActCat, $sActManufacturer, $sActTag, $sActVendor);
116  }
117 
118  // Checking for the default category
119  if ($sActCat === null && !$oProduct && !$sActManufacturer && !$sActTag) {
120  // set remote cat
121  $sActCat = $this->getConfig()->getActiveShop()->oxshops__oxdefcat->value;
122  if ($sActCat == 'oxrootid') {
123  // means none selected
124  $sActCat = null;
125  }
126  }
127 
128  return $sActCat;
129  }
130 
136  protected function _loadCategoryTree($sActCat)
137  {
138  $oCategoryTree = oxNew('oxCategoryList');
139  $oCategoryTree->buildTree($sActCat);
140 
141  $oParentView = $this->getParent();
142 
143  // setting active category tree
144  $oParentView->setCategoryTree($oCategoryTree);
145  $this->setCategoryTree($oCategoryTree);
146 
147  // setting active category
148  $oParentView->setActiveCategory($oCategoryTree->getClickCat());
149  }
150 
156  protected function _loadManufacturerTree($sActManufacturer)
157  {
158  $myConfig = $this->getConfig();
159  if ($myConfig->getConfigParam('bl_perfLoadManufacturerTree')) {
160  $oManufacturerTree = oxNew('oxmanufacturerlist');
161  $shopHomeURL = $myConfig->getShopHomeURL();
162  $oManufacturerTree->buildManufacturerTree('manufacturerlist', $sActManufacturer, $shopHomeURL);
163 
164  $oParentView = $this->getParent();
165 
166  // setting active Manufacturer list
167  $oParentView->setManufacturerTree($oManufacturerTree);
168  $this->setManufacturerTree($oManufacturerTree);
169 
170  // setting active Manufacturer
171  if (($oManufacturer = $oManufacturerTree->getClickManufacturer())) {
172  $oParentView->setActManufacturer($oManufacturer);
173  }
174  }
175  }
176 
183  public function render()
184  {
185  parent::render();
186 
187  // Performance
188  $myConfig = $this->getConfig();
189  $oParentView = $this->getParent();
190 
191  if ($myConfig->getConfigParam('bl_perfLoadManufacturerTree') && $this->_oManufacturerTree) {
192  $oParentView->setManufacturerlist($this->_oManufacturerTree);
193  $oParentView->setRootManufacturer($this->_oManufacturerTree->getRootCat());
194  }
195 
196  if ($this->_oCategoryTree) {
197  return $this->_oCategoryTree;
198  }
199  }
200 
212  protected function _addAdditionalParams($oProduct, $sActCat, $sActManufacturer, $sActTag, $sActVendor)
213  {
214  $sSearchPar = oxRegistry::getConfig()->getRequestParameter('searchparam');
215  $sSearchCat = oxRegistry::getConfig()->getRequestParameter('searchcnid');
216  $sSearchVnd = oxRegistry::getConfig()->getRequestParameter('searchvendor');
217  $sSearchMan = oxRegistry::getConfig()->getRequestParameter('searchmanufacturer');
218  $sListType = oxRegistry::getConfig()->getRequestParameter('listtype');
219 
220  // search ?
221  if ((!$sListType || $sListType == 'search') && ($sSearchPar || $sSearchCat || $sSearchVnd || $sSearchMan)) {
222  // setting list type directly
223  $sListType = 'search';
224  } else {
225 
226  // such Manufacturer is available ?
227  if ($sActManufacturer && ($sActManufacturer == $oProduct->getManufacturerId())) {
228  // setting list type directly
229  $sListType = 'manufacturer';
230  $sActCat = $sActManufacturer;
231  } elseif ($sActVendor && (substr($sActVendor, 2) == $oProduct->getVendorId())) {
232  // such vendor is available ?
233  $sListType = 'vendor';
234  $sActCat = $sActVendor;
235  } elseif ($sActTag) {
236  // tag ?
237  $sListType = 'tag';
238  } elseif ($sActCat && $oProduct->isAssignedToCategory($sActCat)) {
239  // category ?
240  } else {
241  list($sListType, $sActCat) = $this->_getDefaultParams($oProduct);
242  }
243  }
244 
245  $oParentView = $this->getParent();
246  //set list type and category id
247  $oParentView->setListType($sListType);
248  $oParentView->setCategoryId($sActCat);
249 
250  return $sActCat;
251  }
252 
260  protected function _getDefaultParams($oProduct)
261  {
262  $sListType = null;
263  $aArticleCats = $oProduct->getCategoryIds(true);
264  if (is_array($aArticleCats) && count($aArticleCats)) {
265  $sActCat = reset($aArticleCats);
266  } elseif (($sActCat = $oProduct->getManufacturerId())) {
267  // not assigned to any category ? maybe it is assigned to Manufacturer ?
268  $sListType = 'manufacturer';
269  } elseif (($sActCat = $oProduct->getVendorId())) {
270  // not assigned to any category ? maybe it is assigned to vendor ?
271  $sListType = 'vendor';
272  } else {
273  $sActCat = null;
274  }
275 
276  return array($sListType, $sActCat);
277  }
278 
284  public function setCategoryTree($oCategoryTree)
285  {
286  $this->_oCategoryTree = $oCategoryTree;
287  }
288 
294  public function setManufacturerTree($oManufacturerTree)
295  {
296  $this->_oManufacturerTree = $oManufacturerTree;
297  }
298 }