Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Setting up category header graphic...


Guest

Recommended Posts

Ok, I keep playing around :P

 

I'm starting work on my product_info page. Don't mind anything below the header right now please.

 

What I'm trying to do is have the graphic for the main category "Balls" in the header area. I thought I'd found the correct code for this:

 

<?php echo tep_image(DIR_WS_IMAGES . $category['categories_image'], $category['categories_name'], HEADING_IMAGE_WIDTH, HEADING_IMAGE_HEIGHT); ?>

 

But all I'm getting is a blank image.

 

Any idea what I'm doing wrong? Did I grab the wrong code? Not enough of the code? I'm a total PHP newbie I'm afraid, and just as much a newbie to OSCommerce too. But I'm trying, and I learn pretty quickly :D

 

Laura

Link to comment
Share on other sites

When you are on the product_info.php there is no definition for the variables you are using.

 

While they work on default.php they are not passed over to product_info.php

 

You could make a handy dandy function to get the image and name for the product's category and image.

 

I think I made one of those for one of my add-ons ... but I would have to hunt it down.

 

So, make a function for getting a product's categories name and one to grab the image then call those when you need them on this or any other page.

Link to comment
Share on other sites

Thanks! Sounds great...but, I haven't the foggiest clue as to how to write a function! I'm a total newbie to both PHP & OSC.

 

If you can find the one you did, I would be awfully appreciative of getting my hands on it ;-)

Link to comment
Share on other sites

Okay ... let's have some fun ... :D

 

Create a new file /catalog/includes/functions/categories_lookup.php and insert this code into it:

<?php

/*

 Categories Functions

*/



////

// Return a product's catagory

// TABLES: products_to_catagories

 function tep_get_products_catagory_id($products_id) {

   global $languages_id;



   $the_products_catagory_query = tep_db_query("select products_id, categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $products_id . "'" . " order by products_id,categories_id");

   $the_products_catagory = tep_db_fetch_array($the_products_catagory_query);



   return $the_products_catagory['categories_id'];

 }



////

// WebMakers.com Added: Find a Categories Name

// TABLES: categories_description

 function tep_get_categories_name($who_am_i) {

   global $languages_id;

   $the_categories_name_query= tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id= '" . $who_am_i . "' and language_id= '" . $languages_id . "'");



   $the_categories_name = tep_db_fetch_array($the_categories_name_query);

   return $the_categories_name['categories_name'];

 }





////

// WebMakers.com Added: Find a Categories image

// TABLES: categories_image

 function tep_get_categories_image($what_am_i) {

   $the_categories_image_query= tep_db_query("select categories_image from " . TABLE_CATEGORIES . " where categories_id= '" . $what_am_i . "'");



   $the_categories_image = tep_db_fetch_array($the_categories_image_query);

   return $the_categories_image['categories_image'];

 }

?>

 

Edit the file /incldues/functions/general.php and at the very bottom, just before the ?> add this line:

require(DIR_WS_FUNCTIONS . 'categories_lookup.php');

 

Edit your product_info.php file and insert this row somewhere. You will have to modify this to suit your needs:

          <tr>

         <td colspan="2" class="main"><?php echo tep_image(DIR_WS_IMAGES . tep_get_categories_image(tep_get_products_catagory_id($product_info_values['products_id']))) . '<br>' . tep_get_categories_name(tep_get_products_catagory_id($product_info_values['products_id'])); ?></td>

         </tr>

 

You now have the categories_name and categories_image where ever you want to put it using these functions ...

 

Simple, eh? :shock:

Link to comment
Share on other sites

Looks like it wants to work. I've tried putting it in my (newly created) header2.pcgi, as well as in my product_info.pcgi. I've uploaded all the relavent files, but I'm getting a broken image. I know I've assigned an image to the main category - Balls - but it's just not showing up.

 

Any thoughts?

 

http://www.bowlzilla.com/catalog/catalog/p...?products_id=28

(don't mind the rest of the page right now. I'm still trying to get the top portion formatted right and then I'll move on down the page).

 

Laura

Link to comment
Share on other sites

That's odd. I just moved the code around a bit on the product_info file, and it shows up now. I just wish I could get it to work on the header page. Is that not going to be possible? I'm presuming that the product_info page has code on it that helps to tell what the category is in the first place, which the header file does not.

 

Well, it's progress. I'll keep playing around.

 

THANKS!!!

 

Laura

Link to comment
Share on other sites

On further playing around...it seems that it'll only work within the body_text area? If I put it anywhere else on the page it just comes up as a broken image. Does that make any sense?

 

I've tried copying the table the code appears in from the body_text area into the header area of the product_info file, and still get the same effect - broken image, no text.

 

Puzzled,

Laura

Link to comment
Share on other sites

You are passing the products_id to the function.

 

This means if using a products_id via a select statement, the select statement has to happen before using it.

 

The header.php happens before the product_info.php and where the select statement is made.

 

Basically, that means you are passing nothing to the function so it returns nothing. :shock:

 

You can use this code/function anywhere you like, but you have to pass it a valid products_id for it to work.

Link to comment
Share on other sites

So in other words, unless I call the product ID from the header (seems like a silly thing to do, eh?), then I can't have this image called in that area. Is that right?

 

Remembering that I'm just a newbie who doesn't mind getting her hands dirty and digging around in the code but might not actually understand much of it, do you have any suggestions or existing mods that I might be able to use for this? Can I simply call the product id earlier in the body of the product_info page?

 

Thanks TONS! Linda, you're amazing!

 

Laura

Link to comment
Share on other sites

Basically, you need to know what products_id you are looking at.

 

If the products_id is defined after the header.php then it won't work by referring to something defined after the header.

 

What I did was add that statement right after the if statement of the define. Go to the end of the IF statement that reads:

 

  if (!tep_db_num_rows($product_info)) { // product not found in database

 

Then add:

      <tr>

       <td><table border="0" width="100%" cellspacing="0" cellpadding="2">

<?php /* BOF: WebMakers.com Added: Show Category and Image */ ?>

         <tr><td colspan="2"><table align="right">

           <tr>

             <td class="main" align="center"><?php echo tep_image(DIR_WS_IMAGES . tep_get_categories_image(tep_get_products_catagory_id($product_info_values['products_id']))); ?></td>

           </tr>

           <tr>

             <td class="main" align="center"><?php echo tep_get_categories_name(tep_get_products_catagory_id($product_info_values['products_id'])); ?></td>

           </tr>

         </table></td></tr>

<?php /* EOF: WebMakers.com Added: Show Category and Image */ ?>



         <tr height="40">

           <td class="pageHeading"><?php echo $product_info_values['products_name']; ?></td>

           <td align="right" class="pageHeading"><?php echo $products_price; ?></td>

         </tr>

 

This puts it on the right side of the product_info.php

 

Peek at this over at:

 

http://www.thewebmakerscorner.com/snap_attributes

 

I think the only catagory in there without an image is the Extra category. But try the others and you will see it.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...