0

We have created megamenu for our site. But the issue we are facing is that the url is appending if click more than once instead of showing corresponding page.

How to resolve this issue?

Below is the code:

<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * Top menu for store
 *
 * @var $block \Magento\Theme\Block\Html\Topmenu
 */
?>


    <link rel="stylesheet" type="text/css" href="<?php echo $block->getViewFileUrl('css/cart.css')?>">

  <?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

?>
<?php
/**
 * Top menu for store
 *
 * @var $block \Magento\Theme\Block\Html\Topmenu
 */
?>



<header class="headers">
  <div class="header-inrs">
    <div class="menu-container">
      <div class="menus contenedor-menu">
        <ul class="clearfix backcolor designmenu">
          <div class="totalmobilelog">
            <div class="lo">
              <a href="http://127.0.0.1/newmagento/customer/account/login/" ><b class="clsml">Login</b></a>
            </div>
            <div class="si">
              <a href="" ><b class="clsml">Sign Up</b></a>
            </div>
          </div>
          <?php
          $categories = $block->getStoreCategories();

          foreach ($categories as $category):

          ?>


          <li><a href="<?php echo $category->getRequestPath();?>"><?php echo $category->getName(); ?>

            <?php
            $subCategories = $block->getCategoryById($category->getId());
            $subCats = $subCategories->getChildrenCategories();
            if(count($subCats) > 0): ?>
              <i class="fa fa-angle-down arrowmm" aria-hidden="true"></i>
            <?php endif; ?>
          </a>
            <ul class="subc">
            <?php
            foreach ($subCats as $subCategory):
            ?>

            <li><a href="<?php echo $subCategory->getRequestPath();?>"><?php echo $subCategory->getName(); ?></a>

          </li>

          <?php endforeach; ?>

        </ul>
        <?php echo $block->getSubcategories($subCategories); ?>
        <?php endforeach; ?>
      </li>
  </ul>
</div>
</div>
</div>
</header>
  • Can you please concat your category request path with base url and then check ? like <a href="<?php echo $block->getBaseUrl().$category->getRequestPath();?>"><?php echo $category->getName(); ?> – Kishan Savaliya Oct 15 at 9:31
  • @KishanSavaliya, I have tried the code as you suggested but its not working. Any help will be appreciated. – Siva Oct 15 at 9:43
  • You did that for both categories ? Child and Main category ? – Kishan Savaliya Oct 15 at 9:50
  • @KishanSavaliya, yes, I have done that for both main and sub categories – Siva Oct 15 at 10:38
  • I've added answer, you can check there this may help you. – Kishan Savaliya Oct 15 at 10:47
0

You can try changing the getRequestPath() with getUrl() to get the category Url Path.

  • I have tried with getUrl() and got the category page but the problem is appending the url. Any help will be appreciated – Siva Oct 15 at 10:42
0

Please use $category->getUrl() and $subCategory->getUrl().

This may be help you to get exact Category URL there.

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.