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         // building category tree for all purposes (nav, search and simple category trees)
00062         $this->_loadCategoryTree( $sActCat );
00063     }
00064 
00070     public function getProduct()
00071     {
00072         if ( ( $sActProduct = oxConfig::getParameter( 'anid' ) ) ) {
00073             $oParentView = $this->getParent();
00074             if ( ( $oProduct = $oParentView->getViewProduct() ) ) {
00075                 return $oProduct;
00076             } else {
00077                 $oProduct = oxNew( 'oxarticle' );
00078                 if ( $oProduct->load( $sActProduct ) ) {
00079                     // storing for reuse
00080                     $oParentView->setViewProduct( $oProduct );
00081                     return $oProduct;
00082                 }
00083             }
00084         }
00085     }
00086 
00092     protected function _getActCat()
00093     {
00094         $sActManufacturer = oxConfig::getParameter( 'mnid' );
00095         $sActTag = oxConfig::getParameter( 'searchtag' );
00096         $sActCat = $sActManufacturer ? null : oxConfig::getParameter( 'cnid' );
00097 
00098         // loaded article - then checking additional parameters
00099         $oProduct = $this->getProduct();
00100         if ( $oProduct ) {
00101             $myConfig = $this->getConfig();
00102 
00103             $sActManufacturer = $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ? $sActManufacturer : null;
00104 
00105             $sActVendor = ( getStr()->preg_match( '/^v_.?/i', $sActCat ) ) ? $sActCat : null;
00106 
00107             $sActCat = $this->_addAdditionalParams( $oProduct, $sActCat, $sActManufacturer, $sActTag, $sActVendor );
00108         }
00109 
00110         // Checking for the default category
00111         if ( $sActCat === null && !$oProduct && !$sActManufacturer && !$sActTag ) {
00112             // set remote cat
00113             $sActCat = $this->getConfig()->getActiveShop()->oxshops__oxdefcat->value;
00114             if ( $sActCat == 'oxrootid' ) {
00115                 // means none selected
00116                 $sActCat= null;
00117             }
00118         }
00119         return $sActCat;
00120     }
00121 
00129     protected function _loadCategoryTree( $sActCat )
00130     {
00131         $oCategoryTree = oxNew( 'oxCategoryList' );
00132         $oCategoryTree->buildTree( $sActCat );
00133 
00134         $oParentView = $this->getParent();
00135 
00136         // setting active category tree
00137         $oParentView->setCategoryTree( $oCategoryTree );
00138         $this->setCategoryTree( $oCategoryTree );
00139 
00140         // setting active category
00141         $oParentView->setActiveCategory( $oCategoryTree->getClickCat() );
00142     }
00143 
00151     protected function _loadManufacturerTree( $sActManufacturer )
00152     {
00153         $myConfig = $this->getConfig();
00154         if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00155             $oManufacturerTree = oxNew( 'oxmanufacturerlist' );
00156             $oManufacturerTree->buildManufacturerTree( 'manufacturerlist', $sActManufacturer, $myConfig->getShopHomeURL() );
00157 
00158             $oParentView = $this->getParent();
00159 
00160             // setting active Manufacturer list
00161             $oParentView->setManufacturerTree( $oManufacturerTree );
00162             $this->setManufacturerTree($oManufacturerTree);
00163 
00164             // setting active Manufacturer
00165             if ( ( $oManufacturer = $oManufacturerTree->getClickManufacturer() ) ) {
00166                 $oParentView->setActManufacturer( $oManufacturer );
00167             }
00168         }
00169     }
00170 
00177     public function render()
00178     {
00179         parent::render();
00180 
00181         // Performance
00182         $myConfig = $this->getConfig();
00183         $oParentView = $this->getParent();
00184 
00185         if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) && $this->_oManufacturerTree ) {
00186             $oParentView->setManufacturerlist( $this->_oManufacturerTree );
00187             $oParentView->setRootManufacturer( $this->_oManufacturerTree->getRootCat() );
00188         }
00189 
00190         if ( $this->_oCategoryTree ) {
00191             return $this->_oCategoryTree;
00192         }
00193     }
00194 
00206     protected function _addAdditionalParams( $oProduct, $sActCat, $sActManufacturer, $sActTag, $sActVendor )
00207     {
00208         $sSearchPar = oxConfig::getParameter( 'searchparam' );
00209         $sSearchCat = oxConfig::getParameter( 'searchcnid' );
00210         $sSearchVnd = oxConfig::getParameter( 'searchvendor' );
00211         $sSearchMan = oxConfig::getParameter( 'searchmanufacturer' );
00212         $sListType  = oxConfig::getParameter( 'listtype' );
00213 
00214         // search ?
00215         if ( ( !$sListType || $sListType == 'search' ) && ( $sSearchPar || $sSearchCat || $sSearchVnd || $sSearchMan ) ) {
00216             // setting list type directly
00217             $sListType = 'search';
00218         } else {
00219 
00220             // such Manufacturer is available ?
00221             if ( $sActManufacturer && ( $sActManufacturer == $oProduct->getManufacturerId() ) ) {
00222                 // setting list type directly
00223                 $sListType = 'manufacturer';
00224                 $sActCat   = $sActManufacturer;
00225             } elseif ( $sActVendor && ( substr( $sActVendor, 2 ) == $oProduct->getVendorId() ) ) {
00226                 // such vendor is available ?
00227                 $sListType = 'vendor';
00228                 $sActCat   = $sActVendor;
00229             } elseif ( $sActTag ) {
00230                 // tag ?
00231                 $sListType = 'tag';
00232             } elseif ( $sActCat && $oProduct->isAssignedToCategory( $sActCat ) ) {
00233                 // category ?
00234             } else {
00235                 list( $sListType, $sActCat ) = $this->_getDefaultParams( $oProduct );
00236             }
00237         }
00238 
00239         $oParentView = $this->getParent();
00240         //set list type and category id
00241         $oParentView->setListType( $sListType );
00242         $oParentView->setCategoryId( $sActCat );
00243 
00244         return $sActCat;
00245     }
00246 
00254     protected function _getDefaultParams( $oProduct )
00255     {
00256         $sListType = null;
00257         $aArticleCats = $oProduct->getCategoryIds( true );
00258         if ( is_array( $aArticleCats ) && count( $aArticleCats ) ) {
00259             $sActCat = reset( $aArticleCats );
00260         } elseif ( ( $sActCat = $oProduct->getManufacturerId() ) ) {
00261             // not assigned to any category ? maybe it is assigned to Manufacturer ?
00262             $sListType = 'manufacturer';
00263         } elseif ( ( $sActCat = $oProduct->getVendorId() ) ) {
00264             // not assigned to any category ? maybe it is assigned to vendor ?
00265             $sListType = 'vendor';
00266         } else {
00267             $sActCat = null;
00268         }
00269 
00270         return array( $sListType, $sActCat );
00271     }
00272 
00280     public function setCategoryTree( $oCategoryTree )
00281     {
00282         $this->_oCategoryTree = $oCategoryTree;
00283     }
00284 
00292     public function setManufacturerTree( $oManufacturerTree )
00293     {
00294         $this->_oManufacturerTree = $oManufacturerTree;
00295     }
00296 }