Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How to get the parent category name for a product


Fireflight

Recommended Posts

I'm trying to implement e-commerce tracking for Google Analytics and ran into this problem. Luckily I discovered that OSC already has a function to get the category ID from a product id. From there it was a fairly simple process, so I just thought I'd share my solution.

 

This is my production code, so please modify it to your needs.

 

$ga_category_id = tep_get_product_path($order->products[$i]['id']);
$ga_category_query = tep_db_query("select categories_name from " . TABLE_CATEGORIES_DESCRIPTION . " where categories_id = '" . $ga_category_id . "'");
$ga_category = tep_db_fetch_array($ga_category_query);
echo '<input name="ga_category[' . $i .'][category]" type="hidden" value="' . $ga_category[categories_name] . '"  />';

 

Replace $order->products[$i]['id'] with whatever variable contains your products id. $ga_category[categories_name] is what actually outputs the name of the category.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...