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( 'bl_perfLoadCatTree' ) ||
00037 ( $myConfig->getConfigParam( 'blDisableNavBars' ) &&
00038 $myConfig->getActiveView()->getIsOrderStep() ) ) {
00039 return;
00040 }
00041
00042 $sActProduct = oxConfig::getParameter( 'anid' );
00043 $sActCat = oxConfig::getParameter( 'cnid' );
00044
00045 $sActCont = false;
00046
00047
00048 $blArtLoaded = false;
00049 if ( $sActProduct ) {
00050 $oProduct = oxNew( 'oxarticle' );
00051 $oProduct->setSkipAbPrice( true );
00052 if ( $oProduct->load( $sActProduct ) ) {
00053
00054
00055 $this->_oParent->setViewProduct( $oProduct );
00056 $blArtLoaded = true;
00057 }
00058 }
00059
00060
00061 if ( $blArtLoaded ) {
00062 $sActCat = $this->_addAdditionalParams( $oProduct, $sActCat, $sActCont );
00063 }
00064
00065
00066 if ( $sActCat === null && !$blArtLoaded && !$sActCont ) {
00067
00068 $sActCat = $myConfig->getActiveShop()->oxshops__oxdefcat->value;
00069 if ( $sActCat == 'oxrootid' ) {
00070
00071 $sActCat= null;
00072 }
00073 }
00074
00075 if ( $myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
00076
00077 $this->_loadVendorTree( $sActCat );
00078 }
00079
00080
00081 $this->_loadCategoryTree( $sActCat );
00082
00083 if ( $myConfig->getConfigParam( 'blTopNaviLayout' ) ) {
00084 $this->_oMoreCat = $this->_getMoreCategory( $sActCat, $sActCont );
00085 }
00086
00087 if ( oxUtils::getInstance()->seoIsActive() ) {
00088
00089 $this->_oParent->setSessionCategoryId( $sActCat );
00090 }
00091 }
00092
00100 protected function _loadCategoryTree( $sActCat )
00101 {
00102 $myConfig = $this->getConfig();
00103 if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) ) {
00104 $oCategoryTree = oxNew( 'oxcategorylist' );
00105 $oCategoryTree->buildTree( $sActCat, $myConfig->getConfigParam( 'blLoadFullTree' ), $myConfig->getConfigParam( 'bl_perfLoadTreeForSearch' ), $myConfig->getConfigParam( 'blTopNaviLayout' ) );
00106
00107
00108 $this->_oParent->setCategoryTree( $oCategoryTree );
00109
00110
00111 $this->_oParent->setActCategory( $oCategoryTree->getClickCat() );
00112 }
00113 }
00114
00122 protected function _loadVendorTree( $sActVendor )
00123 {
00124 $myConfig = $this->getConfig();
00125 if ( $myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
00126 $oVendorTree = oxNew( 'oxvendorlist' );
00127 $oVendorTree->buildVendorTree( 'vendorlist', $sActVendor, $myConfig->getShopHomeURL() );
00128
00129
00130 $this->_oParent->setVendorTree( $oVendorTree );
00131
00132
00133 if ( ( $oVendor = $oVendorTree->getClickVendor() ) ) {
00134 $this->_oParent->setActVendor( $oVendor );
00135 }
00136 }
00137 }
00138
00145 public function render()
00146 {
00147 parent::render();
00148
00149
00150 $myConfig = $this->getConfig();
00151 if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) ) {
00152
00153 if ( $myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
00154
00155 if ( ( $oVendorTree = $this->_oParent->getVendorTree() ) ) {
00156 $this->_oParent->setVendorlist( $oVendorTree );
00157 $this->_oParent->setRootVendor( $oVendorTree->getRootCat() );
00158
00159
00160 $this->_oParent->addTplParam( 'rootvendor', $this->_oParent->getRootVendor() );
00161 $this->_oParent->addTplParam( 'aVendorlist', $this->_oParent->getVendorlist() );
00162 $this->_oParent->addTplParam( 'sVendorID', $this->_oParent->getVendorId() );
00163 }
00164 }
00165
00166
00167 $oCategoryTree = $this->_oParent->getCategoryTree();
00168
00169
00170 if ( $oCategoryTree && $myConfig->getConfigParam( 'bl_perfLoadTreeForSearch' ) ) {
00171 $this->_oParent->setSearchCatTree($oCategoryTree);
00172
00173 $this->_oParent->addTplParam( 'aSearchCatTree', $this->_oParent->getSearchCatTree());
00174 }
00175
00176
00177 if ( $myConfig->getConfigParam( 'blTopNaviLayout' ) && $oCategoryTree ) {
00178 $this->_oParent->setCatMore($this->_oMoreCat);
00179
00180 $this->_oParent->addTplParam( 'navcategorytree', $oCategoryTree );
00181 $this->_oParent->addTplParam( 'navcategorycount', $oCategoryTree->count() );
00182 $this->_oParent->addTplParam( 'navcatmore', $this->_oParent->getCatMore() );
00183 }
00184
00185
00186 return $oCategoryTree;
00187 }
00188 }
00189
00198 protected function _getMoreCategory( $sActCat, $sActCont )
00199 {
00200 $myConfig = $this->getConfig();
00201 $iTopCount = $myConfig->getConfigParam( 'iTopNaviCatCount' );
00202 $blExpanded = false;
00203
00204 if ( $sActCat == 'oxmore' ) {
00205 $blExpanded = true;
00206 } else {
00207 $oCategoryTree = $this->_oParent->getCategoryTree();
00208 if ( $oCategoryTree ) {
00209 $iCnt = 0;
00210 foreach ( $oCategoryTree as $oCat ) {
00211 $iCnt++;
00212
00213 if ( ( $aContent = $oCat->getContentCats() ) ) {
00214 foreach ( $aContent as $oContent ) {
00215 if ( $sActCont == $oContent->getId() && $iCnt > $iTopCount ) {
00216 $blExpanded = true;
00217 break 2;
00218 }
00219 $iCnt++;
00220 }
00221 }
00222
00223 if ( $oCat->getExpanded() && $iCnt > $iTopCount ) {
00224 $blExpanded = true;
00225 break;
00226 }
00227 }
00228 }
00229 }
00230
00231 $oMoreCat = new oxStdClass();
00232 $oMoreCat->closelink = $oMoreCat->openlink = $myConfig->getShopHomeURL().'cnid=oxmore';
00233 $oMoreCat->expanded = $blExpanded;
00234 return $oMoreCat;
00235 }
00236
00246 protected function _addAdditionalParams( $oProduct, $sActCat, $sActCont )
00247 {
00248 $sSearchPar = oxConfig::getParameter( 'searchparam' );
00249 $sSearchCat = oxConfig::getParameter( 'searchcnid' );
00250 $sSearchVnd = oxConfig::getParameter( 'searchvendor' );
00251 $sListType = oxConfig::getParameter( 'listtype' );
00252
00253 if ( oxUtils::getInstance()->seoIsActive() ) {
00254
00255 if ( ( $sSessCat = $this->_oParent->getSessionCategoryId() ) !== null ) {
00256 $sActCat = $sSessCat;
00257 }
00258 }
00259
00260
00261
00262
00263
00264
00265 if ( !$sListType && ( $sSearchPar || $sSearchCat || $sSearchVnd ) ) {
00266
00267 $sListType = 'search';
00268 } else {
00269
00270 $blVendor = false;
00271 if ( $sActCat && $this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) && eregi( '^v_.?', $sActCat ) ) {
00272
00273 if ( substr( $sActCat, 2 ) == $oProduct->getVendorId() ) {
00274 $blVendor = true;
00275
00276 $sListType = 'vendor';
00277 }
00278 }
00279
00280
00281 if ( $sActCat && !$blVendor ) {
00282 if ( !$oProduct->isAssignedToCategory( $sActCat ) ) {
00283
00284 $aArticleCats = $oProduct->getCategoryIds();
00285 if ( is_array( $aArticleCats ) && count( $aArticleCats ) ) {
00286 $sActCat = reset( $aArticleCats );
00287
00288 $sListType = null;
00289 } elseif ( ( $sActCat = $oProduct->getVendorId() ) ) {
00290
00291
00292 $sListType = 'vendor';
00293 } else {
00294 $sActCat = null;
00295 }
00296 }
00297 } elseif ( !$sActCat && !$sActCont ) {
00298 $aArticleCats = $oProduct->getCategoryIds();
00299 if ( is_array( $aArticleCats ) && count( $aArticleCats ) ) {
00300 $sActCat = reset( $aArticleCats );
00301
00302 $sListType = null;
00303 } elseif ( ( $sActCat = $oProduct->getVendorId() ) ) {
00304
00305
00306 $sListType = 'vendor';
00307 }
00308 }
00309 }
00310
00311
00312 $this->_oParent->setListType( $sListType );
00313 $this->_oParent->setCategoryId( $sActCat );
00314
00315 return $sActCat;
00316 }
00317 }