Last active
August 29, 2015 14:04
-
-
Save proudcommerce/4106ae70ab02824ce756 to your computer and use it in GitHub Desktop.
gets first subcategory of a main category and redirect to this.uses an array, which main categories should be checked.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This program is free software: you can redistribute it and/or modify | |
* it under the terms of the GNU General Public License as published by | |
* the Free Software Foundation, either version 3 of the License, or | |
* (at your option) any later version. | |
* | |
* @copyright (c) Proud Sourcing GmbH | 2014 | |
* @link https://gist.github.com/proudcommerce | |
* @link http://www.proudcommerce.com | |
* @version 1.0.0 | |
**/ | |
class glModules_alist extends glModules_alist_parent | |
{ | |
/** | |
* main category oxids for redirect check | |
* @var array | |
*/ | |
protected $_aRedirectMainCats = array('b24952903a91bc85a5378b2dfc72cf44', 'fa713d83c4cd5c14144e9fd05a91bc63', '1eacce546a769f8a9f1d21b5f0c5a848', '8f9682f1c9445fc17a447fa09e6cddc2', '1b5fcfb2cc0aa27c666cafdf8991aaae' ); | |
/** | |
* Executes parent::render(), loads active category, prepares article | |
* list sorting rules. According to category type loads list of | |
* articles - regular (oxarticlelist::LoadCategoryArticles()) or price | |
* dependent (oxarticlelist::LoadPriceArticles()). Generates page navigation data | |
* such as previous/next window URL, number of available pages, generates | |
* meta tags info (oxubase::_convertForMetaTags()) and returns name of | |
* template to render. Also checks if actual pages count does not exceed real | |
* articles page count. If yes - calls error_404_handler(). | |
* | |
* @return string $this->_sThisTemplate current template file name | |
*/ | |
public function render() | |
{ | |
if (($oCategory = $this->getActiveCategory())) | |
{ | |
if(in_array($oCategory->oxcategories__oxid->value, $this->_aRedirectMainCats)) | |
{ | |
if($aSubCats = $oCategory->getSubCats()) | |
{ | |
if ( is_array( $aSubCats ) ) | |
{ | |
foreach ( $aSubCats as $oSubCat ) | |
{ | |
oxRegistry::getUtils()->redirect( $oSubCat->getLink(), false, 302 ); | |
} | |
} | |
} | |
} | |
} | |
return parent::render(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to use redirect only, if no articles in category, change line 37 to:
if($this->getArticleList() == null && in_array($oCategory->oxcategories__oxid->value, $this->_aRedirectMainCats))