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

Generated on Thu Feb 19 15:02:22 2009 for OXID eShop CE by  doxygen 1.5.5