Forums / General Questions / Separate Product Listing by Category

Separate Product Listing by Category

Locked

Views: 2,771

Results 1 to 11 of 11
This thread is locked. New replies are disabled.
12 Sep 2008, 9:48 PM
#1
cinbou avatar

cinbou

New Zenner

Join Date:
Aug 2007
Posts:
91
Plugin Contributions:
0

Separate Product Listing by Category

I'm working on a Jewelry site and I would like to separate the product listing page by category. For instance, I have "Gemstones" listed as a category, when someone clicks on a gemstone, I'd like to divide the page into three categories:

Bracelet
Earrings
Necklace

Here is an example of what I'm trying to do:

http://www.stonehinged.com/amethyst_jewelry.html

Here is the site I'm working on: http://twistjewelrydesign.com/shoppingcart/index.php?main_page=

Is this possible? What do I need to change? Would it mess up my other categories? I'm currently using the add-on that shows subcategories all the time.

Thanks,
Cindy

12 Sep 2008, 11:23 PM
#2
gjh42 avatar

gjh42

Black Belt

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

Re: Separate Product Listing by Category

It would not be a big deal to sort the products by type and then start a new row and add a heading above the first item in each type; but if you only want three of each type per page, that will require some involved coding or perhaps very picky sorting.

13 Sep 2008, 12:35 AM
#3
cinbou avatar

cinbou

New Zenner

Join Date:
Aug 2007
Posts:
91
Plugin Contributions:
0

Re: Separate Product Listing by Category

gjh42,

Sorting the products by type and then starting a new row and adding a heading above the first item in each type would work fine.

How would I go about doing that?

Thanks,
Cindy

13 Sep 2008, 12:53 AM
#4
gjh42 avatar

gjh42

Black Belt

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

Re: Separate Product Listing by Category

The Main Category - sub heading sort - is it possible? thread discusses this.
We got it working for the category/subcategory page, but I think the code as first given will work for the product listing page.
Try it and let me know.

13 Sep 2008, 12:41 PM
#5
cinbou avatar

cinbou

New Zenner

Join Date:
Aug 2007
Posts:
91
Plugin Contributions:
0

Re: Separate Product Listing by Category

Hi Glenn,

I tried it, but it didn't work. Nothing changed on my site. Any ideas?

13 Sep 2008, 12:49 PM
#6
cinbou avatar

cinbou

New Zenner

Join Date:
Aug 2007
Posts:
91
Plugin Contributions:
0

Re: Separate Product Listing by Category

Here is my code:

// Following code will be executed only if Column Layout (Grid Layout) option is chosen
if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
$section_check = $listing->fields['products_name'];
$section_header = '';
if (in_array($section_check,explode(",",'Bracelets,Earrings,Necklaces'))) {
$column = -1;
$rows ++;
switch ($section_check) {
case "First Name":
$section_header = 'First Section';
break;
case "Second Name":
$section_header = 'Second Section';
break;
case "Third Name":
$section_header = 'Third Section';
break;
} //switch
$section_header = '<div class="sectionHeader">' . $section_header . '</div>';
} //if
$lc_text = $section_header . 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 ++;
}
}
// End of Code fragment for Column Layout (Grid Layout) option in add on module

13 Sep 2008, 6:50 PM
#7
gjh42 avatar

gjh42

Black Belt

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

Re: Separate Product Listing by Category

The cases given are generic:
case "First Name":

You need to customize them to match your installation:
case "Bracelets":

13 Sep 2008, 7:54 PM
#8
cinbou avatar

cinbou

New Zenner

Join Date:
Aug 2007
Posts:
91
Plugin Contributions:
0

Re: Separate Product Listing by Category

Thanks Glenn.

I changed the Case names. Still not working... Below is my updated code:

// Following code will be executed only if Column Layout (Grid Layout) option is chosen
if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
$section_check = $listing->fields['products_name'];
$section_header = '';
if (in_array($section_check,explode(",",'Bracelets,Earrings,Necklaces'))) {
$column = -1;
$rows ++;
switch ($section_check) {
case "Bracelets":
$section_header = 'First Section';
break;
case "Earrings":
$section_header = 'Second Section';
break;
case "Necklaces":
$section_header = 'Third Section';
break;
} //switch
$section_header = '<div class="sectionHeader">' . $section_header . '</div>';
} //if
$lc_text = $section_header . 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 ++;
}
}
// End of Code fragment for Column Layout (Grid Layout) option in add on module

13 Sep 2008, 9:08 PM
#9
gjh42 avatar

gjh42

Black Belt

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

Re: Separate Product Listing by Category

First, you need to use the product names in the explode, not the section names.
As your product names are long and may include commas, they will be cumbersome if not fatal to use. It will be better to use product ids, which are short and unique.

    // Following code will be executed only if Column Layout (Grid Layout) option is chosen
    if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
      $section_check = $listing->fields['products_id']; // subheadings - gjh42 20080913 
      $section_header = '';
      if (in_array($section_check,explode(",",'list_ids_to_start_new_lines_here,separated_by_commas,and_no_spaces'))) { 
        $column != 0?$rows ++:''; 
        $column = -1;
        switch ($section_check) {
        case "first id":
          $section_header = 'First Section';
        break;
        case "second id": //repeat case/$section/break for other ids to start headings
          $section_header = 'Second Section';
        break;
        } //switch
        $section_header = '<div class="sectionHeader">' . $section_header . '</div>';
      } //if
      $lc_text = $section_header . implode('<br />', $product_contents);  // /subheadings
      $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 ++;
      }
    }
    // End of Code fragment for Column Layout (Grid Layout) option in add on module
 
14 Sep 2008, 7:00 PM
#10
cinbou avatar

cinbou

New Zenner

Join Date:
Aug 2007
Posts:
91
Plugin Contributions:
0

Re: Separate Product Listing by Category

Glenn,

I'm not sure I totally understand. Do I need to list out every single product ID? This site will have over 300 products. Each "gemstone" page would have a different set of product ids, will this script work for that?

Sorry, if these are dumb questions, but I'm new to all of this.

Thanks,
Cindy

14 Sep 2008, 8:27 PM
#11
gjh42 avatar

gjh42

Black Belt

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

Re: Separate Product Listing by Category

You will need to list each product id that will be the first one in a section. You won't need to list the rest of them.

You do need to assign sort orders to all the products so they display in the correct sequence. Do this in the product editing page.

Another tweak is that some or all of these products will also appear in other categories where you don't want the subheadings. You will need to wrap another test around the code so it only checks for subheadings in the desired categories.```php
// Following code will be executed only if Column Layout (Grid Layout) option is chosen
if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
if (in_array($_GET[cPath],explode(",",'category_paths_to_have_subheadings'))) { // check for subheading cats
$section_check = $listing->fields['products_id']; // subheadings - gjh42 20080913
$section_header = '';
if (in_array($section_check,explode(",",'list_ids_to_start_new_lines_here,separated_by_commas,and_no_spaces'))) {
$column != 0?$rows ++:'';
$column = -1;
switch ($section_check) {
case "first id":
$section_header = 'First Section';
break;
case "second id": //repeat case/$section/break for other ids to start headings
$section_header = 'Second Section';
break;
} //switch
$section_header = '<div class="sectionHeader">' . $section_header . '</div>';
} //if
$lc_text = $section_header . implode('<br />', $product_contents); // /subheadings
$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 ++;
}
} // subheading cats
}
// End of Code fragment for Column Layout (Grid Layout) option in add on module

Replace 
category_paths_to_have_subheadings 
with a comma-separated list of the categories to get subheadings.