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)
-   -   Link to parent/root cat (https://forum.x-cart.com/showthread.php?t=51908)

balinor 01-21-2010 03:39 PM

Link to parent/root cat
 
Hey guys, I know I've seen this somewhere before, but I can't find it, and can't remember how I did this. I have a couple of clients that need links directly to a products root category, and a sub-categories parent category. Any idea what the context would be for this? I tried playing with the location variable with no success. Thanks!

Jon 01-22-2010 08:46 AM

Re: Link to parent/root cat
 
To link to a products root category based on the location variable you can...

Open product.php

FIND:

Code:

$smarty->assign("product",$product_info);

BEFORE ADD:

Code:

// WCM - Assign Root Category
$product_info['root_category'] = $location[1][0];
$product_info['root_category_link'] = $location[1][1];
// / WCM - Assign Root Category


In skin1/customer/main/product.tpl use:

Code:

{if $product.root_category_link}
<strong>Root Category:</strong> <a href="{$product.root_category_link}" title="{$product.root_category}">{$product.root_category}</a>
{/if}


balinor 01-22-2010 08:50 AM

Re: Link to parent/root cat
 
Sweet - that looks like it will work exactly the way I want! Thanks Jon! Any ideas on the parent cat for a sub-cat?

Jon 01-22-2010 09:10 AM

Re: Link to parent/root cat
 
To show the parent of a subcategory:

Open home.php

FIND:

Code:

require $xcart_dir."/include/categories.php";


AFTER ADD:

Code:

// WCM - Get Parent Cat (customization)
$wcmParentCat = func_query_first("SELECT categoryid,category FROM $sql_tbl[categories] WHERE categoryid='" . (int)$current_category['parentid'] . "'");
$current_category['parent_categoryid'] = $wcmParentCat['categoryid'];
$current_category['parent_category'] = $wcmParentCat['category'];
$smarty->assign('current_category',$current_category);
// WCM - Get Parent Cat (customization)



In your template use:

Code:

{if $current_category.parent_categoryid gt 0}
    The parent category for this is: <a href="home.php?cat={$current_category.parent_categoryid}">{$current_category.parent_category}</a>.
{/if}


balinor 01-22-2010 10:10 AM

Re: Link to parent/root cat
 
Beautiful! Thanks a million Jon. Only tweak necessary was to change this:

<a href="home.php?cat={$current_category.parent_categ ory}">

to this:

<a href="home.php?cat={$current_category.parent_categ oryid}">

Going to put this in the Custom Mods forum. FYI, this was tested on a 4.1.12 install.

Jon 01-22-2010 10:14 AM

Re: Link to parent/root cat
 
Oops - thanks I've updated the instructions.

It will work on all versions 4.0-4.3. Versions prior to that didn't use the categoryid_path.

dgallek 02-16-2010 11:26 AM

Re: Link to parent/root cat
 
is there anyway to see this in action? I'm not sure I follow the description of the functionality and it sounds like something one of my clients want.

I'm using X-Cart 4.3

balinor 02-16-2010 03:59 PM

Re: Link to parent/root cat
 
It is just a simple link that links the user back to the product's root category.

chrischall 08-03-2010 07:13 AM

Re: Link to parent/root cat
 
Hi Jon,

Im using 4.0.14 and the root category mod worked great thanks! However just tried the parent category part and that doesnt seem to show up - is there different coding for this version?

Cheers,
Chris

jvolvovski 12-01-2010 08:46 AM

Re: Link to parent/root cat
 
I'm trying to check for a parent category in product.tpl in version 4.4.1

Any idea how I would do that?
None of the code above seems to match with the new version of x-cart.

Thanks!
Jenny


All times are GMT -8. The time now is 04:46 PM.

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