Re: 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.
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.
(int)$cPath == 3 will handle all subcats of top category 3, such as 3_14_37 or 3_29.
Re: Is this possible ? Two or more product listing layouts (one per category)?
THANK YOU! I should have noticed this before...
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.
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) {
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.
Quote:
if (PRODUCT_LISTING_LAYOUT_STYLE == 'columns' AND (int) $current_category_id !== 114450 || 2260) { //did not work
Try
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
Re: Is this possible ? Two or more product listing layouts (one per category)?
GJH42, Thanks for the help
Quote:
Originally Posted by
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.
Quote:
Originally Posted by
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.
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'))))
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((int)$cPath, explode(',','10,23,45')))
These would need to be used with OR or AND as appropriate, like the previous examples.
Re: Is this possible ? Two or more product listing layouts (one per category)?
Quote:
Originally Posted by
yellow1912
This is what I did, worked like a charm if you want to select the product listing module you want to use:
PHP Code:
$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?