0

I have a category menu which works fine when viewing a category with its true URL path

eg. /catalog/category/view/id/360/?dir=desc&order=position

Category Screenshot 1

However when i input the new URL redirects i require it removes the sub categories.

eg. shop-by-product-type/shop-lashes/

Screenshot 2

These are set as anchors and i have checked the catalog backend to check these are set correctly.

Edit :

This is the PHP Menu which i am generating which works fine on the catalog/category URL but not the other. It is as if it is not retrieving the

<?php $subcategories = $cat->getChildrenCategories(); ?>

Edit : Full page code for navigation:

<?php $_menu = ''?>

<?php $_rootcatID   = Mage::app()->getStore()->getRootCategoryId(); ?>
<?php $_category    = $this->getCurrentCategory();
$_curcatID    = $_category->entity_id;
$_parcatID    = $_category->getParentId();
$_collection  = Mage::getModel('catalog/category')->getCategories($_rootcatID, 0, false, false, false );
$_helper      = Mage::helper('catalog/category'); ?>
<?php /* */ ?>


<?php $isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn(); ?>
<?php if (!$isLoggedIn) {?>
    <?php $_helper = Mage::helper('catalog/category') ?>
    <?php $categoryId = 354;?>
    <?php $_categoryNumber = Mage::getModel('catalog/category')->load($categoryId) ?>
    <?php $_cat2 = 355; ?>
    <?php $_categoryNumber2 = Mage::getModel('catalog/category')->load($_cat2) ?>

<ul class="sideMenu">
    <li>
        <a href="<?php echo $_helper->getCategoryUrl($_categoryNumber); ?>" class="cat-name"><?php echo $_categoryNumber->getName(); ?></a>
    </li>
    <li>
        <a href="<?php echo $_helper->getCategoryUrl($_categoryNumber2); ?>" class="cat-name"><?php echo $_categoryNumber2->getName(); ?></a>
    </li>
    <li>
        <a class="cat-name" href="<?php echo Mage::getUrl('customer/account/login'); ?>" class="cat-name">Shop Professional Range</a>
    </li>
</ul>
<?php } else { ?>
<?php $customerGroupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); ?>
<?php if ($customerGroupId == 3) {?>
    <?php if ($_collection): ?>
        <div class="nav-container">
            <?php foreach ($_collection as $_maincat):?>
                <?php $_categories = $_maincat->getChildrenCategories(); ?>
                <?php if($_maincat->getIsActive() && sizeof($_categories) > 0):?>
                    <?php $cur_maincat = Mage::getModel('catalog/category')->load($_maincat->getId());?>
                    <nav class="sidebar-menu-1" style="display:block">
                        <h3><?php echo $cur_maincat->getName(); ?></h3>
                        <ol class="sideMenu">
                            <?php $_categories = $_maincat->getChildrenCategories(); ?>
                            <?php if (count($_categories) > 0 ) : ?>
                                <?php foreach ($_categories as $cat):?>
                                    <?php if($_category->getIsActive()):?>
                                        <?php $cur_category = Mage::getModel('catalog/category')->load($cat->getId());?>
                                        <li class="<?php if( $_curcatID == $cat->getId() ) : ?> current <?php endif; ?>"><a href="<?php echo $_helper->getCategoryUrl($cur_category); ?>"><span class="cat-chk-box"></span><span class="cat-name"><?php echo $cur_category->getName(); ?></span></a> </li>

                                        <?php if( $_curcatID == $cat->getId() || $_parcatID == $cat->getId()) : ?>
                                            <?php $subcategories = $cat->getChildrenCategories(); ?>
                                            <?php if (count($subcategories) > 0 ) : ?>
                                                <ul class="sideMenu">
                                                    <?php foreach($subcategories as $subcat) : ?>
                                                        <?php if($subcat->getIsActive()): ?>
                                                            <?php $cur_subcat = Mage::getModel('catalog/category')->load($subcat->getId());?>
                                                            <li class="<?php if( $_curcatID == $subcat->getId() ) : ?> current <?php endif; ?> subCats"><a href="<?php echo $_helper->getCategoryUrl($cur_subcat); ?>" ><?php echo $cur_subcat->getName(); ?></a> </li>
                                                        <?php endif; ?>
                                                    <?php endforeach; ?>
                                                </ul>
                                            <?php endif; ?>
                                        <?php endif; ?>
                                    <?php endif; ?>
                                <?php endforeach; ?>
                            <?php endif; ?>
                        </ol>
                    </nav>
                <?php endif; ?>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>
<?php } else { ?>
    <?php $_helper = Mage::helper('catalog/category') ?>
    <?php $categoryId = 354;?>
    <?php $_categoryNumber = Mage::getModel('catalog/category')->load($categoryId) ?>
    <?php $_cat2 = 355; ?>
    <?php $_categoryNumber2 = Mage::getModel('catalog/category')->load($_cat2) ?>

    <ul class="sideMenu">
        <li>
            <a href="<?php echo $_helper->getCategoryUrl($_categoryNumber); ?>" class="cat-name"><?php echo $_categoryNumber->getName(); ?></a>
        </li>
        <li>
            <a href="<?php echo $_helper->getCategoryUrl($_categoryNumber2); ?>" class="cat-name"><?php echo $_categoryNumber2->getName(); ?></a>
        </li>
    </ul>
<?php } ?>
  • do you mean you want to remove the sub category url key from the url ? – Sunil Verma Feb 14 '18 at 10:13
  • Hi Sunil, no. If you see the first screenshot there are sub categories below the category 'Shop Professional Range'. However on the 2nd screenshot they have disappeared and this is when i have accessed the category via a custom URL in the category. – Kirsty Marks Feb 14 '18 at 10:16
  • can you also add the earlier part ofcode for ex : $_collection so i can check the code... – Sunil Verma Feb 14 '18 at 10:23
  • Hi Sunil, full code added. Any pointers is appreciated, as im at a loss as to why it would show on the true category URL and not on the rewrote URL. – Kirsty Marks Feb 14 '18 at 10:27
  • Basically I have a custom menu pulling only two cats if the user is logged in. Otherwise its a full menu. The full menu shows fine on the category view without a rewritten URL, however it disappears when i use the rewrite. Ive flushed the caches and indexes also. – Kirsty Marks Feb 14 '18 at 10:28
