Rulian Posted March 17, 2016 Share Posted March 17, 2016 Lets say my category tree is like this: ├Men | ├ Shirts | └ Pants └Women ├ Dresses └ Tops In AdminProductController's default view (listing products), I'd like to customize the category tree helper (above the list, at the top of the page) in order to achieve such a behaviour: Only shows "1st level" categories (ie. in our case: 'Men' and 'Women') When a category is selected, the controller would list each and every product from the category and also all sub-categories. Example: I check "Men" and the AdminProductController lists all shirts and pants Does anyone ever worked on such a thing ?Any help would be greatly appreciated! Link to comment Share on other sites More sharing options...
Rulian Posted March 18, 2016 Author Share Posted March 18, 2016 (edited) Ok, I went the SQL way... In order to display product from subcategories, in AdminProductController.php (approx. line190) I modified the _join line: if ($join_category) { $this->_join .= ' INNER JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = a.`id_product` AND cp.`id_category` = '.(int)$this->_category->id.') '; $this->_select .= ' , cp.`position`, '; } ...and added another join in order to retrieve sub categories: if ($join_category) { //$this->_join .= ' INNER JOIN `'._DB_PREFIX_.'category_product` cp ON (cp.`id_product` = a.`id_product` AND cp.`id_category` = '.(int)$this->_category->id.') '; $this->_join .= ' INNER JOIN `'._DB_PREFIX_.'category_product` cp ON ( cp.`id_product` = a.`id_product` )'; $this->_join .= ' JOIN `'._DB_PREFIX_.'category` c2 ON ( cp.`id_category` = c2.`id_category` AND c2.id_parent = '.(int)$this->_category->id.') '; $this->_select .= ' , cp.`position`, '; } Edited March 18, 2016 by Rulian (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now