OXID eShop CE  4.8.11
 All Classes Files Functions Variables Pages
oxcmp_categories.php
Go to the documentation of this file.
1 <?php
2 
7 class oxcmp_categories extends oxView
8 {
13  protected $_oMoreCat = null;
14 
19  protected $_blIsComponent = true;
20 
25  protected $_oCategoryTree = null;
26 
31  protected $_oManufacturerTree = null;
32 
42  public function init()
43  {
44  parent::init();
45 
46  // Performance
47  $myConfig = $this->getConfig();
48  if ( $myConfig->getConfigParam( 'blDisableNavBars' ) &&
49  $myConfig->getTopActiveView()->getIsOrderStep() ) {
50  return;
51  }
52 
53  $sActCat = $this->_getActCat();
54 
55  if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
56  // building Manufacturer tree
57  $sActManufacturer = oxConfig::getParameter( 'mnid' );
58  $this->_loadManufacturerTree( $sActManufacturer );
59  }
60 
61  // building category tree for all purposes (nav, search and simple category trees)
62  $this->_loadCategoryTree( $sActCat );
63  }
64 
70  public function getProduct()
71  {
72  if ( ( $sActProduct = oxConfig::getParameter( 'anid' ) ) ) {
73  $oParentView = $this->getParent();
74  if ( ( $oProduct = $oParentView->getViewProduct() ) ) {
75  return $oProduct;
76  } else {
77  $oProduct = oxNew( 'oxarticle' );
78  if ( $oProduct->load( $sActProduct ) ) {
79  // storing for reuse
80  $oParentView->setViewProduct( $oProduct );
81  return $oProduct;
82  }
83  }
84  }
85  }
86 
92  protected function _getActCat()
93  {
94  $sActManufacturer = oxConfig::getParameter( 'mnid' );
95  $sActTag = oxConfig::getParameter( 'searchtag' );
96  $sActCat = $sActManufacturer ? null : oxConfig::getParameter( 'cnid' );
97 
98  // loaded article - then checking additional parameters
99  $oProduct = $this->getProduct();
100  if ( $oProduct ) {
101  $myConfig = $this->getConfig();
102 
103  $sActManufacturer = $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ? $sActManufacturer : null;
104 
105  $sActVendor = ( getStr()->preg_match( '/^v_.?/i', $sActCat ) ) ? $sActCat : null;
106 
107  $sActCat = $this->_addAdditionalParams( $oProduct, $sActCat, $sActManufacturer, $sActTag, $sActVendor );
108  }
109 
110  // Checking for the default category
111  if ( $sActCat === null && !$oProduct && !$sActManufacturer && !$sActTag ) {
112  // set remote cat
113  $sActCat = $this->getConfig()->getActiveShop()->oxshops__oxdefcat->value;
114  if ( $sActCat == 'oxrootid' ) {
115  // means none selected
116  $sActCat= null;
117  }
118  }
119  return $sActCat;
120  }
121 
129  protected function _loadCategoryTree( $sActCat )
130  {
131  $oCategoryTree = oxNew( 'oxCategoryList' );
132  $oCategoryTree->buildTree( $sActCat );
133 
134  $oParentView = $this->getParent();
135 
136  // setting active category tree
137  $oParentView->setCategoryTree( $oCategoryTree );
138  $this->setCategoryTree( $oCategoryTree );
139 
140  // setting active category
141  $oParentView->setActiveCategory( $oCategoryTree->getClickCat() );
142  }
143 
151  protected function _loadManufacturerTree( $sActManufacturer )
152  {
153  $myConfig = $this->getConfig();
154  if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
155  $oManufacturerTree = oxNew( 'oxmanufacturerlist' );
156  $oManufacturerTree->buildManufacturerTree( 'manufacturerlist', $sActManufacturer, $myConfig->getShopHomeURL() );
157 
158  $oParentView = $this->getParent();
159 
160  // setting active Manufacturer list
161  $oParentView->setManufacturerTree( $oManufacturerTree );
162  $this->setManufacturerTree($oManufacturerTree);
163 
164  // setting active Manufacturer
165  if ( ( $oManufacturer = $oManufacturerTree->getClickManufacturer() ) ) {
166  $oParentView->setActManufacturer( $oManufacturer );
167  }
168  }
169  }
170 
177  public function render()
178  {
179  parent::render();
180 
181  // Performance
182  $myConfig = $this->getConfig();
183  $oParentView = $this->getParent();
184 
185  if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) && $this->_oManufacturerTree ) {
186  $oParentView->setManufacturerlist( $this->_oManufacturerTree );
187  $oParentView->setRootManufacturer( $this->_oManufacturerTree->getRootCat() );
188  }
189 
190  if ( $this->_oCategoryTree ) {
191  return $this->_oCategoryTree;
192  }
193  }
194 
206  protected function _addAdditionalParams( $oProduct, $sActCat, $sActManufacturer, $sActTag, $sActVendor )
207  {
208  $sSearchPar = oxConfig::getParameter( 'searchparam' );
209  $sSearchCat = oxConfig::getParameter( 'searchcnid' );
210  $sSearchVnd = oxConfig::getParameter( 'searchvendor' );
211  $sSearchMan = oxConfig::getParameter( 'searchmanufacturer' );
212  $sListType = oxConfig::getParameter( 'listtype' );
213 
214  // search ?
215  if ( ( !$sListType || $sListType == 'search' ) && ( $sSearchPar || $sSearchCat || $sSearchVnd || $sSearchMan ) ) {
216  // setting list type directly
217  $sListType = 'search';
218  } else {
219 
220  // such Manufacturer is available ?
221  if ( $sActManufacturer && ( $sActManufacturer == $oProduct->getManufacturerId() ) ) {
222  // setting list type directly
223  $sListType = 'manufacturer';
224  $sActCat = $sActManufacturer;
225  } elseif ( $sActVendor && ( substr( $sActVendor, 2 ) == $oProduct->getVendorId() ) ) {
226  // such vendor is available ?
227  $sListType = 'vendor';
228  $sActCat = $sActVendor;
229  } elseif ( $sActTag ) {
230  // tag ?
231  $sListType = 'tag';
232  } elseif ( $sActCat && $oProduct->isAssignedToCategory( $sActCat ) ) {
233  // category ?
234  } else {
235  list( $sListType, $sActCat ) = $this->_getDefaultParams( $oProduct );
236  }
237  }
238 
239  $oParentView = $this->getParent();
240  //set list type and category id
241  $oParentView->setListType( $sListType );
242  $oParentView->setCategoryId( $sActCat );
243 
244  return $sActCat;
245  }
246 
254  protected function _getDefaultParams( $oProduct )
255  {
256  $sListType = null;
257  $aArticleCats = $oProduct->getCategoryIds( true );
258  if ( is_array( $aArticleCats ) && count( $aArticleCats ) ) {
259  $sActCat = reset( $aArticleCats );
260  } elseif ( ( $sActCat = $oProduct->getManufacturerId() ) ) {
261  // not assigned to any category ? maybe it is assigned to Manufacturer ?
262  $sListType = 'manufacturer';
263  } elseif ( ( $sActCat = $oProduct->getVendorId() ) ) {
264  // not assigned to any category ? maybe it is assigned to vendor ?
265  $sListType = 'vendor';
266  } else {
267  $sActCat = null;
268  }
269 
270  return array( $sListType, $sActCat );
271  }
272 
280  public function setCategoryTree( $oCategoryTree )
281  {
282  $this->_oCategoryTree = $oCategoryTree;
283  }
284 
292  public function setManufacturerTree( $oManufacturerTree )
293  {
294  $this->_oManufacturerTree = $oManufacturerTree;
295  }
296 }