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

Generated on Wed May 13 13:25:55 2009 for OXID eShop CE by  doxygen 1.5.5