0

After looking at this, it appears that the menu was checking that the currently selected option had sub categories before displaying them.

I have since rewritten the below which now works correctly :

<?php if ($_collection): ?>
        <div class="nav-container">
            <?php foreach ($_collection as $_maincat):?>
                <?php $_categories = $_maincat->getChildrenCategories(); ?>
                <?php if($_maincat->getIsActive() && sizeof($_categories) > 0):?>
                    <?php $cur_maincat = Mage::getModel('catalog/category')->load($_maincat->getId());?>
                    <nav class="sidebar-menu-1" style="display:block">
                        <h3><?php echo $cur_maincat->getName(); ?></h3>
                        <ol class="sideMenu">
                            <?php $_categories = $_maincat->getChildrenCategories(); ?>
                            <?php if (count($_categories) > 0 ) : ?>
                                <?php foreach ($_categories as $cat):?>
                                    <?php if($_category->getIsActive()):?>
                                        <?php $cur_category = Mage::getModel('catalog/category')->load($cat->getId());?>
                                        <li class="<?php if( $_curcatID == $cat->getId() ) : ?> current <?php endif; ?>"><a href="<?php echo $_helper->getCategoryUrl($cur_category); ?>"><span class="cat-name"><?php echo $cur_category->getName(); ?></span></a> </li>
                                        <?php $subcategories = $cur_category->getChildrenCategories(); ?>
                                        <?php if (count($subcategories) > 0 ) : ?>
                                            <ul class="sideMenu">
                                                <?php foreach($subcategories as $subcat) : ?>
                                                    <?php if($subcat->getIsActive()): ?>
                                                        <?php $cur_subcat = Mage::getModel('catalog/category')->load($subcat->getId());?>
                                                        <li class="<?php if( $_curcatID == $subcat->getId() ) : ?> current <?php endif; ?> subCats"><a href="<?php echo $_helper->getCategoryUrl($cur_subcat); ?>" ><?php echo $cur_subcat->getName(); ?></a> </li>
                                                    <?php endif ?>
                                                <?php endforeach ?>
                                            </ul>
                                        <?php endif ?>
                                    <?php endif ?>
                                <?php endforeach ?>
                            <?php endif ?>
                        </ol>
                    </nav>
                <?php endif ?>
            <?php endforeach ?>
        </div>
    <?php endif ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.