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