Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

showing the category in the featured product/search result

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions
 
Thread Tools Search this Thread
  #1  
Old 02-11-2005, 07:11 AM
 
lrueegg lrueegg is offline
 

Newbie
  
Join Date: Jan 2005
Location: Zurich, Switzerland
Posts: 8
 

Default 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.
__________________
--
xcart gold v4.0.11 [LAMP]
Reply With Quote
  #2  
Old 02-21-2005, 04:30 PM
 
cyberdriveway cyberdriveway is offline
 

Advanced Member
  
Join Date: Aug 2004
Location: California
Posts: 32
 

Default

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));
__________________
Tyson McPherson
X-Cart version 4.1.8
PHP 4.3.9
MySQL server 4.1.12-log
MySQL client 4.1.12
Web server Apache/2.0.52 (Red Hat)
Operation system Red Hat 3.4.6-2
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 02:44 AM.

   

 
X-Cart forums © 2001-2020