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
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
00045 $this->_loadVendorTree( $sActCat );
00046 }
00047
00048 if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) ) {
00049
00050 $sActManufacturer = oxConfig::getParameter( 'mnid' );
00051 $this->_loadManufacturerTree( $sActManufacturer );
00052 }
00053
00054 if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) ) {
00055
00056
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
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
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
00116 if ( $sActCat === null && !$oProduct && !$sActCont && !$sActManufacturer && !$sActTag ) {
00117
00118 $sActCat = $this->getConfig()->getActiveShop()->oxshops__oxdefcat->value;
00119 if ( $sActCat == 'oxrootid' ) {
00120
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
00144 $oParentView->setCategoryTree( $oCategoryTree );
00145
00146
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
00168 $oParentView->setVendorTree( $oVendorTree );
00169
00170
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
00194 $oParentView->setManufacturerTree( $oManufacturerTree );
00195
00196
00197 if ( ( $oManufacturer = $oManufacturerTree->getClickManufacturer() ) ) {
00198 $oParentView->setActManufacturer( $oManufacturer );
00199 }
00200 }
00201 }
00202
00209 public function render()
00210 {
00211 parent::render();
00212
00213
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 $oParentView->addTplParam( 'rootvendor', $oParentView->getRootVendor() );
00224 $oParentView->addTplParam( 'aVendorlist', $oParentView->getVendorlist() );
00225 $oParentView->addTplParam( 'sVendorID', $oParentView->getVendorId() );
00226 }
00227
00228 if ( $myConfig->getConfigParam( 'bl_perfLoadManufacturerTree' ) &&
00229 ( $oManufacturerTree = $oParentView->getManufacturerTree() ) ) {
00230 $oParentView->setManufacturerlist( $oManufacturerTree );
00231 $oParentView->setRootManufacturer( $oManufacturerTree->getRootCat() );
00232
00233
00234 $oParentView->addTplParam( 'rootmanufacturer', $oParentView->getRootManufacturer() );
00235 $oParentView->addTplParam( 'aManufacturerlist', $oParentView->getManufacturerlist() );
00236 $oParentView->addTplParam( 'sManufacturerID', $oParentView->getManufacturerId() );
00237 }
00238
00239 if ( $myConfig->getConfigParam( 'bl_perfLoadCatTree' ) &&
00240 ( $oCategoryTree = $oParentView->getCategoryTree() ) ) {
00241
00242
00243 if ( $myConfig->getConfigParam( 'bl_perfLoadTreeForSearch' ) ) {
00244 $oParentView->setSearchCatTree( $oCategoryTree );
00245
00246 $oParentView->addTplParam( 'aSearchCatTree', $oParentView->getSearchCatTree() );
00247 }
00248
00249
00250 if ( $myConfig->getConfigParam( 'blTopNaviLayout' ) ) {
00251 $oParentView->setCatMore( $this->_oMoreCat );
00252
00253 $oParentView->addTplParam( 'navcategorytree', $oCategoryTree );
00254 $oParentView->addTplParam( 'navcategorycount', $oCategoryTree->count() );
00255 $oParentView->addTplParam( 'navcatmore', $oParentView->getCatMore() );
00256 }
00257
00258 return $oCategoryTree;
00259 }
00260 }
00261
00270 protected function _getMoreCategory( $sActCat, $sActCont )
00271 {
00272 $myConfig = $this->getConfig();
00273 $blExpanded = false;
00274
00275 if ( $sActCat == 'oxmore' ) {
00276 $blExpanded = true;
00277 } else {
00278 $iTopCount = $myConfig->getConfigParam( 'iTopNaviCatCount' );
00279 $oCategoryTree = $this->getParent()->getCategoryTree();
00280 if ( $oCategoryTree ) {
00281 $iCnt = 0;
00282 foreach ( $oCategoryTree as $oCat ) {
00283 $iCnt++;
00284
00285 if ( ( $aContent = $oCat->getContentCats() ) ) {
00286 foreach ( $aContent as $oContent ) {
00287 if ( $sActCont == $oContent->getId() && ($iCnt > $iTopCount )) {
00288 $blExpanded = true;
00289 break 2;
00290 }
00291 $iCnt++;
00292 }
00293 }
00294
00295 if ( $oCat->getExpanded() && ($iCnt > $iTopCount )) {
00296 $blExpanded = true;
00297 break;
00298 }
00299 }
00300 }
00301 }
00302
00303 $oMoreCat = new oxStdClass();
00304 $oMoreCat->closelink = $oMoreCat->openlink = $myConfig->getShopHomeURL().'cnid=oxmore';
00305 $oMoreCat->expanded = $blExpanded;
00306 return $oMoreCat;
00307 }
00308
00321 protected function _addAdditionalParams( $oProduct, $sActCat, $sActManufacturer, $sActCont, $sActTag, $sActVendor )
00322 {
00323 $sSearchPar = oxConfig::getParameter( 'searchparam' );
00324 $sSearchCat = oxConfig::getParameter( 'searchcnid' );
00325 $sSearchVnd = oxConfig::getParameter( 'searchvendor' );
00326 $sSearchMan = oxConfig::getParameter( 'searchmanufacturer' );
00327 $sListType = oxConfig::getParameter( 'listtype' );
00328
00329
00330 if ( ( !$sListType || $sListType == 'search' ) && ( $sSearchPar || $sSearchCat || $sSearchVnd || $sSearchMan ) ) {
00331
00332 $sListType = 'search';
00333 } else {
00334
00335
00336 if ( $sActManufacturer && ( $sActManufacturer == $oProduct->getManufacturerId() ) ) {
00337
00338 $sListType = 'manufacturer';
00339 $sActCat = $sActManufacturer;
00340 } elseif ( $sActVendor && ( substr( $sActVendor, 2 ) == $oProduct->getVendorId() ) ) {
00341
00342 $sListType = 'vendor';
00343 $sActCat = $sActVendor;
00344 } elseif ( $sActTag ) {
00345
00346 $sListType = 'tag';
00347 } elseif ( $sActCat && $oProduct->isAssignedToCategory( $sActCat ) ) {
00348
00349 } else {
00350 list( $sListType, $sActCat ) = $this->_getDefaultParams( $oProduct );
00351 }
00352 }
00353
00354 $oParentView = $this->getParent();
00355
00356 $oParentView->setListType( $sListType );
00357 $oParentView->setCategoryId( $sActCat );
00358
00359 return $sActCat;
00360 }
00361
00369 protected function _getDefaultParams( $oProduct )
00370 {
00371 $sListType = null;
00372 $aArticleCats = $oProduct->getCategoryIds( true );
00373 if ( is_array( $aArticleCats ) && count( $aArticleCats ) ) {
00374 $sActCat = reset( $aArticleCats );
00375 } elseif ( ( $sActCat = $oProduct->getManufacturerId() ) ) {
00376
00377 $sListType = 'manufacturer';
00378 } elseif ( ( $sActCat = $oProduct->getVendorId() ) ) {
00379
00380 $sListType = 'vendor';
00381 } else {
00382 $sActCat = null;
00383 }
00384
00385 return array( $sListType, $sActCat );
00386 }
00387 }