X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (https://forum.x-cart.com/forumdisplay.php?f=20)
-   -   showing the category in the featured product/search result (https://forum.x-cart.com/showthread.php?t=12111)

lrueegg 02-11-2005 07:11 AM

showing the category in the featured product/search result
 
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.

cyberdriveway 02-21-2005 04:30 PM

Thanks for posting. I added code as suggested. Everything worked as stated with one exception.


Quote:

then add the following code to 'featured_products.php' after the following line (probably line 69):
I did remove the code from "featured_products.php" since it appears to be redunent, and casued an error.



Quote:

add the same code to the file '/include/search.php' before the $products variable is assigned to $smarty.
This worked best when placed around line 595 of the '/include/search.php' file. See below:

Code:

                        if (!empty($active_modules["Special_Offers"]) && empty($search_data["products"]["show_special_prices"])) {
                                func_offers_check_products($login, $current_area, $products);
                        }
                ### START pwx addition, 050211
                $f_categories = func_get_categories($products);
                $smarty->assign("f_products_categories", $f_categories);
                ### END pwx addition, 050211

                }
               

                # Assign the Smarty variables
                $smarty->assign("navigation_script","search.php?mode=search");
                $smarty->assign("products", $products);
                $smarty->assign("first_item", $first_page+1);
                $smarty->assign("last_item", min($first_page+$objects_per_page, $total_items));



All times are GMT -8. The time now is 03:06 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.