Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bootstrap navigation active item BUG #128

Open
janannedh opened this issue Jun 29, 2015 · 10 comments
Open

Bootstrap navigation active item BUG #128

janannedh opened this issue Jun 29, 2015 · 10 comments

Comments

@janannedh
Copy link

Hello,

The menu active buttons are buggy when you add a "Home" button within the navigation in the topmenu.phtml like this:

<?php $_menu = $this->getHtml('level-top') ?>
<?php if ($_menu): ?>
<ul class="nav navbar-nav">
    <li><a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>">Home</a></li>
    <?php echo $_menu ?>
</ul>
<?php endif ?>

See: http://seamless.dehaanwerkbank.nl/ for a live example. The menu item "Category 1" is active while being on the homepage.

How can i fix this?

@bencorlett
Copy link
Contributor

And to confirm, this DOESN’T happen if you remove the “home” link?

On 29 Jun 2015, at 6:48 pm, jananne [email protected] wrote:

Hello,

The menu active buttons are buggy when you add a "Home" button within the navigation in the topmenu.php like this:

getHtml('level-top') ?>

Home x-msg://2/%3C?php%20echo%20%24this-%3EgetUrl('')%20?%3E

See: http://seamless.dehaanwerkbank.nl/ http://seamless.dehaanwerkbank.nl/ for a live example. The menu item "Category 1" is active while being on the homepage.

How can fix this?


Reply to this email directly or view it on GitHub #128.

@janannedh
Copy link
Author

Yes, i confirm.

@bencorlett
Copy link
Contributor

You’ll need to trace down through the Topmenu.php class to see where the “active” attribute is being set.

I have that setup on many client sites and don’t experience that issue at all.

Let me know how you go!

On 29 Jun 2015, at 6:54 pm, jananne [email protected] wrote:

Yes, i confirm.


Reply to this email directly or view it on GitHub #128 (comment).

@janannedh
Copy link
Author

I've noticed that when i clear the cache, everything is OK. But i didn't modify you code, i only changed the layout of the navigation by CSS. And the Magento installation is default/clean. This makes the bug hard to recreate.

When the store is cached for a while, but bug will come back.

Is this info of any help?

@bencorlett
Copy link
Contributor

Leave your cache off while developing.

I would guess if it only happens when caching is turned on, it has something to do with Magento's "getCacheKey" in the navigation class. Gives something to work off though

Sent from my iPhone

Please excuse my brevity

On 29 Jun 2015, at 7:14 PM, jananne [email protected] wrote:

I've noticed that when i clear the cache, everything is OK. But i didn't modify you code, i only changed the layout of the navigation by CSS. And the Magento installation is default/clean. This makes the bug hard to recreate.

When the store is cached for a while, but bug will come back.

Is this info of any help?


Reply to this email directly or view it on GitHub.

@janannedh
Copy link
Author

Okay, thanks.

Hopefully i've been of any help with this report.

@Dcl2049
Copy link

Dcl2049 commented Jul 14, 2015

I've been bugged by this issue for a while and decided to do something about it today, I think I found a quick and dirty fix.

Like Ben said, it has to do with Magento's core modules setting cache keys for the top menu. I added one extra cache key to specify the CMS page (that way each CMS page gets a cached copy of the menu with active attributes either set or not set). There may be a more efficient way of doing this than I did, but this is working for me.

Make copy of /app/code/core/Mage/Page/Block/Html/Topmenu.php to app/code/local directory to edit. Make the change marked at line 239:

public function getCacheKeyInfo()
{
    $shortCacheId = array(
        'TOPMENU',
        Mage::app()->getStore()->getId(),
        Mage::getDesign()->getPackageName(),
        Mage::getDesign()->getTheme('template'),
        Mage::getSingleton('customer/session')->getCustomerGroupId(),
        Mage::getSingleton('cms/page')->getIdentifier(), /* Edit - add cms page ID to prevent active link on homepage/other */
        'template' => $this->getTemplate(),
        'name' => $this->getNameInLayout(),
        $this->getCurrentEntityKey()
    );
    $cacheId = $shortCacheId;

    $shortCacheId = array_values($shortCacheId);
    $shortCacheId = implode('|', $shortCacheId);
    $shortCacheId = md5($shortCacheId);

    $cacheId['entity_key'] = $this->getCurrentEntityKey();
    $cacheId['short_cache_id'] = $shortCacheId;

    return $cacheId;
}

@janannedh
Copy link
Author

Thank you, this works perfectly for me.

@janannedh
Copy link
Author

Somehow it's still not working. The bug is always active.

Look for example to this webstore: http://www.krijtverfkopen.nl/

  1. Go to category: Krijtverf
  2. Go to product: Milk
  3. Go to category: Muurfverf Kalkmat
  4. Go to product: Olive

You will see that the category item within the menu is staying at category Krijtverf. Ofcourse, when i clear the cache, the correct category item will be shown.

Any solutions?

@bencorlett
Copy link
Contributor

Hi there,

I really don’t have any solutions without access to your server’s backend.

This would be something I could do on a contractual basis. If you’d like this help, please email hello [at] webcomm.io http://webcomm.io/ and we can talk there :)

On 28 Sep 2015, at 8:19 PM, jananne [email protected] wrote:

Somehow it's still not working. The bug is always active.

Look for example to this webstore: http://www.krijtverfkopen.nl/ http://www.krijtverfkopen.nl/

  1. Go to category: Krijtverf
  2. Go to product: Milk
  3. Go to category: Muurfverf Kalkmat
  4. Go to product: Olive

You will see that the category item within the menu is staying at category Krijtverf. Ofcourse, when i clear the cache, the correct category item will be shown.

Any solutions?


Reply to this email directly or view it on GitHub #128 (comment).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants