Jump to content

blocktopmenu - direct links only - drop down


tarmouti
 Share

Recommended Posts

Hi!

 

I'd like to ask you about creating my own drop down menu with links - without hard-coding it into module files.

 

My store has got only 4-5 products and there's no point in creating subcategory for each of them.

The problem is that I can't create menu like:

Products (drop down menu):

Product 1 - Direct link to the product (not (sub)category)

...

Product X - Direct link to the product (not (sub)category)

 

I know that I can hook the links separately without drop-down menu, but it's waste of space.

 

Thank you in advance.

 

 

 

 

Share this post


Link to post
Share on other sites

Well, somewhat quick and dirty, you could do this:

 

 

Edit file modules/blocktopmenu/blocktopmenu.php   (Make backup!!)

 

 

Go to function:

   private function makeMenu()
 
Add the red code:   (Sample code from PS 1.6.0.14)
 
private function makeMenu()
{
  $menu_items = $this->getMenuItems();
  $id_lang = (int)$this->context->language->id;
  $id_shop = (int)Shop::getContextShopID();
 
  $post_prd_string = '</ul></a></li>'; // string to close product submenu after last product.
  $last_item_was_prd = false;   // Check if need to create submenu or main menu
 
  foreach ($menu_items as $item)
  {
    if (!$item)
      continue;
 
    preg_match($this->pattern, $item, $value);
    $id = (int)substr($item, strlen($value[1]), strlen($item));
 
 
    if ($last_item_was_prd && substr($item, 0, strlen($value[1])) !='PRD') {  // last product?
      $this->_menu .= $post_prd_string;    // close submenu
      $last_item_was_prd = false;
    }
 
    switch (substr($item, 0, strlen($value[1])))
    {
      case 'CAT':
          $this->_menu .= $this->generateCategoriesMenu(Category::getNestedCategories($id, $id_lang, true, $this->user_groups));
          break;
 
      case 'PRD':
          if (!$last_item_was_prd)          // first product? Add main menu item
            $this->_menu .= '<li><a href ="#" class="">'.$this->l('Products').
                '<ul class="prd_submenu">'.PHP_EOL;
          $last_item_was_prd = true;
 
          $selected = ($this->page_name == 'product' && (Tools::getValue('id_product') == $id)) ? ' class="sfHover"' : '';
          $product = new Product((int)$id, true, (int)$id_lang);
          if (!is_null($product->id))
            $this->_menu .= '<li'.$selected.'><a href="'.Tools::HtmlEntitiesUTF8($product->getLink()).'" title="'.$product->name.'">'.$product->name.'</a></li>'.PHP_EOL;
          break;
 
      case 'CMS':
 
 
 
 
 
Result:
If you add some products to the top hor. menu, like this:
post-455771-0-71995700-1431284817_thumb.png
 
The top menu will look like this:
products are grouped in submenu products:
post-455771-0-82706400-1431284859_thumb.png
and the second group as well, in a new submenu:
post-455771-0-69134200-1431284929_thumb.png
 
 
Hope this helps. If you need some small changes, let me know.
 
pascal.
  • Like 1

Share this post


Link to post
Share on other sites

Dear Pascal!

 

Thank you a lot for your reply. I really appreciate your help. It redirects directly to the product page.

 

Is there a chance that future releases of this module will contain this option as built-in?

Share this post


Link to post
Share on other sites

The module is a standard Prestashop module. I'm a moderator at the forum (think 'volunteer'), not directly connected to the Prestashop team. You can request features on their site :-)

 

Cheers,

Pascal

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More