00001 <?php
00002
00007 class oxcmp_categories extends oxView
00008 {
00013 protected $_oMoreCat = null;
00014
00019 protected $_blIsComponent = true;
00020
00030 public function init()
00031 {
00032 parent::init();
00033
00034
00035 $myConfig = $this->getConfig();
00036 if ( $myConfig->getConfigParam( 'blDisableNavBars' ) &&
00037 $myConfig->getActiveView()->getIsOrderStep() ) {
00038 return;
00039 }
00040
00041 $sActProduct = oxConfig::getParameter( 'anid' );
00042 if ( ! ( $sActCont = oxConfig::getParameter( 'oxcid' ) ) ) {
00043 $sActCont = oxConfig::getParameter( 'tpl' );
00044 }
00045 $sActManufacturer = oxConfig::getParameter( 'mnid' );
00046 $sActCat = $sActManufacturer ? null : oxConfig::getParameter( 'cnid' );
00047 $sActTag = oxConfig::getParameter( 'searchtag' );
00048
00049 $blArtLoaded = false;
00050 if ( $sActProduct ) {
00051
00052 $oProduct = $this->_oParent->getViewProduct();
00053 $blArtLoaded = $oProduct ? true : false;
00054 if ( !$blArtLoaded ) {
00055 $oProduct = oxNew( 'oxarticle' );
00056
00057 if ( $oProduct->load( $sActProduct ) ) {
00058
00059
00060 $this->_oParent->setViewProduct( $oProduct );
00061 $blArtLoaded = true;
00062 }
00063 }
00064 }
00065
00066
00067 if ( $blArtLoaded ) {
00068 $sActCat = $this->_addAdditionalParams( $oProduct, $sActCat, $sActManufacturer, $sActCont, $sActTag );
00069 }
00070
00071
00072 if ( $sActCat === null && !$blArtLoaded && !$sActCont && !$sActManufacturer && !$sActTag ) {
00073
00074 $sActCat = $myConfig->getActiveShop()->oxshops__oxdefcat->value;
00075 if ( $sActCat == 'oxrootid' ) {
00076
00077 $sActCat= null;
00078 }
00079 }
00080
00081 if ( $myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
00082
00083 $this->_loadVendorTree( $sActCat );
00084 }
00085
00086 if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00087
00088 $this->_loadManufacturerTree( $sActManufacturer );
00089 }
00090
00091 if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) ) {
00092
00093
00094 $this->_loadCategoryTree( $sActCat );
00095
00096 if ( $myConfig->getConfigParam( 'blTopNaviLayout' ) ) {
00097 $this->_oMoreCat = $this->_getMoreCategory( $sActCat, $sActCont );
00098 }
00099 }
00100 }
00101
00109 protected function _loadCategoryTree( $sActCat )
00110 {
00111 $myConfig = $this->getConfig();
00112 if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) ) {
00113 $oCategoryTree = oxNew( 'oxcategorylist' );
00114 $oCategoryTree->buildTree( $sActCat, $myConfig->getConfigParam( 'blLoadFullTree' ), $myConfig->getConfigParam( 'bl_perfLoadTreeForSearch' ), $myConfig->getConfigParam( 'blTopNaviLayout' ) );
00115
00116
00117 $this->_oParent->setCategoryTree( $oCategoryTree );
00118
00119
00120 $this->_oParent->setActCategory( $oCategoryTree->getClickCat() );
00121 }
00122 }
00123
00131 protected function _loadVendorTree( $sActVendor )
00132 {
00133 $myConfig = $this->getConfig();
00134 if ( $myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
00135 $oVendorTree = oxNew( 'oxvendorlist' );
00136 $oVendorTree->buildVendorTree( 'vendorlist', $sActVendor, $myConfig->getShopHomeURL() );
00137
00138
00139 $this->_oParent->setVendorTree( $oVendorTree );
00140
00141
00142 if ( ( $oVendor = $oVendorTree->getClickVendor() ) ) {
00143 $this->_oParent->setActVendor( $oVendor );
00144 }
00145 }
00146 }
00147
00155 protected function _loadManufacturerTree( $sActManufacturer )
00156 {
00157 $myConfig = $this->getConfig();
00158 if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00159 $oManufacturerTree = oxNew( 'oxmanufacturerlist' );
00160 $oManufacturerTree->buildManufacturerTree( 'manufacturerlist', $sActManufacturer, $myConfig->getShopHomeURL() );
00161
00162
00163 $this->_oParent->setManufacturerTree( $oManufacturerTree );
00164
00165
00166 if ( ( $oManufacturer = $oManufacturerTree->getClickManufacturer() ) ) {
00167 $this->_oParent->setActManufacturer( $oManufacturer );
00168 }
00169 }
00170 }
00171
00178 public function render()
00179 {
00180 parent::render();
00181
00182
00183 $myConfig = $this->getConfig();
00184
00185 if ( $myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) &&
00186 ( $oVendorTree = $this->_oParent->getVendorTree() )) {
00187 $this->_oParent->setVendorlist( $oVendorTree );
00188 $this->_oParent->setRootVendor( $oVendorTree->getRootCat() );
00189
00190
00191 $this->_oParent->addTplParam( 'rootvendor', $this->_oParent->getRootVendor() );
00192 $this->_oParent->addTplParam( 'aVendorlist', $this->_oParent->getVendorlist() );
00193 $this->_oParent->addTplParam( 'sVendorID', $this->_oParent->getVendorId() );
00194 }
00195
00196 if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) &&
00197 ( $oManufacturerTree = $this->_oParent->getManufacturerTree() ) ) {
00198 $this->_oParent->setManufacturerlist( $oManufacturerTree );
00199 $this->_oParent->setRootManufacturer( $oManufacturerTree->getRootCat() );
00200
00201
00202 $this->_oParent->addTplParam( 'rootmanufacturer', $this->_oParent->getRootManufacturer() );
00203 $this->_oParent->addTplParam( 'aManufacturerlist', $this->_oParent->getManufacturerlist() );
00204 $this->_oParent->addTplParam( 'sManufacturerID', $this->_oParent->getManufacturerId() );
00205 }
00206
00207 if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) &&
00208 ( $oCategoryTree = $this->_oParent->getCategoryTree() ) ) {
00209
00210
00211 if ( $myConfig->getConfigParam( 'bl_perfLoadTreeForSearch' ) ) {
00212 $this->_oParent->setSearchCatTree( $oCategoryTree );
00213
00214 $this->_oParent->addTplParam( 'aSearchCatTree', $this->_oParent->getSearchCatTree() );
00215 }
00216
00217
00218 if ( $myConfig->getConfigParam( 'blTopNaviLayout' ) ) {
00219 $this->_oParent->setCatMore( $this->_oMoreCat );
00220
00221 $this->_oParent->addTplParam( 'navcategorytree', $oCategoryTree );
00222 $this->_oParent->addTplParam( 'navcategorycount', $oCategoryTree->count() );
00223 $this->_oParent->addTplParam( 'navcatmore', $this->_oParent->getCatMore() );
00224 }
00225
00226 return $oCategoryTree;
00227 }
00228 }
00229
00238 protected function _getMoreCategory( $sActCat, $sActCont )
00239 {
00240 $myConfig = $this->getConfig();
00241 $iTopCount = $myConfig->getConfigParam( 'iTopNaviCatCount' );
00242 $blExpanded = false;
00243
00244 if ( $sActCat == 'oxmore' ) {
00245 $blExpanded = true;
00246 } else {
00247 $oCategoryTree = $this->_oParent->getCategoryTree();
00248 if ( $oCategoryTree ) {
00249 $iCnt = 0;
00250 foreach ( $oCategoryTree as $oCat ) {
00251 $iCnt++;
00252
00253 if ( ( $aContent = $oCat->getContentCats() ) ) {
00254 foreach ( $aContent as $oContent ) {
00255 if ( $sActCont == $oContent->getId() && $iCnt > $iTopCount ) {
00256 $blExpanded = true;
00257 break 2;
00258 }
00259 $iCnt++;
00260 }
00261 }
00262
00263 if ( $oCat->getExpanded() && $iCnt > $iTopCount ) {
00264 $blExpanded = true;
00265 break;
00266 }
00267 }
00268 }
00269 }
00270
00271 $oMoreCat = new oxStdClass();
00272 $oMoreCat->closelink = $oMoreCat->openlink = $myConfig->getShopHomeURL().'cnid=oxmore';
00273 $oMoreCat->expanded = $blExpanded;
00274 return $oMoreCat;
00275 }
00276
00288 protected function _addAdditionalParams( $oProduct, $sActCat, $sActManufacturer, $sActCont, $sActTag )
00289 {
00290 $sSearchPar = oxConfig::getParameter( 'searchparam' );
00291 $sSearchCat = oxConfig::getParameter( 'searchcnid' );
00292 $sSearchVnd = oxConfig::getParameter( 'searchvendor' );
00293 $sSearchMan = oxConfig::getParameter( 'searchmanufacturer' );
00294 $sListType = oxConfig::getParameter( 'listtype' );
00295
00296
00297 if ( !$sListType ) {
00298
00299 if ( ( !$sListType || $sListType == 'search' ) && ( $sSearchPar || $sSearchCat || $sSearchVnd ) ) {
00300
00301 $sListType = 'search';
00302 } else {
00303
00304
00305 $blManufacturer = false;
00306 if ( $this->getConfig()->getConfigParam( 'bl_perfLoadManufacturerTree' ) && $sActManufacturer ) {
00307
00308 if ( $sActManufacturer == $oProduct->getManufacturerId() ) {
00309 $blManufacturer = true;
00310
00311 $sListType = 'manufacturer';
00312 }
00313 }
00314
00315
00316 $blVendor = false;
00317 if ( !$blManufacturer && $sActCat && $this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) && preg_match( '/^v_.?/i', $sActCat ) ) {
00318
00319 if ( substr( $sActCat, 2 ) == $oProduct->getVendorId() ) {
00320 $blVendor = true;
00321
00322 $sListType = 'vendor';
00323 }
00324 }
00325
00326
00327 $blTags = false;
00328 if ( !$blVendor && !$blManufacturer && $sActTag ) {
00329 $blTags = true;
00330
00331 $sListType = 'tag';
00332 }
00333
00334
00335 if ( $sActCat && !$blVendor && !$blManufacturer && !$blTags ) {
00336 if ( !$oProduct->isAssignedToCategory( $sActCat ) ) {
00337
00338
00339 $aArticleCats = $oProduct->getCategoryIds(true);
00340 if ( is_array( $aArticleCats ) && count( $aArticleCats ) ) {
00341 $sActCat = reset( $aArticleCats );
00342
00343 $sListType = null;
00344 } elseif ( ( $sActCat = $oProduct->getManufacturerId() ) ) {
00345
00346
00347 $sListType = 'manufacturer';
00348 } elseif ( ( $sActCat = $oProduct->getVendorId() ) ) {
00349
00350
00351 $sListType = 'vendor';
00352 } else {
00353 $sActCat = null;
00354 }
00355 }
00356 } elseif ( !$sActCat && !$sActCont && !$sActManufacturer && !$blTags ) {
00357 $aArticleCats = $oProduct->getCategoryIds(true);
00358 if ( is_array( $aArticleCats ) && count( $aArticleCats ) ) {
00359 $sActCat = reset( $aArticleCats );
00360
00361 $sListType = null;
00362 } elseif ( ( $sActCat = $oProduct->getManufacturerId() ) ) {
00363
00364
00365 $sListType = 'manufacturer';
00366 } elseif ( ( $sActCat = $oProduct->getVendorId() ) ) {
00367
00368
00369 $sListType = 'vendor';
00370 }
00371 }
00372 }
00373 }
00374
00375 $this->_oParent->setListType( $sListType );
00376 $this->_oParent->setCategoryId( $sActCat );
00377
00378 return $sActCat;
00379 }
00380 }