Jump to content

Product from category in place of thumbnail


falkor

Recommended Posts

Hello,

 

I want to show my customers featured product from each 2nd tier category (in place where parent category thumbnail), and show this product on mouse over ( hover on list item shows item from category). It is possible in any easy way without huge changes in classes/controllers or maybe any module to buy/download?

I'm not native English speaker, so if I wrote something wrong give me a feedback to edit :)

 

Thanks for help

 

 

EDIT:
I've made some modifications of blocktopmenu.php (its not enough optimalized so I'll post it tomorrow)
Atm thanks to Category::getProducts() I have random product from category.

 

Added in line 484 of blocktopmenu.php ( after
$html .= $this->generateCategoriesMenu($category['children']);)

 

        if ((int)$category['level_depth'] == 2){
          $products = array();
          $childrenCats = array();
          foreach($category['children'] as $nextlvlCat){          
            $childrenCats[] = new Category($nextlvlCat['id_category']); 
          }
          foreach($childrenCats as $randomProducts){
            $products[] = $randomProducts->getProducts(null,null,null,null,null,false,true,true,1,true,null);
          }
          if (count($products) > 0){
            $i = 0;
            foreach($products as $product){
              if(!empty($product) && isset($product)){
              $name = Product::getProductName($product[0]['id_product']);
              $image = Product::getCover($product[0]['id_product']);
              $imageLink = Link::getImageLink($product[0]['link'], $image['id_image'], 'large_default');
              if($i == 0){
                $class = ' first';
              }else{
                $class = '';
              }
              $html .= '
                <li data-category="category'.$product[0]['id_category_default'].'" class="featuredProduct'.$class.'">
                  <a href="'.$product[0]['link'].'">
                    <img src="'.$imageLink.'" alt="'.$name.'" />
                    <h3>'.$name.'</h3>
                  </a>
                </li>';
                $i++;
              }
            }
          }
        }

And jQuery for hover

 

  $('#block_top_menu ul li ul li').hover(function(){
    var category = $(this).data('category');
    $('#block_top_menu .featuredProduct').each(function(){     
      if($(this).data('category') == category){
        $(this).show();
      }else{
        $(this).hide();
      }
    });
  });

It's probably not last version so I'll be updating this post.



 

Edited by falkor (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...