Forums / Templates, Stylesheets, Page Layout / Is this possible ? Two or more product listing layouts (one per category)?

Is this possible ? Two or more product listing layouts (one per category)?

Views: 8,064

Results 21 to 40 of 52
18 Aug 2011, 3:53 PM
#21
stsung avatar

stsung

New Zenner

Join Date:
Aug 2011
Posts:
21
Plugin Contributions:
0

Is this possible ? Two or more product listing layouts (one per category)?

I tried working with one subcategory whichID is 2_18. I tried both 2_18 and 18 and I got the very same result - blank page.

I did not try with top category as I don't have any products listed there. but it should work with any category as far as I know.

the shop I'm working on now...
http://outcast.cz/

21 Aug 2011, 2:07 AM
#22
gjh42 avatar

gjh42

Black Belt

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

Re: Is this possible ? Two or more product listing layouts (one per category)?

$current_category_id will only reference the id of the (sub)category being processed, and not the cPath (except for top cats). It cannot handle other categories or groups of subcats.

(int)$cPath will resolve to the top category id of the current category or subcat, whatever it is.
COLOR="Red"$cPath == 3[/COLOR] will handle all subcats of top category 3, such as 3_14_37 or 3_29.

21 Aug 2011, 7:38 PM
#23
stsung avatar

stsung

New Zenner

Join Date:
Aug 2011
Posts:
21
Plugin Contributions:
0

Re: Is this possible ? Two or more product listing layouts (one per category)?

THANK YOU! I should have noticed this before...

the shop I'm working on now...
http://outcast.cz/

22 Aug 2011, 1:09 PM
#24
gjh42 avatar

gjh42

Black Belt

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

Re: Is this possible ? Two or more product listing layouts (one per category)?

Glad you have it working now! By the way, you previously used
$current_category_id != ^2$)
which is regular expression syntax, but this is not a situation where regular expressions can be evaluated.

29 Aug 2011, 2:02 PM
#25
idc1 avatar

idc1

Zen Follower

Join Date:
Jul 2011
Posts:
139
Plugin Contributions:
0

Re: Is this possible ? Two or more product listing layouts (one per category)?

I have tried several different expressions. Can I get some assistance as to what is wrong with my coding? I need to assign row layout in many locations for example:

-all subcategories of $cPath == 45_1180_108850
-just subcategory 114450

I have tried
if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns' AND (int) $current_category_id !== 114450) { //worked for single category

if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns' AND (int) $current_category_id !== 114450 || 2260) { //did not work

if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns' AND (int) $current_category_id !== 114450 || PRODUCT_LISTING_LAYOUT_STYLE == 'columns' AND (int) $current_category_id !== 2260) { //worked for 2260 but did not on 114450

if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns' AND (int) $cPath !== 45_1180_108850_) { //did not work

if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns' AND (int) $cPath !== 45_1180_108850) { //removed last underscore and it did not work

I've kept the same structure and tried variations depending if it was the row or column statement:
if (PRODUCT_LISTING_LAYOUT_STYLE == 'rows' OR (int) $current_category_id == 2260) {
or
if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns' AND (int) $current_category_id !== 2260) {

ZC 1.5.5
Add ons: - Column/Grid 1.3.8 - Dual pricing 1.7 - ImageHandler3

29 Aug 2011, 3:34 PM
#26
gjh42 avatar

gjh42

Black Belt

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

Re: Is this possible ? Two or more product listing layouts (one per category)?

To clarify, by "all subcategories of $cPath == 45_1180_108850"
did you mean all subcategories of top cat 45? Or all subcats of sub-subcat 108850? (The second would be trickier.)

When testing for alternate conditions, it is always clearer and may be important to use parentheses to group conditions rather than letting operator precedence do all the work.

if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns' AND (int) $current_category_id !== 114450 || 2260) { //did not workTry

if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns' AND $current_category_id !== 114450 and $current_category_id !== 2260) { //grouping not strictly needed here

or

if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns' AND (!in_array($current_category_id, explode(',','114450,2260')))) { //you can add more categories to the array

30 Aug 2011, 3:40 PM
#27
idc1 avatar

idc1

Zen Follower

Join Date:
Jul 2011
Posts:
139
Plugin Contributions:
0

Re: Is this possible ? Two or more product listing layouts (one per category)?

GJH42, Thanks for the help

gjh42:

To clarify, by "all subcategories of $cPath == 45_1180_108850"
did you mean all subcategories of top cat 45? Or all subcats of sub-subcat 108850? (The second would be trickier.)
I could see using both methods but originally I was asking for all subcats of subcat 108850.

However your below method works great for me at this point. Ideally I would like to be able to just have a field in the Categories table designating the layout, but I need to crawl before I run. Thanks again GJH42 as this will get me through this hurdle.

gjh42:

if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns' AND (!in_array($current_category_id, explode(',','114450,2260')))) { //you can add more categories to the array

For anyone using GJH42's suggestion I have quoted, please note the following are the two required peices of text

if (PRODUCT_LISTING_LAYOUT_STYLE == 'rows' OR (in_array($current_category_id, explode(',','104150,2260')))) {

if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns' AND (!in_array($current_category_id, explode(',','104150,2260')))) {

I will also point out for rookies such as myself, do NOT overlook the ! in the column statement or else you will confuse the crap out of your computer. Leaving it out or accidently copying it into the rows statement will make both statements return the same result.

ZC 1.5.5
Add ons: - Column/Grid 1.3.8 - Dual pricing 1.7 - ImageHandler3

30 Aug 2011, 3:55 PM
#28
idc1 avatar

idc1

Zen Follower

Join Date:
Jul 2011
Posts:
139
Plugin Contributions:
0

Re: Is this possible ? Two or more product listing layouts (one per category)?

GJH42,

out of curosity can I mix and match Top Cat ID and Sub Cat ID's. For example (the code may be wrong but hopefully it demonstrates my question)

explode(',','^45$,2260'))))

