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

Calling additional category as well as main category

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #1  
Old 05-17-2010, 11:52 PM
 
dreg123 dreg123 is offline
 

Member
  
Join Date: Apr 2005
Posts: 13
 

Default Calling additional category as well as main category

I am trying to setup a simple feature where I will be adding a category called "Whats New" and any item added to this category would then display a small "New" icon. It's basicall all working but I can't seem to call up the "additonal category" which would be the "Whats New" category with the {if} statement to determine when the image should be displayed. It only seems to call up the main category. Does anyone know how to call up ANY category the product is in on the products.tpl file? The addiotnal category ID in this case is 384 and it doesn't work.. if I use the main category id it does.. thanks.

{if $product.categoryid eq '384'} place image here (/if}
__________________
eHub - Web Design & Hosting
X-Cart 4.2 / 4.3 / 4.4.X
Reply With Quote
  #2  
Old 05-26-2010, 12:23 PM
 
dreg123 dreg123 is offline
 

Member
  
Join Date: Apr 2005
Posts: 13
 

Default Re: Calling additional category as well as main category

Bump!..

Does anyone know? It would seem rather simple for anyone who has done any work with the categories before? thx
__________________
eHub - Web Design & Hosting
X-Cart 4.2 / 4.3 / 4.4.X
Reply With Quote
  #3  
Old 11-04-2015, 11:31 AM
  McGuireArmyNavy's Avatar 
McGuireArmyNavy McGuireArmyNavy is offline
 

Member
  
Join Date: Oct 2013
Posts: 29
 

Default Re: Calling additional category as well as main category

I know it's been a while, but since this is the thread that showed up while I was searching for this, I will post my solution here.
I'm sure that someone more experienced has a more elegant solution, but here is what I did in 4.6.4
[edited to add] On /product.php, around line 89 [end edit]
after
PHP Code:
if ($cat 0) {
    
$is_product_cat func_query_first_cell("SELECT productid FROM $sql_tbl[products_categories] WHERE productid='$productid' AND categoryid='$cat'");

I added:
PHP Code:
$sec_cat func_query("SELECT categoryid FROM $sql_tbl[products_categories] WHERE productid='$productid' AND main='N'");
$smarty->assign('sec_cat'$sec_cat); 

Then, on the product page (/common_files/customer/main/product.tpl around line 50) i put this
Code:
{foreach from=$sec_cat item=sub} {if $sub.categoryid eq "???"}<p>LOREM IPSUM</p>{/if} {/foreach}
obviously replace ??? with the categoryid you're looking for, and the LOREM IPSUM paragraph with whatever you want to show on the page.
__________________
X-Cart Gold 4.6.4
www.mcguirearmynavy.com
Reply With Quote
  #4  
Old 11-04-2015, 12:10 PM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default Re: Calling additional category as well as main category

I haven't tested this but should point you in the right direction for a bit more elegant solution.

Open include/func/func.product.php

FIND:

Code:
$product['categoryid'] = $categoryid;

AFTER ADD:

Code:
// SD - Check if product is in new category $product['is_new'] = (func_query_first_cell("SELECT categoryid FROM $sql_tbl[products_categories] WHERE productid='" . intval($product['productid']) . "' AND categoryid='384'") > 0 ? 'Y' : 'N'); // / SD - Check if product is in new category

Open include/search.php

FIND:

Code:
$products[$k]['taxed_price'] = $v['taxed_price'] = $v['price'];

AFTER ADD:

Code:
// SD - Check if product is in new category $products[$k]['is_new'] = (func_query_first_cell("SELECT categoryid FROM $sql_tbl[products_categories] WHERE productid='" . intval($v['productid']) . "' AND categoryid='384'") > 0 ? 'Y' : 'N'); // / SD - Check if product is in new category

Then in your templates on your product listings or your product details page you can use:

Code:
{if $product.is_new eq 'Y'}Show Icon{/if}
Reply With Quote
  #5  
Old 11-04-2015, 12:22 PM
  McGuireArmyNavy's Avatar 
McGuireArmyNavy McGuireArmyNavy is offline
 

Member
  
Join Date: Oct 2013
Posts: 29
 

Default Re: Calling additional category as well as main category

Thank you.

The only problem that i see, right off the bat, is that this would need to be adjusted for each specific category that I want to flag for. Unless I'm reading it wrong
__________________
X-Cart Gold 4.6.4
www.mcguirearmynavy.com
Reply With Quote
  #6  
Old 11-04-2015, 12:32 PM
  Jon's Avatar 
Jon Jon is offline
 

X-Guru
  
Join Date: Oct 2002
Location: Vancouver, Canada
Posts: 4,200
 

Default Re: Calling additional category as well as main category

I used category 384 as that was the category the first poster used.

You could change:

Code:
categoryid='384'

To:

Code:
categoryid IN ('X','Y','Z')

And update X, Y and Z with your categoryids if you have more.

If you wanted to have a dynamic admin where you could toggle categories off and on as new, I would create a new `is_new` category field in the database (you'd have to update the category add/modify pages as well) and then do a LEFT JOIN on the categories table like so.

Code:
$products[$k]['is_new'] = func_query_first_cell("SELECT pc.categoryid FROM $sql_tbl[products_categories] pc LEFT JOIN $sql_tbl[categories] c ON pc.categoryid=c.categoryid WHERE pc.productid='" . intval($v['productid']) . "' AND c.is_new='Y'") > 0 ? 'Y' : 'N');

Then you could toggle categories off and on in the database.

Or another way, if your new category names were the only ones that started with the word "New" you could do something like:

Code:
$products[$k]['is_new'] = func_query_first_cell("SELECT pc.categoryid FROM $sql_tbl[products_categories] pc LEFT JOIN $sql_tbl[categories] c ON pc.categoryid=c.categoryid WHERE pc.productid='" . intval($v['productid']) . "' AND c.category LIKE 'New %'") > 0 ? 'Y' : 'N');

Jon
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



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 09:59 AM.

   

 
X-Cart forums © 2001-2020