Zen Cart Logo
Forums / Setting Up Categories, Products, Attributes / Main Category - sub heading sort - is it possible?

Main Category - sub heading sort - is it possible?

Locked

Views: 3,226

Results 1 to 16 of 16
This thread is locked. New replies are disabled.
11 Jun 2008, 2:33 PM
#1
wokka avatar

wokka

New Zenner

Join Date:
May 2008
Posts:
12
Plugin Contributions:
0

Main Category - sub heading sort - is it possible?

Hi,

I'm wondering if it's possible to sort or analyse sub-categories within the center section window?

I'm setting up a printer cartridge Zen Cart e-commerce site and want to group the HP printers into sub groups in the main center window.

I know I can hard code the category sort by entering a sort order number in the category setup screen - but I would like to have a sub-heading just above each group of these printers.

Eg. All the HP types of printers are under the HP category.
If I assign, say 10 to all the Deskjet Printer Categories and 20 to all the officejet Printer Categories - would it be possible for the center screen to display the categories
like this:-

HP Deskjet Printers:
Deskjet 1 - Deskjet 2 - Deskjet 3
Deskjet 4 ..... so on and so on

HP Officejet Printers:
Officejet 1 - Officejet 2 - Officejet 3
Officejet 4 .... so on and so on

Any help would be appreciated.

Many thanks,
John

11 Jun 2008, 5:27 PM
#2
gjh42 avatar

gjh42

Black Belt

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

Re: Main Category - sub heading sort - is it possible?

As you are using the Column Grid mod for the display, you would add/modify the code in that copy of /includes/modules/your_template/product_listing.php.

Find this section```php
// Following code will be executed only if Column Layout (Grid Layout) option is chosen
if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
$lc_text = implode('<br />', $product_contents);
$list_box_contents[$rows][$column] = array('params' => 'class="centerBoxContentsProducts centeredContent back"' . ' ' . 'style="width:' . $col_width . '%;"',
'text' => $lc_text);
$column ++;
if ($column >= PRODUCT_LISTING_COLUMNS_PER_ROW) {
$column = 0;
$rows ++;
}
}

$lc_text = implode('<br />', $product_contents); 
line with ```php
      $section_check = $listing->fields['products_name'];
      $section_header = '';
      if (in_array($section_check,explode(",",'list_names_to_start_new_lines_here,separated_by_commas,and_no_spaces'))) {
        $column = -1;
        $rows ++;
        switch ($section_check) {
        case "first name":
          $section_header = 'First Section';
        break;
        case "second name":
          $section_header = 'Second Section';
        break;
        } //switch
      } //if
      $lc_text = '<div class="sectionHeader">' . $section_header . '</div>' . implode('<br />', $product_contents);
```Put all of the names that begin sections in the explode function. I'm not sure about the effect of internal spaces in the names, whether they will cause problems or not. If so, some more code tweaking will be needed.

Repeat the case ... break; code for each section heading in the list.

Style .sectionHeader {} as desired in your stylesheet.

I haven't tested this, and it probably will need some adjusting, but I think this approach will do the job.
11 Jun 2008, 5:39 PM
#3
gjh42 avatar

gjh42

Black Belt

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

Re: Main Category - sub heading sort - is it possible?

First correction: the end of the code replacement needs to only add the div when there is a section header.php } //switch } //if $lc_text = '<div class="sectionHeader">' . $section_header . '</div>' . implode('<br />', $product_contents); should be```php
} //switch
$section_header = '<div class="sectionHeader">' . $section_header . '</div>';
} //if
$lc_text = $section_header . implode('<br />', $product_contents);

11 Jun 2008, 6:29 PM
#4
wokka avatar

wokka

New Zenner

Join Date:
May 2008
Posts:
12
Plugin Contributions:
0

Re: Main Category - sub heading sort - is it possible?

Hi Glenn,

Thanks for your reply and for looking into this for me.

I should have posted example links to the site - sorry.

I think the product listing looks better in rows (some printers have up to 9 different cartridges that work in them) - so I don't think the column grid mod for products is being used - it might be though as I'm only new to ZC.
Eg Product page
http://www.123-inkjet-cartridges.co.uk/index.php?main_page=index&cPath=919_981

I'm hoping to organise the Categories that are in the main HP holding category here
http://www.123-inkjet-cartridges.co.uk/index.php?main_page=index&cPath=919

