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

Generated on Tue Sep 29 16:45:15 2009 for OXID eShop CE by  doxygen 1.5.5