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 
00025     protected $_oCategoryTree = null;
00026 
00031     protected $_oManufacturerTree = null;
00032 
00042     public function init()
00043     {
00044         parent::init();
00045 
00046         // Performance
00047         $myConfig = $this->getConfig();
00048         if ( $myConfig->getConfigParam( 'blDisableNavBars' ) &&
00049              $myConfig->getTopActiveView()->getIsOrderStep() ) {
00050             return;
00051         }
00052 
00053         $sActCat = $this->_getActCat();
00054 
00055         if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00056             // building Manufacturer tree
00057             $sActManufacturer = oxConfig::getParameter( 'mnid' );
00058             $this->_loadManufacturerTree( $sActManufacturer );
00059         }
00060 
00061         if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) ) {
00062             // building category tree for all purposes (nav, search and simple category trees)
00063             $this->_loadCategoryTree( $sActCat );
00064         }
00065     }
00066 
00072     public function getProduct()
00073     {
00074         if ( ( $sActProduct = oxConfig::getParameter( 'anid' ) ) ) {
00075             $oParentView = $this->getParent();
00076             if ( ( $oProduct = $oParentView->getViewProduct() ) ) {
00077                 return $oProduct;
00078             } else {
00079                 $oProduct = oxNew( 'oxarticle' );
00080                 if ( $oProduct->load( $sActProduct ) ) {
00081                     // storing for reuse
00082                     $oParentView->setViewProduct( $oProduct );
00083                     return $oProduct;
00084                 }
00085             }
00086         }
00087     }
00088 
00094     protected function _getActCat()
00095     {
00096         $sActManufacturer = oxConfig::getParameter( 'mnid' );
00097         $sActTag = oxConfig::getParameter( 'searchtag' );
00098         $sActCat = $sActManufacturer ? null : oxConfig::getParameter( 'cnid' );
00099 
00100         // loaded article - then checking additional parameters
00101         $oProduct = $this->getProduct();
00102         if ( $oProduct ) {
00103             $myConfig = $this->getConfig();
00104 
00105             $sActManufacturer = $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ? $sActManufacturer : null;
00106 
00107             $sActVendor = ( getStr()->preg_match( '/^v_.?/i', $sActCat ) ) ? $sActCat : null;
00108 
00109             $sActCat = $this->_addAdditionalParams( $oProduct, $sActCat, $sActManufacturer, $sActTag, $sActVendor );
00110         }
00111 
00112         // Checking for the default category
00113         if ( $sActCat === null && !$oProduct && !$sActManufacturer && !$sActTag ) {
00114             // set remote cat
00115             $sActCat = $this->getConfig()->getActiveShop()->oxshops__oxdefcat->value;
00116             if ( $sActCat == 'oxrootid' ) {
00117                 // means none selected
00118                 $sActCat= null;
00119             }
00120         }
00121         return $sActCat;
00122     }
00123 
00131     protected function _loadCategoryTree( $sActCat )
00132     {
00133         $myConfig = $this->getConfig();
00134         if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) ) {
00135             $oCategoryTree = oxNew( 'oxcategorylist' );
00136             $oCategoryTree->buildTree( $sActCat, $myConfig->getConfigParam( 'blLoadFullTree' ), $myConfig->getConfigParam( 'bl_perfLoadTreeForSearch' ) );
00137 
00138             $oParentView = $this->getParent();
00139 
00140             // setting active category tree
00141             $oParentView->setCategoryTree( $oCategoryTree );
00142             $this->setCategoryTree($oCategoryTree);
00143 
00144             // setting active category
00145             $oParentView->setActiveCategory( $oCategoryTree->getClickCat() );
00146         }
00147     }
00148 
00156     protected function _loadManufacturerTree( $sActManufacturer )
00157     {
00158         $myConfig = $this->getConfig();
00159         if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00160             $oManufacturerTree = oxNew( 'oxmanufacturerlist' );
00161             $oManufacturerTree->buildManufacturerTree( 'manufacturerlist', $sActManufacturer, $myConfig->getShopHomeURL() );
00162 
00163             $oParentView = $this->getParent();
00164 
00165             // setting active Manufacturer list
00166             $oParentView->setManufacturerTree( $oManufacturerTree );
00167             $this->setManufacturerTree($oManufacturerTree);
00168 
00169             // setting active Manufacturer
00170             if ( ( $oManufacturer = $oManufacturerTree->getClickManufacturer() ) ) {
00171                 $oParentView->setActManufacturer( $oManufacturer );
00172             }
00173         }
00174     }
00175 
00182     public function render()
00183     {
00184         parent::render();
00185 
00186         // Performance
00187         $myConfig = $this->getConfig();
00188         $oParentView = $this->getParent();
00189 
00190         if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) && $this->_oManufacturerTree ) {
00191             $oParentView->setManufacturerlist( $this->_oManufacturerTree );
00192             $oParentView->setRootManufacturer( $this->_oManufacturerTree->getRootCat() );
00193         }
00194 
00195         if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) && $this->_oCategoryTree ) {
00196 
00197             // we loaded full category tree ?
00198             if ( $myConfig->getConfigParam( 'bl_perfLoadTreeForSearch' ) ) {
00199                 $oParentView->setSearchCatTree( $this->_oCategoryTree );
00200             }
00201 
00202             return $this->_oCategoryTree;
00203         }
00204     }
00205 
00217     protected function _addAdditionalParams( $oProduct, $sActCat, $sActManufacturer, $sActTag, $sActVendor )
00218     {
00219         $sSearchPar = oxConfig::getParameter( 'searchparam' );
00220         $sSearchCat = oxConfig::getParameter( 'searchcnid' );
00221         $sSearchVnd = oxConfig::getParameter( 'searchvendor' );
00222         $sSearchMan = oxConfig::getParameter( 'searchmanufacturer' );
00223         $sListType  = oxConfig::getParameter( 'listtype' );
00224 
00225         // search ?
00226         if ( ( !$sListType || $sListType == 'search' ) && ( $sSearchPar || $sSearchCat || $sSearchVnd || $sSearchMan ) ) {
00227             // setting list type directly
00228             $sListType = 'search';
00229         } else {
00230 
00231             // such Manufacturer is available ?
00232             if ( $sActManufacturer && ( $sActManufacturer == $oProduct->getManufacturerId() ) ) {
00233                 // setting list type directly
00234                 $sListType = 'manufacturer';
00235                 $sActCat   = $sActManufacturer;
00236             } elseif ( $sActVendor && ( substr( $sActVendor, 2 ) == $oProduct->getVendorId() ) ) {
00237                 // such vendor is available ?
00238                 $sListType = 'vendor';
00239                 $sActCat   = $sActVendor;
00240             } elseif ( $sActTag ) {
00241                 // tag ?
00242                 $sListType = 'tag';
00243             } elseif ( $sActCat && $oProduct->isAssignedToCategory( $sActCat ) ) {
00244                 // category ?
00245             } else {
00246                 list( $sListType, $sActCat ) = $this->_getDefaultParams( $oProduct );
00247             }
00248         }
00249 
00250         $oParentView = $this->getParent();
00251         //set list type and category id
00252         $oParentView->setListType( $sListType );
00253         $oParentView->setCategoryId( $sActCat );
00254 
00255         return $sActCat;
00256     }
00257 
00265     protected function _getDefaultParams( $oProduct )
00266     {
00267         $sListType = null;
00268         $aArticleCats = $oProduct->getCategoryIds( true );
00269         if ( is_array( $aArticleCats ) && count( $aArticleCats ) ) {
00270             $sActCat = reset( $aArticleCats );
00271         } elseif ( ( $sActCat = $oProduct->getManufacturerId() ) ) {
00272             // not assigned to any category ? maybe it is assigned to Manufacturer ?
00273             $sListType = 'manufacturer';
00274         } elseif ( ( $sActCat = $oProduct->getVendorId() ) ) {
00275             // not assigned to any category ? maybe it is assigned to vendor ?
00276             $sListType = 'vendor';
00277         } else {
00278             $sActCat = null;
00279         }
00280 
00281         return array( $sListType, $sActCat );
00282     }
00283 
00291     public function setCategoryTree( $oCategoryTree )
00292     {
00293         $this->_oCategoryTree = $oCategoryTree;
00294     }
00295 
00303     public function setManufacturerTree( $oManufacturerTree )
00304     {
00305         $this->_oManufacturerTree = $oManufacturerTree;
00306     }
00307 }