I've only loaded a small selection up to now and the page is already getting quite long - as I'm not showing any images in this section, is it possible to reduce the space between each row?

Thanks again for your help :D

John

11 Jun 2008, 7:41 PM
#5
gjh42 avatar

gjh42

Black Belt

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

Re: Main Category - sub heading sort - is it possible?

Ah yes, the link and description makes a difference. You have multiple products for each printer model, so the header insertion code would not go in any version of product_listing.php. It may be category_row.php that needs to be edited. The same principles will apply, though many of the variables will be different. I'll look at that later - have to go now.

16 Jun 2008, 2:59 PM
#6
wokka avatar

wokka

New Zenner

Join Date:
May 2008
Posts:
12
Plugin Contributions:
0

Re: Main Category - sub heading sort - is it possible?

The site has been down for a few days and I've changed the url structure.

So I thought I would post links to the main HP category page again:-
http://www.123-inkjet-cartridges.co.uk/hp-ink-cartridges-23/

It would be fantastic if the different families of HP printers could be separated (to make the page more readable) with titles like:-

HP Deskjet Series Printer Cartridges:-
deskjet 1 deskjet 2 deskjet 3 ....

HP Officejet Series Printer Ink Cartridges:-
Officejet 1 Officejet 2 Officejet 3....

Hope you can help.

Many thanks,
John

17 Jun 2008, 6:43 PM
#7
gjh42 avatar

gjh42

Black Belt

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

Re: Main Category - sub heading sort - is it possible?

