oxcmp_categories.php

Go to the documentation of this file.
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         // Performance
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                 // storing for reusage
00055                 $this->_oParent->setViewProduct( $oProduct );
00056                 $blArtLoaded = true;
00057             }
00058         }
00059 
00060         // loaded article - then checking additional parameters
00061         if ( $blArtLoaded ) {
00062             $sActCat = $this->_addAdditionalParams( $oProduct, $sActCat, $sActCont );
00063         }
00064 
00065         // Checking for the default category
00066         if ( $sActCat === null && !$blArtLoaded && !$sActCont ) {
00067             // set remote cat
00068             $sActCat = $myConfig->getActiveShop()->oxshops__oxdefcat->value;
00069             if ( $sActCat == 'oxrootid' ) {
00070                 // means none selected
00071                 $sActCat= null;
00072             }
00073         }
00074 
00075         if ( $myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
00076             // building vendor tree
00077             $this->_loadVendorTree( $sActCat );
00078         }
00079 
00080         // building categorytree for all purposes (nav, search and simple category trees)
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             // tracking active category
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             // setting active category tree
00108             $this->_oParent->setCategoryTree( $oCategoryTree );
00109 
00110             // setting active category
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             // setting active vendor list
00130             $this->_oParent->setVendorTree( $oVendorTree );
00131 
00132             // setting active vendor
00133             if ( ( $oVendor = $oVendorTree->getClickVendor() ) ) {
00134                 $this->_oParent->setActVendor( $oVendor );
00135             }
00136         }
00137     }
00138 
00145     public function render()
00146     {
00147         parent::render();
00148 
00149         // Performance
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                     // Passing to view. Left for compatibility reasons for a while. Will be removed in future
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             // PE issue, category tree is not loaded in basket
00167             $oCategoryTree = $this->_oParent->getCategoryTree();
00168 
00169             // we loaded full category tree ?
00170             if ( $oCategoryTree && $myConfig->getConfigParam( 'bl_perfLoadTreeForSearch' ) ) {
00171                 $this->_oParent->setSearchCatTree($oCategoryTree);
00172                 // Passing to view. Left for compatibility reasons for a while. Will be removed in future
00173                 $this->_oParent->addTplParam( 'aSearchCatTree', $this->_oParent->getSearchCatTree());
00174             }
00175 
00176             // new navigation ?
00177             if ( $myConfig->getConfigParam( 'blTopNaviLayout' ) && $oCategoryTree ) {
00178                 $this->_oParent->setCatMore($this->_oMoreCat);
00179                 // Passing to view. Left for compatibility reasons for a while. Will be removed in future
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             // tracking active category
00255             if ( ( $sSessCat = $this->_oParent->getSessionCategoryId() ) !== null ) {
00256                 $sActCat = $sSessCat;
00257             }
00258         }
00259 
00260         // search ?
00261         //if ( !$sListType ) {
00262         // removed this check according to problems: if listtype is set, but active category not.
00263         // e.g. in details change language
00264 
00265         if ( !$sListType && ( $sSearchPar || $sSearchCat || $sSearchVnd ) ) {
00266             // setting list type directly
00267             $sListType = 'search';
00268         } else {
00269             // vendor ?
00270             $blVendor = false;
00271             if ( $sActCat && $this->getConfig()->getConfigParam( 'bl_perfLoadVendorTree' ) && eregi( '^v_.?', $sActCat ) ) {
00272                 // such vendor is available ?
00273                 if ( substr( $sActCat, 2 ) == $oProduct->getVendorId() ) {
00274                     $blVendor = true;
00275                     // setting list type directly
00276                     $sListType = 'vendor';
00277                 }
00278             }
00279 
00280             // category ?
00281             if ( $sActCat && !$blVendor ) {
00282                 if ( !$oProduct->isAssignedToCategory( $sActCat ) ) {
00283                     // article is assigned to any category ?
00284                     $aArticleCats = $oProduct->getCategoryIds();
00285                     if ( is_array( $aArticleCats ) && count( $aArticleCats ) ) {
00286                         $sActCat = reset( $aArticleCats );
00287                         // setting list type directly
00288                         $sListType = null;
00289                     } elseif ( ( $sActCat = $oProduct->getVendorId() ) ) {
00290                         // not assigned to any category ? maybe it is assigned to vendor ?
00291                         // setting list type directly
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                     // setting list type directly
00302                     $sListType  = null;
00303                 } elseif ( ( $sActCat = $oProduct->getVendorId() ) ) {
00304                     // not assigned to any category ? maybe it is assigned to vendor ?
00305                     // setting list type directly
00306                     $sListType = 'vendor';
00307                 }
00308             }
00309         }
00310 
00311         //set list type and category id
00312         $this->_oParent->setListType( $sListType );
00313         $this->_oParent->setCategoryId( $sActCat );
00314 
00315         return $sActCat;
00316     }
00317 }

Generated on Thu Dec 4 12:04:57 2008 for OXID eShop CE by  doxygen 1.5.5