Post by head_dunce » Wed Apr 10, 2019 3:56 am

Is there a way to give a category multiple parent categories?

Jim
Middle Caicos, Turks and Caicos Islands


Active Member

Posts

Joined
Thu Apr 04, 2019 11:50 pm

Post by xxvirusxx » Wed Apr 10, 2019 4:08 am

Yes. You can add that category in many parents categories.

My Extensions | OC 3.0.3.1, 3.0.2.0, 2.3.0.2 with bugs fixed | 2.3.0.2 Custom version | Buy me a beer or coffee


Active Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm

Post by head_dunce » Wed Apr 10, 2019 4:19 am

Ok, so I'm trying to figure this out on a test space here http://carguygarage.org
The site is currently a Yahoo Store at https://www.carguygarage.com/

So for example want the category "Cabinets" to have the parent of "Storage" and the parent of "Accessories"
But when I go to Admin > Catalog > Categories
Edit the category "Cabinets" go to the "Data" tab, it only allows me to enter in one parent. I've tried to enter in multiple parents separated by a comma, but it only ever saves one.

Jim
Middle Caicos, Turks and Caicos Islands


Active Member

Posts

Joined
Thu Apr 04, 2019 11:50 pm

Post by xxvirusxx » Wed Apr 10, 2019 4:29 am

Sorry my mistake. I though on products :)

You can test this demo
https://www.opencart.com/index.php?rout ... n_id=18829

My Extensions | OC 3.0.3.1, 3.0.2.0, 2.3.0.2 with bugs fixed | 2.3.0.2 Custom version | Buy me a beer or coffee


Active Member

Posts

Joined
Tue Jul 17, 2012 10:35 pm

Post by head_dunce » Wed Apr 10, 2019 8:38 am

Thanks for the tip

Jim
Middle Caicos, Turks and Caicos Islands


Active Member

Posts

Joined
Thu Apr 04, 2019 11:50 pm

Post by head_dunce » Sat Apr 27, 2019 4:26 am

Ok, I tried to purchase that extension but got some message after purchase saying "Waiting for Proof of ID" so it wouldn't let me download anything. I sent in a support ticket, and I am waiting to hear back.

My problem with that extension is that I assume that will then break other things like file uploads for categories, or API calls (haven't used API calls yet, but will be once I get everything else sorted out so I can connect OC with my Perl order management system which does API called with Yahoo's cart.) So I fear the one OC change will then snowball into a bunch of custom changes.

So, I built on my other hack -
viewtopic.php?f=199&t=211255

And with this, you can add a subcategory to any parent via the comment tag -
/var/www/html/catalog/model/catalog/category.php

Code: Select all

	public function getCategories($parent_id = 0) {
// ######################################################################################################
// ## START: New sort code that looks for a meta tag in the section description to sort the categories.
// ## Put HTML comment in the category description via the admin panel source view. Note you must unview
// ## source view for it to save in the admin panel. Add in this HTML comment with the way you want 
// ## the category sorted. If you add in a subcategory that is not technically a child of the parent
// ## it will include it on the category page anyway so subcategories can have more than one parent.
// ## <!-- name="sortorder" content="21536,16146,16133" -->
// ######################################################################################################

		$description = '';
		$sortordersql = "select description from oc_category_description where category_id=".$parent_id." limit 1";
		$query = $this->db->query($sortordersql);
		foreach ($query->rows as $result) {
				$description = $result['description'];
		}
		$pattern = '/&lt;!--.*?name=&quot;sortorder&quot;.*?content=&quot;(.*)?&quot;.*?--&gt;/i';
		$matches = array();
		$sortorder = '';
		if ( preg_match($pattern, $description, $matches) ){
			$sortorder = $matches[1];
		}

		$sqlquery = "SELECT * FROM " . DB_PREFIX . "category c LEFT JOIN " . DB_PREFIX . "category_description cd ON (c.category_id = cd.category_id) LEFT JOIN " . DB_PREFIX . "category_to_store c2s ON (c.category_id = c2s.category_id) ";

		if(!empty($sortorder)){
			$sqlquery .= " WHERE ( c.parent_id = '".(int)$parent_id."' || c.category_id IN (".$sortorder.")   )";
		} else {
			$sqlquery .= " WHERE c.parent_id = '".(int)$parent_id."'";
		}

		$sqlquery .= " AND cd.language_id = '" . (int)$this->config->get('config_language_id') . "' AND c2s.store_id = '" . (int)$this->config->get('config_store_id') . "'  AND c.status = '1' ";

		if(!empty($sortorder)){
			$sqlquery .= " ORDER BY IF(FIELD(c.category_id,$sortorder)=0,1,0),FIELD(c.category_id,$sortorder)";
		} else {
			$sqlquery .= " ORDER BY c.sort_order, LCASE(cd.name)";
		}

		$query = $this->db->query($sqlquery);

		return $query->rows;
// ######################################################################################################
// ## END: New sort code that looks for a meta tag in the section description to sort the categories.
// ######################################################################################################
	}

Jim
Middle Caicos, Turks and Caicos Islands


Active Member

Posts

Joined
Thu Apr 04, 2019 11:50 pm

Post by letxobnav » Sat Apr 27, 2019 4:30 am

So I fear the one OC change will then snowball into a bunch of custom changes.
I fear that that is exactly what you are now doing.

Crystal Light Centrum Taiwan


Active Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm

Post by head_dunce » Sat Apr 27, 2019 4:35 am

letxobnav wrote:
Sat Apr 27, 2019 4:30 am
So I fear the one OC change will then snowball into a bunch of custom changes.
I fear that that is exactly what you are now doing.
Easy changes to comment tags. Simple stuff. You should see what I did to Yahoo's RTML :laugh: This is just front end stuff.

Jim
Middle Caicos, Turks and Caicos Islands


Active Member

Posts

Joined
Thu Apr 04, 2019 11:50 pm

Post by letxobnav » Sat Apr 27, 2019 5:02 am

well, we all know what happened to Yahoo..., now we know why...

Crystal Light Centrum Taiwan


Active Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm

Post by head_dunce » Sat Apr 27, 2019 5:45 am

letxobnav wrote:
Sat Apr 27, 2019 5:02 am
well, we all know what happened to Yahoo..., now we know why...
Ha, funny guy :crazy: Happy Friday, have a good weekend. -- oh I just "fixed" the breadcrumbs too, will post the code later. Next up figure out the API end of what I need, read something about event triggers too, fun fun fun! But plans to snorkel and fish all weekend, see ya Monday!

Jim
Middle Caicos, Turks and Caicos Islands


Active Member

Posts

Joined
Thu Apr 04, 2019 11:50 pm
Who is online

Users browsing this forum: No registered users and 3 guests