ZC 1.5.5
Add ons: - Column/Grid 1.3.8 - Dual pricing 1.7 - ImageHandler3

30 Aug 2011, 7:22 PM
#29
gjh42 avatar

gjh42

Black Belt

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

Re: Is this possible ? Two or more product listing layouts (one per category)?

The explode() function does not evaluate regular expressions, so ^45$ is not going to do anything.

If you want to test for subcats of a particular top cat as well as some specific subcats, you would need a combination of two kinds of test, $current_category_id for subcats and (int)$cPath for top cats:
(in_array($current_category_id, explode(',','104150,2260'))) or (in_array(COLOR="Red"$cPath[/COLOR], explode(',','10,23,45')))
These would need to be used with OR or AND as appropriate, like the previous examples.

23 Dec 2011, 11:01 AM
#30
post_carlos avatar

post_carlos

New Zenner

Join Date:
Dec 2011
Posts:
15
Plugin Contributions:
0

Re: Is this possible ? Two or more product listing layouts (one per category)?

yellow1912:

This is what I did, worked like a charm if you want to select the product listing module you want to use:

$listing_module_loaded = false;
if(!$is_index_listing && $GET['main_page'] == 'index' && !empty($cPath)){
$category_array = explode('
', $cPath);
$category_array = array_reverse($category_array);
foreach ($category_array as $c){
$listing_module_file = DIR_WS_MODULES . zen_get_module_directory("product_listing_c_$c.php");
if(file_exists($listing_module_file)){
include($listing_module_file);
$listing_module_loaded = true;
break;
}
}
}
if(!$listing_module_loaded)
include(DIR_WS_MODULES . zen_get_module_directory(FILENAME_PRODUCT_LISTING));



Dear yellow1912,


I have a zen-cart website with a modification to make it work with two
or more different product listing layouts, one per category (instead
of the standard single product listing layout). Depending on the
selected category, a different product_listing.php file is loaded.
The problem is that each specific product_listing.php files need to be made manually
for each new category.

What I really need for my zen-cart website is:

- I need 10 additional product listing layouts, next to the existing standard
'product listing' layout' (like "product2 listing", "product3 listing" etc.) integrated in my shop.
- Each additional product listing layouts needs to be adjustable from
the admin (just like the standard 'product listing'), each with it's own
specific configuration:
       - the number of columns
       - choose between 4, 3, 2 columns (grid view) or single column view,
       - number of products per page.
- I need an option in the admin, that when creating a new category or
editing a category,  you need to choose from a popdown which 1 of the 10 product
listing layouts it has to use for that specific category (i think that's got to be added in the database?)
- each product listing needs to be styled with it's own stylesheets.

Can someone help me?
25 Dec 2011, 5:11 AM
#31
gjh42 avatar

gjh42

Black Belt

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

Re: Is this possible ? Two or more product listing layouts (one per category)?

Yellow1912 is no longer active in the forum. What you are asking for here is a highly specific and complex set of custom coding, and you will need to hire someone to write it if you can't do it yourself. Look for the Commercial Help Wanted section, with its link to oDesk for posting your request.

23 Mar 2012, 11:22 PM
#32
dgent avatar

dgent

Totally Zenned

Join Date:
Nov 2009
Location:
UK
Posts:
1,117
Plugin Contributions:
0

Re: Is this possible ? Two or more product listing layouts (one per category)?

I'm a bit confused on this thread. I want the same thing, just to use a different product listing template file for a certain category.

What is the code required and what file do I insert it in?

25 Mar 2012, 1:28 PM
#34
gjh42 avatar

gjh42

Black Belt

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

Re: Is this possible ? Two or more product listing layouts (one per category)?

I think you would put your if() test in /includes/templates/your_template/templates/tpl_modules_product_listing.php, which is what calls tpl_columnar_display.php.

26 Mar 2012, 10:06 AM
#35
dgent avatar

dgent

Totally Zenned

Join Date:
Nov 2009
Location:
UK
Posts:
1,117
Plugin Contributions:
0

Re: Is this possible ? Two or more product listing layouts (one per category)?

This is what Ive got and the modified extra line in the middle, but at the moment it brings up two lots of listings (one below the other) on one page if im in category 544.

How do I make it only display the one listing (tpl_columnar_display2.php)?

<?php /** * load the list_box_content template to display the products */ if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') { require($template->get_template_dir('tpl_columnar_display.php',DIR_WS_TEMPLATE, $current_page_base,'common'). '/tpl_columnar_display.php'); } if ($current_category_id !== 544) { require($template->get_template_dir('tpl_columnar_display2.php',DIR_WS_TEMPLATE, $current_page_base,'common'). '/tpl_columnar_display2.php'); } else {// (PRODUCT_LISTING_LAYOUT_STYLE == 'rows') require($template->get_template_dir('tpl_tabular_display.php',DIR_WS_TEMPLATE, $current_page_base,'common'). '/tpl_tabular_display.php'); } ?>
26 Mar 2012, 3:05 PM
#36
gjh42 avatar

gjh42

Black Belt

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

Re: Is this possible ? Two or more product listing layouts (one per category)?

I expect you have set the listing style to "columns".
Then when it gets to the first if(), it outputs the listing because that is true, and when it gets to the second if() that is also true so it outputs again. You need to reorganize the tests so you cover each possibility once. The way your posted code is written, you will get the extra listing unless you are on cat 544 ($current_category_id !== 544). Is that what you want? ```php
if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
require($template->get_template_dir('tpl_columnar_display.php',DIR_WS_TEMPLATE, $current_page_base,'common'). '/tpl_columnar_display.php');

}

if ($current_category_id !== 544) {
require($template->get_template_dir('tpl_columnar_display2.php',DIR_WS_TEMPLATE, $current_page_base,'common'). '/tpl_columnar_display2.php');

}

else {// (PRODUCT_LISTING_LAYOUT_STYLE == 'rows')

needs to be something like ```php
if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns') {
  if ($current_category_id == 544) {
    require($template->get_template_dir('tpl_columnar_display2.php',DIR_WS_TEMPLATE, $current_page_base,'common'). '/tpl_columnar_display2.php');
  } else {
    require($template->get_template_dir('tpl_columnar_display.php',DIR_WS_TEMPLATE, $current_page_base,'common'). '/tpl_columnar_display.php');
  }
} else {// (PRODUCT_LISTING_LAYOUT_STYLE == 'rows')
26 Mar 2012, 3:08 PM
#37
dgent avatar

dgent

Totally Zenned

Join Date:
Nov 2009
Location:
UK
Posts:
1,117
Plugin Contributions:
0

Re: Is this possible ? Two or more product listing layouts (one per category)?

Ok ive got this working, but working in reverse, ie cat 544 is pulling up tpl_tabular_display.php and all other cats are pulling up tpl_columnar_display2.php

<?php /** * load the list_box_content template to display the products */ if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns' AND $current_category_id !== 544) { require($template->get_template_dir('tpl_columnar_display2.php',DIR_WS_TEMPLATE, $current_page_base,'common'). '/tpl_columnar_display2.php'); } else {// (PRODUCT_LISTING_LAYOUT_STYLE == 'rows') require($template->get_template_dir('tpl_tabular_display.php',DIR_WS_TEMPLATE, $current_page_base,'common'). '/tpl_tabular_display.php'); } ?>

Any ideas? What I also want is multiple statements for multiple cats, so they can pull up different columnar display files for each category.

26 Mar 2012, 3:16 PM
#40
gjh42 avatar

gjh42

Black Belt

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

Re: Is this possible ? Two or more product listing layouts (one per category)?

The current code you have posted will call tpl_columnar_display.php if you are set to "columns";
tpl_columnar_display2.php if you are not in cat 544 no matter the setting;
or tpl_tabular_display.php if you are in cat 544 no matter the setting.

Nevermind, I didn't see your posts after my previous one.