Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Get Parent_id


nevmic

Recommended Posts

Posted

I would like that a banner on top of the shop (within header) changes according to category as follows:

1) If it is within any other page then I have a default banner.

2) If it is within a category I want to show the banner associated with that category (same image uploaded from admin).

3) If it is within a subcategory I want to still show the banner associated with that category.

4) If it is within a product page I want to still show the banner associated with that category.

 

1) OK

2) OK

 

Code used:

 

 if ($category_depth == 'nested') {
$category_query = tep_db_query("select c.categories_image from " . TABLE_CATEGORIES . " c  where c.categories_id = '" . (int)$current_category_id . "'");
$category = tep_db_fetch_array($category_query);

echo tep_image(DIR_WS_IMAGES . $category['categories_image'], "ALT", 768, 130);

 

3)

I need to extract the parent_id from the subcategory for this to work but I cannot manage:

 

elseif ($category_depth == 'products') {
$category_query = tep_db_query("select c.product_id, c.categories_image from " . TABLE_CATEGORIES . " c  where c.categories_id = '" . (int)product_id . "'");
}

 

4) no idea so far

 

I would appreciate some help to solve points 3 & 4

 

Thanks

Posted

I solved this issue with my limited php/mysql. I am sure there is a cleaner way to do it... but in the meantime it works fine. If you have any suggextions, please let me know.

 

	//if within a category
 if ($category_depth == 'nested') {
$category_query = tep_db_query("select c.categories_image from " . TABLE_CATEGORIES . " c  where c.categories_id = '" . (int)$current_category_id . "'");
$category = tep_db_fetch_array($category_query);

echo tep_image(DIR_WS_IMAGES . $category['categories_image'], STORE_NAME, 768, 130);

// if within subcategory
} elseif ($category_depth == 'products') {
$parent_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . (int)$current_category_id . "'");
$parent = tep_db_fetch_array($parent_query);	
$category_query = tep_db_query("select c.categories_image from " . TABLE_CATEGORIES . " c  where c.categories_id = '" . $parent['parent_id'] . "'");
$category = tep_db_fetch_array($category_query);

echo tep_image(DIR_WS_IMAGES . $category['categories_image'], STORE_NAME, 768, 130);

// if within product page
} elseif ($_GET['pID']){
$cat_query = tep_db_query("select categories_id from " . TABLE_PRODUCTS_TO_CATEGORIES . " where products_id = '" . $_GET['pID'] . "'");
$cat = tep_db_fetch_array($cat_query);	


$parent_query = tep_db_query("select parent_id from " . TABLE_CATEGORIES . " where categories_id = '" . $cat['categories_id'] . "'");
$parent = tep_db_fetch_array($parent_query);	


$category_query = tep_db_query("select c.categories_image from " . TABLE_CATEGORIES . " c  where c.categories_id = '" . $parent['parent_id'] . "'");
$category = tep_db_fetch_array($category_query);

echo tep_image(DIR_WS_IMAGES . $category['categories_image'], STORE_NAME, 768, 130);

} else {
//whatever
}

 

Thanks

Posted
Probably using the in-built function tep_get_parent_categories is better than writing new code.

 

Jack

 

Interesting! I found the function but did not find 1 simple example on how to use it.

 

Tried this

 

	echo tep_get_parent_categories($category, (int)$current_category_id);

 

with no luck! I am not sure what to place instead of $category.

 

Thanks!

Posted
The first argument is an empty array. See tep_get_product_path in the same file for an example.

 

Jack

 

Thanks for your help but I do not understand. I cannot even understand what the function is returning.... or I blieve it just returns 'true' when it finds the parent category.

 

I just want to get this 'categories_image' of the category (not sub-category) and have no idea how to use that function to find it!

Archived

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

×
×
  • Create New...