Forums / Customization from the Admin / Multiple Categories Link Manager - an Improvement.

Multiple Categories Link Manager - an Improvement.

Views: 5,489

Results 1 to 20 of 24
28 Jun 2009, 5:25 PM
#1
ryk avatar

ryk

Totally Zenned

Join Date:
Oct 2004
Location:
Southport, UK
Posts:
3,644
Plugin Contributions:
6

Multiple Categories Link Manager - an Improvement.

A customisation FOR admin, rather than from it.

We manage a zen-cart store for a pizza company with over 100 franchises (each franchise being a first level category) all selling the same "menu", so all products in the sub-categories are linked. Default ZC displays the Multiple Categories Link Manager using category ID's which is not particularly helpful, and I wanted to be able to see the PARENT category name (ie, in our case, the name of the franchise). Having struggled for a few hours (as I STILL don't actually understand php! :D) I have come up with a solution that works nicely. Now this may not be elegant, but I just could not get the zen_get_categories_parent_name function to work (probably due to ignorance) although by copying the content of that function into the file, I got a result.

So, for anyone who would like to do the same, firstly make a backup copy of admin/products_to_categories.php

Then edit the file and about line 650, replace echo ' <td class="dataTableContent" align="right">' . $categories_list->fields['categories_id'] . '</td>' . "\n";with echo ' <td class="dataTableContent" align="right">'. $parentName.'</td>' . "\n";NB. If you wanted to show both the Parent Category name AND the actual category ID, then use ```
echo ' <td class="dataTableContent" align="right">' . $parentName . '(' . $categories_list->fields['categories_id'] . ')</td>' . "\n";


Then at about line 638 (yes, I know it's backwards, but it made it easier to find the first line number!) find

$cnt_columns = 0;
while (!$categories_list->EOF) {
$cnt_columns++;

$cnt_columns = 0;
while (!$categories_list->EOF) {
//BOF -- To replace Category ID with PARENT category name
$lookup_query = "select parent_id from " . TABLE_CATEGORIES . " where categories_id='" . (int)$categories_list->fields['categories_id'] . "'";
$lookup = $db->Execute($lookup_query);
$lookup_query = "select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id='" . (int)$lookup->fields['parent_id'] . "'";
$lookup = $db->Execute($lookup_query);
$parentName= $lookup->fields['categories_name'];

//EOF -- To replace Category ID with PARENT category name

$cnt_columns++;

Development Manager @ JSWeb Ltd - suppliers of Applepay/Googlepay for Zencart
20 years with Zencart !

28 Jun 2009, 8:32 PM
#2
limelites avatar

limelites

Totally Zenned

Join Date:
Jan 2009
Posts:
2,085
Plugin Contributions:
0

Re: Multiple Categories Link Manager - an Improvement.

Thanks for sharing, hopefully it'll prove useful to others.

10 Nov 2010, 10:23 AM
#3
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,875
Plugin Contributions:
7

Re: Multiple Categories Link Manager - an Improvement.

VERY useful, thanks again for this!

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

10 Nov 2010, 4:52 PM
#5
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Multiple Categories Link Manager - an Improvement.

I can see where that could be handy, but it does not help as much on deeper Categories ...

You might look at changing the display for the Categories Name to:

      if ($product_to_copy->fields['master_categories_id'] == $categories_list->fields['categories_id']) {
//        echo '  <td class="dataTableContent" align="left">' . ($selected ? '<strong>' : '') . $zc_categories_checkbox . ' ' . $categories_list->fields['categories_name'] . ($selected ? '</strong>' : '') . ' ' . zen_image(DIR_WS_IMAGES . 'icon_yellow_on.gif', IMAGE_ICON_LINKED) . '</td>' . "\n";
        echo '  <td class="dataTableContent" align="left">' . ' ' . zen_image(DIR_WS_IMAGES . 'icon_yellow_on.gif', IMAGE_ICON_LINKED) . ' ' . zen_output_generated_category_path($categories_list->fields['categories_id']) . zen_draw_hidden_field('current_master_categories_id', $categories_list->fields['categories_id']) . '</td>' . "\n";
      } else {
        echo '  <td class="dataTableContent" align="left">' . ($selected ? '<strong>' : '') . $zc_categories_checkbox . ' ' . zen_output_generated_category_path($categories_list->fields['categories_id']) . ($selected ? '</strong>' : '') . '</td>' . "\n";
      }

This way you see the full depth of the Categories branch rather than just 1 parent up ...

NOTE: I have not tested this on a database with a large amount of Categories to know what the speed might change to for bigger databases with a lot of Categories to see if this needs to be refined in another manner ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

10 Nov 2010, 5:43 PM
#6
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,875
Plugin Contributions:
7

Re: Multiple Categories Link Manager - an Improvement.

I tried it on a local windows pc, 2000+ categories took about 7 seconds, well worth it for the information.

All it needs now to make my day is the category list arranged alphabetically.....:cheers:

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

10 Nov 2010, 7:08 PM
#7
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Multiple Categories Link Manager - an Improvement.

They are in alpha order from left to right, top to bottom ... :unsure:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

10 Nov 2010, 10:46 PM
#8
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,875
Plugin Contributions:
7

Re: Multiple Categories Link Manager - an Improvement.

I see that only the final subcategories are sorted so at the moment
z->z->-a comes before
a->a->-b

but I meant a sort based on each category level.
a-a-b
a-b-a
a-b-c
a-c-a etc

Here's a screenshot of what I get which is not of any real use just sorted on the last category.
http://www.motorvista.es/images/linked_categories.gif

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

11 Nov 2010, 1:49 PM
#9
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Multiple Categories Link Manager - an Improvement.

I am afraid for that I do not have a simple solution ... :unsure:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

11 Nov 2010, 1:52 PM
#10
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Multiple Categories Link Manager - an Improvement.

You would pretty much need to process the entire list output into an array, then resort it using the now-available top cat names, then subcat names, etc.

11 Nov 2010, 9:19 PM
#11
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,875
Plugin Contributions:
7

Re: Multiple Categories Link Manager - an Improvement.

You would pretty much need to process the entire list output into an array, then resort it using the now-available top cat names, then subcat names, etc.

Yes, that is what I imagined.
I don't think it would be difficult to do (for some people)... I was just hoping not to be the one to do it!

Last question, what would be the most appropriate existing zen function to learn from/copy/modify to have a go at doing this?

thanks
Steve

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

12 Nov 2010, 3:56 PM
#12
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Multiple Categories Link Manager - an Improvement.

Not sure about existing functions... Without looking at the whole file to get the context, I don't know how easy it would be to abstract this into a function. At any rate, my basic approach would be to take the output of
zen_output_generated_category_path($categories_list->fields['categories_id'])
and put the whole thing into the first field of an array (possibly with the rest of its output text/formatting), then explode it and put the pieces in subfields so they can be used. Beyond this, I would have to actually start doing it before I knew the best way to proceed.
You would want to sort first on the deepest level, then repeat on higher levels so the blocks of sorted subcats move into their appropriate top cat order.

13 Nov 2010, 6:14 PM
#13
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,875
Plugin Contributions:
7

Re: Multiple Categories Link Manager - an Improvement.

What is the reasoning behind the Multiple Categories Link Manager only listing categories that already have a product in them?
Why no empty ones?

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

13 Nov 2010, 6:25 PM
#14
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Multiple Categories Link Manager - an Improvement.

One reason was that it listed less Categories to deal with in the display ...

Then, the time savings that individual Categories did not need to be tested as being valid for Products to be added to them ...

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

13 Nov 2010, 6:47 PM
#15
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,875
Plugin Contributions:
7

Re: Multiple Categories Link Manager - an Improvement.

OK, thanks, (I need to to see all the empty categories too).

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

13 Nov 2010, 9:45 PM
#16
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Multiple Categories Link Manager - an Improvement.

You would end up with a screen of all parent categories and sub categories with categories that could result in a screen that times out ... unless you tested each category 1 by 1 before drawing to make sure it does not hold a category ...

How many Categories do you have?

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!

13 Nov 2010, 10:06 PM
#17
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,875
Plugin Contributions:
7

Re: Multiple Categories Link Manager - an Improvement.

unless you tested each category 1 by 1 before drawing to make sure it does not hold a category
That was what I was intending to do as well as only generate a list based on the one top-level category I am interested in.

I am not quite sure how many categories I have that I need to look at in this way, but about 600 at the moment.

I have just finished manually (yes one by one!) linking the first product that is common to almost all categories/bikes to 509 categories, hence I have decided I really need now to find a better visual way to see what is linked or not in all the suitable lowest level subcategories.

So a full sort and showing empty subcats are the two things I need to do.
I am currently clearing up the current 170 validation (form and table) errors before I start, to help me spot my new ones!

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

23 Jan 2011, 9:00 PM
#18
torvista avatar

torvista

Totally Zenned

Join Date:
Aug 2007
Location:
Gijón, Asturias, Spain
Posts:
2,875
Plugin Contributions:
7

Re: Multiple Categories Link Manager - an Improvement.

In the end (or rather just after I started..), I got a pro in to do what I needed, and here it is:

http://www.zen-cart.com/forum/showthread.php?t=172698

Steve
github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

31 May 2013, 3:58 PM
#19
fireflyz avatar

fireflyz

New Zenner

Join Date:
May 2007
Location:
Los Angeles
Posts:
89
Plugin Contributions:
0

Re: Multiple Categories Link Manager - an Improvement.

Hi all,
There are way too many categories which we don't link to. We only link to Top level categories. Is it possible to modify the code to only list the top level categories and maybe the existing category to which the product belongs to?

Thanks!

31 May 2013, 6:42 PM
#20
gjh42 avatar

gjh42

Black Belt

Join Date:
Jul 2005
Location:
Upstate NY
Posts:
21,876
Plugin Contributions:
8

Re: Multiple Categories Link Manager - an Improvement.

The site you show is not Zen Cart, nor can I see any ZC sites for certain in links... so where is the site with the issue, and what categories are you talking about?

Also, from the way you describe it, you may be linking products into categories that also have subcategories, which causes problems with Zen Cart's product/category index display and possibly pricing and other things. So we need more detailed info on what you have done.