i was looking a long time for a possibility to show the category of a product on the featured product page or in the search results. while there are some solutions around, they are all for older versions of x-cart. this mod works with 4.0.11 and is multilanguage-capable:
add the following code to '/include/func.php':
Code:
### START pwx addition, 050211
#
# function to get the categories to a product
#
function func_get_categories($products) {
global $sql_tbl, $shop_language;
$f_categories = array();
foreach ($products as $k => $v) {
$productid=$products[$k]["productid"];
$cat = func_query_first ("SELECT $sql_tbl[categories].categoryid, $sql_tbl[categories].category
FROM $sql_tbl[products]
LEFT JOIN $sql_tbl[products_categories] ON $sql_tbl[products].productid = $sql_tbl[products_categories].productid
LEFT JOIN $sql_tbl[categories] ON $sql_tbl[products_categories].categoryid = $sql_tbl[categories].categoryid
WHERE $sql_tbl[products_categories].main = 'Y'
AND $sql_tbl[products].productid=".$productid);
#
# Get the international category name and description
#
$int_res = func_query_first("SELECT * FROM $sql_tbl[categories_lng] WHERE code='$shop_language' AND categoryid='$cat[categoryid]'");
if (!empty($int_res["category"])) {
$cat["category"] = $int_res["category"];
}
$f_categories[$productid] = $cat;
}
return $f_categories;
}
### END pwx addition, 050211
then add the following code to 'featured_products.php' after the following line (probably line 69):
Code:
$smarty->clear_assign("products");
### START pwx addition, 050211
$f_categories = func_get_categories($products);
$smarty->assign("f_products_categories", $f_categories);
### END pwx addition, 050211
add the same code to the file '/include/search.php' before the $products variable is assigned to $smarty.
then you can modify your template file '/customer/main/products_t.tpl'. add the variable at the place where you would like to show the category of the current product. it must be in the correct {section} tag:
Code:
{section name=product loop=$products}
[...]
{assign var="f_productid" value=$products[product].productid}
{$f_products_categories[$f_productid].category|escape}
[...]
{/section}
hope this helps...
regards, lukas.