Zen Cart Logo

Categories in boxes

Locked

Views: 1,017

Results 1 to 12 of 12
This thread is locked. New replies are disabled.
19 Sep 2010, 7:16 PM
#1
stood avatar

stood

New Zenner

Join Date:
Sep 2010
Location:
crewe
Posts:
41
Plugin Contributions:
0

Categories in boxes

Hi
I would like to have "categories" displayed on the main page (the center column) as well as a short description of each on of them. I already have categories on the main page in two nice columns, but I have no idea how to add this descriptions and make them look like they were in separate boxes. Is it possible using some Zen Cart's options I don't know, or I should install a separate module? I will be very greatful for indicating the right solution :)

19 Sep 2010, 9:45 PM
#2
gjh42 avatar

gjh42

Black Belt

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

Re: Categories in boxes

Do you want to use the regular category description that you can enter in admin, or a different version of description? It shouldn't be too hard to add to the SQL query to get the regular descriptions of all of the subcategories in the current list, and then output them along with the name and image.

The separate boxes is just a matter of styling in the stylesheet.

19 Sep 2010, 11:24 PM
#3
stood avatar

stood

New Zenner

Join Date:
Sep 2010
Location:
crewe
Posts:
41
Plugin Contributions:
0

Re: Categories in boxes

Thank you for a fast reply.
It sounds interesting :) I added the description when I was creating a new category, so that should be ok as a starting point ;)
Can I get some hints how to add the SQL query you mentioned?

20 Sep 2010, 3:52 PM
#4
gjh42 avatar

gjh42

Black Belt

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

Re: Categories in boxes

Note that I am not a SQL expert, but I think it would work like this.

In /includes/modules/pages/index/main_template_vars.php, find this```php
if ($category_depth == 'nested')
{
$sql = "SELECT cd.categories_name, c.categories_image
FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
WHERE c.categories_id = :categoriesID
AND cd.categories_id = :categoriesID
AND cd.language_id = :languagesID
AND c.categories_status= '1'";

$sql = $db->bindVars($sql, ':categoriesID', $current_category_id, 'integer');
$sql = $db->bindVars($sql, ':languagesID', $_SESSION['languages_id'], 'integer');
$category = $db->Execute($sql);

"SELECT cd.categories_name, c.categories_image, cd.categories_description
to get```php
if ($category_depth == 'nested')
{
  $sql = "SELECT cd.categories_name, c.categories_image, cd.categories_description
          FROM   " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
          WHERE      c.categories_id = :categoriesID
          AND        cd.categories_id = :categoriesID
          AND        cd.language_id = :languagesID
          AND        c.categories_status= '1'";

  $sql = $db->bindVars($sql, ':categoriesID', $current_category_id, 'integer');
  $sql = $db->bindVars($sql, ':languagesID', $_SESSION['languages_id'], 'integer');
  $category = $db->Execute($sql);

Then in /includes/modules/your_template/category_row.php, find```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>');

. '<br />' . $categories->fields['categories_description']
to get```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'] . '<br />' . $categories->fields['categories_description'] . '</a>');
20 Sep 2010, 8:49 PM
#5
stood avatar

stood

New Zenner

Join Date:
Sep 2010
Location:
crewe
Posts:
41
Plugin Contributions:
0

Re: Categories in boxes

Thank you very much :)
I did everything as you written, but it doesn't seem to be working.
I'll try ine more time to make sure though.
Do you thik that adding a table to the main page using html would be a good alternative for that?

P.S.
One more thing, because I don't know if I got it right. If there is no category_row.php file in the directory you indicated, should I copy it from the "modules" folder?
Sorry for asking this kind of questions, but it is the first time I'm using Zen Cart :)

20 Sep 2010, 10:29 PM
#6
stood avatar

stood

New Zenner

Join Date:
Sep 2010
Location:
crewe
Posts:
41
Plugin Contributions:
0

Re: Categories in boxes

