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         $sActCat = $this->_getActCat();
00042 
00043         if ( $myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
00044             // building vendor tree
00045             $this->_loadVendorTree( $sActCat );
00046         }
00047 
00048         if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00049             // building Manufacturer tree
00050             $sActManufacturer = oxConfig::getParameter( 'mnid' );
00051             $this->_loadManufacturerTree( $sActManufacturer );
00052         }
00053 
00054         if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) ) {
00055 
00056             // building categorytree for all purposes (nav, search and simple category trees)
00057             $this->_loadCategoryTree( $sActCat );
00058 
00059             if ( $myConfig->getConfigParam( 'blTopNaviLayout' ) ) {
00060                 if ( ! ( $sActCont = oxConfig::getParameter( 'oxcid' ) ) ) {
00061                     $sActCont = oxConfig::getParameter( 'tpl' );
00062                 }
00063                 $this->_oMoreCat = $this->_getMoreCategory( $sActCat, $sActCont );
00064             }
00065         }
00066     }
00067 
00073     public function getProduct()
00074     {
00075         if ( ( $sActProduct = oxConfig::getParameter( 'anid' ) ) ) {
00076             $oParentView = $this->getParent();
00077             if ( ( $oProduct = $oParentView->getViewProduct() ) ) {
00078                 return $oProduct;
00079             } else {
00080                 $oProduct = oxNew( 'oxarticle' );
00081                 if ( $oProduct->load( $sActProduct ) ) {
00082                     // storing for reuse
00083                     $oParentView->setViewProduct( $oProduct );
00084                     return $oProduct;
00085                 }
00086             }
00087         }
00088     }
00089 
00095     protected function _getActCat()
00096     {
00097         if ( ! ( $sActCont = oxConfig::getParameter( 'oxcid' ) ) ) {
00098             $sActCont = oxConfig::getParameter( 'tpl' );
00099         }
00100         $sActManufacturer = oxConfig::getParameter( 'mnid' );
00101         $sActTag = oxConfig::getParameter( 'searchtag' );
00102         $sActCat = $sActManufacturer ? null : oxConfig::getParameter( 'cnid' );
00103 
00104         // loaded article - then checking additional parameters
00105         $oProduct = $this->getProduct();
00106         if ( $oProduct ) {
00107             $myConfig = $this->getConfig();
00108 
00109             $sActManufacturer = $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ? $sActManufacturer : null;
00110             $sActVendor = ( $myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) && getStr()->preg_match( '/^v_.?/i', $sActCat ) ) ? $sActCat : null;
00111 
00112             $sActCat = $this->_addAdditionalParams( $oProduct, $sActCat, $sActManufacturer, $sActCont, $sActTag, $sActVendor );
00113         }
00114 
00115         // Checking for the default category
00116         if ( $sActCat === null && !$oProduct && !$sActCont && !$sActManufacturer && !$sActTag ) {
00117             // set remote cat
00118             $sActCat = $this->getConfig()->getActiveShop()->oxshops__oxdefcat->value;
00119             if ( $sActCat == 'oxrootid' ) {
00120                 // means none selected
00121                 $sActCat= null;
00122             }
00123         }
00124         return $sActCat;
00125     }
00126 
00134     protected function _loadCategoryTree( $sActCat )
00135     {
00136         $myConfig = $this->getConfig();
00137         if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) ) {
00138             $oCategoryTree = oxNew( 'oxcategorylist' );
00139             $oCategoryTree->buildTree( $sActCat, $myConfig->getConfigParam( 'blLoadFullTree' ), $myConfig->getConfigParam( 'bl_perfLoadTreeForSearch' ), $myConfig->getConfigParam( 'blTopNaviLayout' ) );
00140 
00141             $oParentView = $this->getParent();
00142 
00143             // setting active category tree
00144             $oParentView->setCategoryTree( $oCategoryTree );
00145 
00146             // setting active category
00147             $oParentView->setActCategory( $oCategoryTree->getClickCat() );
00148         }
00149     }
00150 
00158     protected function _loadVendorTree( $sActVendor )
00159     {
00160         $myConfig = $this->getConfig();
00161         if ( $myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) ) {
00162             $oVendorTree = oxNew( 'oxvendorlist' );
00163             $oVendorTree->buildVendorTree( 'vendorlist', $sActVendor, $myConfig->getShopHomeURL() );
00164 
00165             $oParentView = $this->getParent();
00166 
00167             // setting active vendor list
00168             $oParentView->setVendorTree( $oVendorTree );
00169 
00170             // setting active vendor
00171             if ( ( $oVendor = $oVendorTree->getClickVendor() ) ) {
00172                 $oParentView->setActVendor( $oVendor );
00173             }
00174         }
00175     }
00176 
00184     protected function _loadManufacturerTree( $sActManufacturer )
00185     {
00186         $myConfig = $this->getConfig();
00187         if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00188             $oManufacturerTree = oxNew( 'oxmanufacturerlist' );
00189             $oManufacturerTree->buildManufacturerTree( 'manufacturerlist', $sActManufacturer, $myConfig->getShopHomeURL() );
00190 
00191             $oParentView = $this->getParent();
00192 
00193             // setting active Manufacturer list
00194             $oParentView->setManufacturerTree( $oManufacturerTree );
00195 
00196             // setting active Manufacturer
00197             if ( ( $oManufacturer = $oManufacturerTree->getClickManufacturer() ) ) {
00198                 $oParentView->setActManufacturer( $oManufacturer );
00199             }
00200         }
00201     }
00202 
00209     public function render()
00210     {
00211         parent::render();
00212 
00213         // Performance
00214         $myConfig = $this->getConfig();
00215         $oParentView = $this->getParent();
00216 
00217         if ( $myConfig->getConfigParam( 'bl_perfLoadVendorTree' ) &&
00218              ( $oVendorTree = $oParentView->getVendorTree() )) {
00219             $oParentView->setVendorlist( $oVendorTree );
00220             $oParentView->setRootVendor( $oVendorTree->getRootCat() );
00221         }
00222 
00223         if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) &&
00224              ( $oManufacturerTree = $oParentView->getManufacturerTree() ) ) {
00225             $oParentView->setManufacturerlist( $oManufacturerTree );
00226             $oParentView->setRootManufacturer( $oManufacturerTree->getRootCat() );
00227         }
00228 
00229         if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) &&
00230              ( $oCategoryTree = $oParentView->getCategoryTree() ) ) {
00231 
00232             // we loaded full category tree ?
00233             if ( $myConfig->getConfigParam( 'bl_perfLoadTreeForSearch' ) ) {
00234                 $oParentView->setSearchCatTree( $oCategoryTree );
00235             }
00236 
00237             // new navigation ?
00238             if ( $myConfig->getConfigParam( 'blTopNaviLayout' ) ) {
00239                 $oParentView->setCatMore( $this->_oMoreCat );
00240             }
00241 
00242             return $oCategoryTree;
00243         }
00244     }
00245 
00254     protected function _getMoreCategory( $sActCat, $sActCont )
00255     {
00256         $myConfig = $this->getConfig();
00257         $blExpanded = false;
00258 
00259         if ( $sActCat == 'oxmore' ) {
00260             $blExpanded = true;
00261         } else {
00262             $iTopCount = $myConfig->getConfigParam( 'iTopNaviCatCount' );
00263             $oCategoryTree = $this->getParent()->getCategoryTree();
00264             if ( $oCategoryTree ) {
00265                 $iCnt = 0;
00266                 foreach ( $oCategoryTree as $oCat ) {
00267                     $iCnt++;
00268 
00269                     if ( ( $aContent = $oCat->getContentCats() ) ) {
00270                         foreach ( $aContent as $oContent ) {
00271                             if ( $sActCont == $oContent->getId() && ($iCnt > $iTopCount )) {
00272                                 $blExpanded = true;
00273                                 break 2;
00274                             }
00275                             $iCnt++;
00276                         }
00277                     }
00278 
00279                     if ( $oCat->getExpanded() && ($iCnt > $iTopCount )) {
00280                         $blExpanded = true;
00281                         break;
00282                     }
00283                 }
00284             }
00285         }
00286 
00287         $oMoreCat = new oxStdClass();
00288         $oMoreCat->closelink = $oMoreCat->openlink = $myConfig->getShopHomeURL().'cnid=oxmore';
00289         $oMoreCat->expanded  = $blExpanded;
00290         return $oMoreCat;
00291     }
00292 
00305     protected function _addAdditionalParams( $oProduct, $sActCat, $sActManufacturer, $sActCont, $sActTag, $sActVendor )
00306     {
00307         $sSearchPar = oxConfig::getParameter( 'searchparam' );
00308         $sSearchCat = oxConfig::getParameter( 'searchcnid' );
00309         $sSearchVnd = oxConfig::getParameter( 'searchvendor' );
00310         $sSearchMan = oxConfig::getParameter( 'searchmanufacturer' );
00311         $sListType  = oxConfig::getParameter( 'listtype' );
00312 
00313         // search ?
00314         if ( ( !$sListType || $sListType == 'search' ) && ( $sSearchPar || $sSearchCat || $sSearchVnd || $sSearchMan ) ) {
00315             // setting list type directly
00316             $sListType = 'search';
00317         } else {
00318 
00319             // such Manufacturer is available ?
00320             if ( $sActManufacturer && ( $sActManufacturer == $oProduct->getManufacturerId() ) ) {
00321                 // setting list type directly
00322                 $sListType = 'manufacturer';
00323                 $sActCat   = $sActManufacturer;
00324             } elseif ( $sActVendor && ( substr( $sActVendor, 2 ) == $oProduct->getVendorId() ) ) {
00325                 // such vendor is available ?
00326                 $sListType = 'vendor';
00327                 $sActCat   = $sActVendor;
00328             } elseif ( $sActTag ) {
00329                 // tag ?
00330                 $sListType = 'tag';
00331             } elseif ( $sActCat && $oProduct->isAssignedToCategory( $sActCat ) ) {
00332                 // category ?
00333             } else {
00334                 list( $sListType, $sActCat ) = $this->_getDefaultParams( $oProduct );
00335             }
00336         }
00337 
00338         $oParentView = $this->getParent();
00339         //set list type and category id
00340         $oParentView->setListType( $sListType );
00341         $oParentView->setCategoryId( $sActCat );
00342 
00343         return $sActCat;
00344     }
00345 
00353     protected function _getDefaultParams( $oProduct )
00354     {
00355         $sListType = null;
00356         $aArticleCats = $oProduct->getCategoryIds( true );
00357         if ( is_array( $aArticleCats ) && count( $aArticleCats ) ) {
00358             $sActCat = reset( $aArticleCats );
00359         } elseif ( ( $sActCat = $oProduct->getManufacturerId() ) ) {
00360             // not assigned to any category ? maybe it is assigned to Manufacturer ?
00361             $sListType = 'manufacturer';
00362         } elseif ( ( $sActCat = $oProduct->getVendorId() ) ) {
00363             // not assigned to any category ? maybe it is assigned to vendor ?
00364             $sListType = 'vendor';
00365         } else {
00366             $sActCat = null;
00367         }
00368 
00369         return array( $sListType, $sActCat );
00370     }
00371 }