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>

没有正确的解决方案

其他提示

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

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

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

许可以下: CC-BY-SA归因
scroll top