I used a table, so don't worry about me any more :)
I nested tables inside one big table, so that I could position images and links as I want. It's pretty time consuming and probably rather primitive, but it works for me :D
Thank you for your time once again :)
Cheers

20 Sep 2010, 11:04 PM
#7
gjh42 avatar

gjh42

Black Belt

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

Re: Categories in boxes

Yes, nested tables are antiquated and clumsy technology, and do not comform to current Web standards. But if they did the job, that's good enough for now.

Copying category_row.php from /modules/ into /modules/your_template/ to customize it is the correct method.

When you said "it doesn't appear to be working", exactly what was happening? Was there an error message or blank screen, or did it just not show up? I was just guessing that the categories_description table has a field named categories_description; that would probably be the first thing to verify.

21 Sep 2010, 8:32 AM
#8
stood avatar

stood

New Zenner

Join Date:
Sep 2010
Location:
crewe
Posts:
41
Plugin Contributions:
0

Re: Categories in boxes

Nothing showed up :)
Do you think that it would be better to use divs instead of tables? I tryed, but then nothing appeared on the main page. But it is possible, that it was my mistake :D

21 Sep 2010, 11:16 AM
#9
gjh42 avatar

gjh42

Black Belt

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

Re: Categories in boxes

Divs with class or id tags would give you a simple, clean structure, which you could then style in your stylesheet.

I checked in the wiki, and the database table field is correct. It seems that the right information in the right language should be fetched, but apparently somewhere along the line it is being lost.

21 Sep 2010, 4:37 PM
#10
stood avatar

stood

New Zenner

Join Date:
Sep 2010
Location:
crewe
Posts:
41
Plugin Contributions:
0

Re: Categories in boxes

Ok, so I will do it using divs but this time will be more careful :)
Thank you once again :)

21 Sep 2010, 4:58 PM
#11
gjh42 avatar

gjh42

Black Belt

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

Re: Categories in boxes

I didn't examine main_template_vars.php closely enough the first time around. There are four different SQL queries built in nested loops for different situations; two of them yield the correct content depending on category structure.
Starting at line 96 in main_template_vars.php, add
, cd.categories_description
to the select line in two places:```php
$categories_query = "SELECT c.categories_id, cd.categories_name, c.categories_image, c.parent_id, cd.categories_description
FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
WHERE c.parent_id = :parentID
AND c.categories_id = cd.categories_id
AND cd.language_id = :languagesID
AND c.categories_status= '1'
ORDER BY sort_order, cd.categories_name";

    $categories_query = $db->bindVars($categories_query, ':parentID', $category_links[$i], 'integer');
    $categories_query = $db->bindVars($categories_query, ':languagesID', $_SESSION['languages_id'], 'integer');
    break; // we've found the deepest category the customer is in
  }
}

} else {
$categories_query = "SELECT c.categories_id, cd.categories_name, c.categories_image, c.parent_id, cd.categories_description
FROM " . TABLE_CATEGORIES . " c, " . TABLE_CATEGORIES_DESCRIPTION . " cd
WHERE c.parent_id = :parentID
AND c.categories_id = cd.categories_id
AND cd.language_id = :languagesID
AND c.categories_status= '1'
ORDER BY sort_order, cd.categories_name";

$categories_query = $db->bindVars($categories_query, ':parentID', $current_category_id, 'integer');
$categories_query = $db->bindVars($categories_query, ':languagesID', $_SESSION['languages_id'], 'integer');

}
$categories = $db->Execute($categories_query);

The modification to /includes/modules/your_template/category_row.php is the same as above.
26 Oct 2010, 9:39 PM
#12
stood avatar

stood

New Zenner

Join Date:
Sep 2010
Location:
crewe
Posts:
41
Plugin Contributions:
0

Re: Categories in boxes

Sorry for not replying so long, but I had something else to do and in consequence forgot about it. Everything works great, thank you so much :D