Page 1 of 1

Products OR Sub-Categories in Drop Down Menus

Posted: Fri Jul 26, 2013 9:17 am
by billynoah
This code will check to see if there are no sub-categories and, if so, display products instead in the top level drop down menus. If sub-categories exist then it will use default behavior and display them in the drop down menus.

Code: Select all

<modification>
	<id>Products in Drop Down Menus</id>
	<version>1.0</version>
	<vqmver>2.1</vqmver>
	<author>billynoah@gmail.com</author>
	<file name="catalog/controller/common/header.php">
		<operation>
			<search position="before"><![CDATA[
$children = $this->model_catalog_category->getCategories($category['category_id']);
			]]></search>
			<add><![CDATA[
if ($this->model_catalog_category->getCategories($category['category_id'])) {
			]]></add>
		</operation>
		
		<operation>
			<search position="before"><![CDATA[
// Level 1
			]]></search>
			<add><![CDATA[
				} else {
                $dataProduct = array(
						'filter_category_id'  => $category['category_id'],
						'filter_sub_category' => true
					);
	            $children = $this->model_catalog_product->getProducts($dataProduct);
				foreach ($children as $child ) {
					$children_data [] = array(
							'name'  =>  $child['name'],
							'href'  => $this->url->link('product/product', 'product_id=' . $child['product_id']),
						);

                }
				}
			]]></add>
		</operation>
	</file>
</modification>

Re: Products OR Sub-Categories in Drop Down Menus

Posted: Sun Jan 12, 2014 12:11 am
by kamelio
Excellent VQMOD RE: Display product links in main menu

Quick note: I had to close the node, seems to be a

Code: Select all

</modification>
missing from the last line.

Thanks for this mod, saved me some time ;)

Re: Products OR Sub-Categories in Drop Down Menus

Posted: Mon Jan 13, 2014 12:49 am
by billynoah
thanks, that was a copy/paste fail :-) I updated the original post to include the closing tag.

Re: Products OR Sub-Categories in Drop Down Menus

Posted: Fri Jan 17, 2014 6:45 am
by ryanpete
I love this mod thanks! I've been trying to tweak it so it will also show products under sub categories as well but I haven't had any luck.. Thoughts?

Re: Products OR Sub-Categories in Drop Down Menus

Posted: Sun Jul 13, 2014 3:23 pm
by raj79
please give me live demo link ..

Re: Products OR Sub-Categories in Drop Down Menus

Posted: Mon Oct 12, 2015 10:39 pm
by FedeBike
Hi all,

in which file should I copy this modification?

Thank you for your help!
Federica

Re: Products OR Sub-Categories in Drop Down Menus

Posted: Thu Nov 23, 2017 3:18 am
by pk_rulz
The Mod did not work and Got this in my log. Any pointers what went wrong
SEARCH NOT FOUND (ABORTING MOD): $children = $this->model_catalog_category->getCategories($category['category_id']);

Re: Products OR Sub-Categories in Drop Down Menus

Posted: Thu Nov 23, 2017 3:31 am
by pk_rulz
Got it. from opencart 3 the menu is contained in a separate menu.php and no more in the header.php. Just changed header to menu in the xml and it works like a charm