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