×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Vincenzo Assenza
Added: Jul 8, 2015 1:45 PM
Modified: Jul 8, 2015 1:50 PM
Views: 8
Tags: no tags
  1. <?php
  2. $_helper = $this->helper('catalog/output');
  3. $_category = $this->getCurrentCategory();
  4. $loadingImage = $this->getSkinUrl('images/transparent.png');
  5. $_parentCategoryId = $_category->getParentCategory()->getId();
  6.  
  7. $_allSubCategories = Mage::getModel('catalog/category')->getCollection()
  8.         ->addAttributeToSelect('*')
  9.         ->addAttributeToFilter('page_layout', $_category->getPageLayout())
  10.         ->addAttributeToFilter('parent_id', array('eq' => $_parentCategoryId));
  11.  
  12.  
  13. $prevCat = $nextCat = $nextIsNow = $firstCat = $lastCat = null;
  14.  
  15. foreach ($_allSubCategories as $single) {
  16.  
  17.     // set absolute first category to get the next even on the end of the cycle (circular cycle)
  18.     if (!$firstCat) {
  19.         $firstCat = $single;
  20.     }
  21.  
  22.     if ($nextIsNow) {
  23.         if (!$nextCat) {
  24.             // set next category
  25.             $nextCat = $single;
  26.         }
  27.         // set absolute last category to get the prev even on the start of the cycle (circular cycle)
  28.         $lastCat = $single;
  29.  
  30.         continue;
  31.     } else {
  32.         if ($single->getId() == $_category->getId()) {
  33.             // prepare the setting of the next category (next cycle)
  34.             $nextIsNow = true;
  35.         } else {
  36.             // set previous category
  37.             $prevCat = $single;
  38.         }
  39.     }
  40. }
  41.  
  42. if (!$prevCat) {
  43.     $prevCat = $lastCat;
  44. }
  45.  
  46. if (!$nextCat) {
  47.     $nextCat = $firstCat;
  48. }
  49. ?>