Copy /includes/modules/category_row.php to /includes/modules/your_template/category_row.php.
Find this line php $list_box_contents[$row][$col] = array('params' => 'class="categoryListBoxContents"' . ' ' . 'style="width:' . $col_width . '%;"', 'text' => '<a href="' . zen_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . zen_image(DIR_WS_IMAGES . $categories->fields['categories_image'], $categories->fields['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br />' . $categories->fields['categories_name'] . '</a>'); and replace with```php
// subheadings - gjh42 20080617
$section_check = $categories->fields['categories_name'];
$section_header = '';
if (in_array($section_check,explode(",",'list_names_to_start_new_lines_here,separated_by_commas,and_no_spaces'))) {
$col = 0;
$row ++;
switch ($section_check) {
case "first name":
$section_header = 'First Section';
break;
case "second name":
$section_header = 'Second Section';
break;
} //switch
$list_box_contents[$row][$col] = array('params' => 'class="sectionHeader" style="width: 100%;"',
'text' => $section_header);
$row ++;
} //if
// /subheadings
$list_box_contents[$row][$col] = array('params' => 'class="categoryListBoxContents"' . ' ' . 'style="width:' . $col_width . '%;"',
'text' => '<a href="' . zen_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . zen_image(DIR_WS_IMAGES . $categories->fields['categories_image'], $categories->fields['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br />' . $categories->fields['categories_name'] . '</a>');

17 Jun 2008, 6:59 PM
#8
gjh42 avatar

gjh42

Black Belt

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

Re: Main Category - sub heading sort - is it possible?

Here is a tweak to improve display consistency.
The code above will start a new line for the heading, but if the last row was filled, there will already be a new line. If there is a new line, $col will be 0, so replace thisphp $col = 0; $row ++; with this```php
$col != 0?$row ++:'';
$col = 0;

19 Jun 2008, 9:44 AM
#9
wokka avatar

wokka

New Zenner

Join Date:
May 2008
Posts:
12
Plugin Contributions:
0

Re: Main Category - sub heading sort - is it possible?

Glenn - Thanks so much for looking at this for me.

My lack of knowledge of ZC and my application of your coding is letting me down...

In the section of code below:-
*if in_array($section_check,explode(",",'list_names_to_start_new_lines_here,separated_by_commas,and_no_spaces'))) { *
Do I replace the 'list_names_to_start_new....' with example 'HP Deskjet,HP Officejet,....'
Or, do I insert these between the "" double quotes?

Also, is this the only place I need to adjust your code?

I'm really sorry - I have tried a few combinations - without any change or the center section just goes blank.

Thanks in advance of your help.

Regards,
John

19 Jun 2008, 9:07 PM
#10
gjh42 avatar

gjh42

Black Belt

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

Re: Main Category - sub heading sort - is it possible?

That is the right format you posted for the explode list.

You also need to put each one of those items in a case statement - replace
case "first name":
with
case "HP Deskjet":
and
$section_header = 'First Section';
with
$section_header = 'HP Deskjet Printers'; //or whatever you want for the header

Repeat for each item in the list.

20 Jun 2008, 6:19 AM
#11
wokka avatar

wokka

New Zenner

Join Date:
May 2008
Posts:
12
Plugin Contributions:
0

Re: Main Category - sub heading sort - is it possible?

Ok, I have applied as per your instructions - but the printer names are still appearing as before. Details of the code below:

*// subheadings - gjh42 20080617
$section_check = $categories->fields['categories_name'];
$section_header = '';
if (in_array($section_check,explode(",",'HP Deskjet,HP Digital,HP Fax,HP Officejet,HP Photo,HP PSC'))) {
$col = 0;
$row ++;
switch ($section_check) {
case "HP Deskjet":
$section_header = 'Hewlett Packard Deskjet Series Printer Cartridges';
break;
case "HP Digital":
$section_header = 'HP Digital Copier Cartridges';
break;
case "HP Fax":
$section_header = 'HP Fax Printer Cartridges';
break;
case "HP Officejet":
$section_header = 'HP Officejet Ink Cartridges';
break;
case "HP Photo":
$section_header = 'HP Photosmart Printer Inks';
break;
case "HP PSC":
$section_header = 'HP Printer/Scanner/Copier Cartridges';
break;
case "HP Cartridges":
$section_header = 'HP Ink Cartridges by References';
break;
} //switch
$list_box_contents[$row][$col] = array('params' => 'class="sectionHeader" style="width: 100%;"',
'text' => $section_header);
$row ++;
} //if
// /subheadings
$list_box_contents[$row][$col] = array('params' => 'class="categoryListBoxContents"' . ' ' . 'style="width:' . $col_width . '%;"',
'text' => '<a href="' . zen_href_link(FILENAME_DEFAULT, $cPath_new) . '">' . zen_image(DIR_WS_IMAGES . $categories->fields['categories_image'], $categories->fields['categories_name'], SUBCATEGORY_IMAGE_WIDTH, SUBCATEGORY_IMAGE_HEIGHT) . '<br />' . $categories->fields['categories_name'] . '</a>');
*
Can you see where I've gone wrong?

20 Jun 2008, 11:23 PM
#12
gjh42 avatar

gjh42

Black Belt

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

Re: Main Category - sub heading sort - is it possible?

For debugging, add an echo statement after this line:
$section_check = $categories->fields['categories_name'];

echo 'name is ' . $section_check;

Does it output anything? The right thing?

Is the first category name really "HP Deskjet" and not "HP Deskjet 123" or some model number?

OK, it looks like it is "HP Deskjet 450". You need to use the exact name of the first subcat in the section - it won't match a partial name.

22 Jun 2008, 10:25 AM
#13
wokka avatar

wokka

New Zenner

Join Date:
May 2008
Posts:
12
Plugin Contributions:
0

Re: Main Category - sub heading sort - is it possible?

Brilliant - works a treat, I was thinking I just had to state the first two words of the category name - Thanks :D

How would I change the font style for 'sectionHeader' - just to make them stand out a bit more?

22 Jun 2008, 11:25 AM
#14
wokka avatar

wokka

New Zenner

Join Date:
May 2008
Posts:
12
Plugin Contributions:
0

Re: Main Category - sub heading sort - is it possible?

Glenn - wondering if you can help with customisation I need to do on the product pages?

I've started a new thread here

Thanks again for all your help so far.

Kind regards,
John

13 Aug 2010, 3:41 AM
#15
danielle avatar

danielle

Totally Zenned

Join Date:
Oct 2004
Posts:
973
Plugin Contributions:
0

Re: Main Category - sub heading sort - is it possible?

I have implemented this mod, but how can I get the subcategories images to show up? Right now, it just shows the section header, and then the subcategories names in each section, but doesn't display the subcategory image.

Thanks!

13 Aug 2010, 3:54 AM
#16
danielle avatar

danielle

Totally Zenned

Join Date:
Oct 2004
Posts:
973
Plugin Contributions:
0

Re: Main Category - sub heading sort - is it possible?

Danielle:

I have implemented this mod, but how can I get the subcategories images to show up? Right now, it just shows the section header, and then the subcategories names in each section, but doesn't display the subcategory image.

Thanks!

Nevermind I tried on another site and it worked great, just something buggy in the first site's template.

Great little mod!