Author Topic: Customize your menu  (Read 9050 times)

Offline David Veganhauser

  • Newbie
  • *
  • Posts: 32
  • Karma: +4/-0
    • View Profile
Customize your menu
« on: May 11, 2020, 09:00:23 AM »
As difficult as it has been, I finally found a way to customize the menu. Programming is not hard, its understanding the framework that is the problem.

Instead of showing a category product, I wanted to create a single product that is custom. When clicking on the menu, I did not want a list of products to show up for this one item, just simple that customized product.

WARNING: It is a hack. you should backup everything. If you do not know anything about HTML, etc. just do not do it. Once you write overtop the default files, there is no going back without a backup. :)

Note: I am doing this using the Parker Theme, so you wuold need to find the appropriate code for your theme, or the default. I have checked and the code is exactly the same, and located in the blocks folder

Note: this hack works for me because I have no subcategories to my custom menu item. That is to say, if you want a toplevel menu option without subcategories, this works. If you want the subcategories, you just need to add the code that is shown in the nested loop above to match that menu item you added. (no example provided since I did not need it, lo siento!) This would not be hard to do for your customized item.

and for the record, I do this under protest (I say that jokingly) but really there should be some flexibility with menu options, not just carts.

I do not take responsibility for this not working for you. I am just a guy trying to get my small website working so I can start my online business.

You HAVE been warned
Custom Menu Hack Implementation

Step 1: turn off cache/and clear cache in order for your changes to be updated
   1.1   Dashboard > System > Settings > System
      Cache Enabled: Off
   1.2   Clear Cache
      Dashboard > System > Cache
      Select files to clear cache and click Clear Selected Cache Button

Step 2: add a product and get the url for that product. This product will be the placeholder for your custom menu item.

Step 3: Edit the following file, located in the blocks folder


You will notice there are two nested loops, first showing the category, then, attaching any subcategories to that category). At the bottom of the file you will find the following lines of code:


just above the closing of the unordered list " </ul>" is where you would add your custom menu item

something like this:
   <li><a href="">New Menu Item 01</a></li>
   <li><a href="">New Menu Item 02</a></li>

Save your changes and ftp them to your site.

If you want to highlight your currently created custom menus, here is another hack to add some code at the top to challenge which "category" you are using. Since my two categories do not exist I am just using their product ID's. This means, of course, they could never be deleted or used for something different, unless updating the code is what you would like. Really, if I had the time I would store this as data in a field associated with the product to automate it more, but I just need this to work for now. I do not have the time to devote to a full solution.

Starting near the top you will see this:
          <?php if ($categories) { ?>

I added two string variables to hold the "current" style if it is passed, along with a boolean. If the product ID is one of these two, it will not be possible to be the other categories due to these products are not associated with those categories. I hope that makes sense.

I also want to point out, my implementation is not efficient code, but because I will not have sub categories and only a few in total, I saw no need to worry about this. I could have of course, but I am a bit lazy I admit :)

               $category124 =  '';
               $category125 =  '';
               $daveCustomCat = false;
               if ($_GET['product_id'] == "142") {
                  $category124 =  ' class="current" ';
                  $daveCustomCat = true;
               }elseif ($_GET['product_id'] == "143") {
                  $category125 =  ' class="current" ';
                  $daveCustomCat = true;
               foreach ($categories as $category) {
                   if ($category['current']) {
                     if ($daveCustomCat===false){
                        $category['current'] = ' class="current" ';
                  } ?>

then where you added the two new <li> items you just add their respective variable
   <li <?php echo $category142 ?>"><a href="index.php?rt=product/product&path=74&product_id=142">New Menu Item 01</a></li>
   <li <?php echo $category143 ?>"><a href="index.php?rt=product/product&path=74&product_id=143">New Menu Item 02</a></li>

« Last Edit: May 14, 2020, 05:02:14 AM by David Veganhauser »

Offline abantecart

  • Administrator
  • Hero Member
  • *****
  • Posts: 4360
  • Karma: +299/-10
    • View Profile
    • Ideal Open Source Ecommerce Solution
Re: Customize your menu
« Reply #1 on: May 19, 2020, 10:53:01 PM »
Thank you for sharing David!!
Please  rate your experience or leave your review
We need your help to build better free open source ecommerce platform for everyone. See how you can help

Offline eCommerce Core

  • Administrator
  • Hero Member
  • *****
  • Posts: 1602
  • Karma: +93/-1
    • View Profile
Re: Customize your menu
« Reply #2 on: May 31, 2020, 08:27:21 AM »
Good post David. Thanks
“If you’re in the luckiest one per cent of humanity, you owe it to the rest of humanity to think about the other 99 per cent.”
― Warren Buffett

Offline rodo22

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
    • Mejor epoca para viajar
Re: Customize your menu
« Reply #3 on: July 16, 2020, 10:30:10 PM »
Thanks for sharing this hack with us.


Powered by SMFPacks Social Login Mod