Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2006
    Posts
    25
    Plugin Contributions
    0

    Default Finding out what top level category a product belongs to?

    Hi,

    Is there a variable or a way to return the value of what the top level category that a product belongs to?

    I need to vary output depending on what main (top level) category a product belongs to.

    Many thanks in advance!

  2. #2
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Finding out what top level category a product belongs to?

    $cPath holds the path that was taken to get to the product, in the form 12_34_etc, 12 being the top category ID and 34 being the subcat if there is one (or more).

    You can use the PHP function ereg to test for the first number having a certain value or values, though it doesn't output the number, just true or false. Here's a sample of how I used it:
    PHP Code:
    if (ereg("(^1$|^1_)",$cPath)) //wedding or sub  
      
    {
        echo 
    "<img src='../fr-136/images/frheadwed.gif' alt='The Wedding and Betrothal Collection'>";
      }
      elseif (
    ereg("(^2$|^2_)",$cPath)) //celtic or sub
    ... 

  3. #3
    Join Date
    Nov 2006
    Posts
    25
    Plugin Contributions
    0

    Default Re: Finding out what top level category a product belongs to?

    Great!

    I assume that this is global and can be used throughout any of the includes. I'll check it out and give it a try.

    Many thanks!

  4. #4
    Join Date
    Nov 2006
    Posts
    25
    Plugin Contributions
    0

    Default Re: Finding out what top level category a product belongs to?

    Hi,

    That didn't work.

    It only works when there is the cPath value available in the url however when I go into the shopping cart for example. The value is no longer available to access and hence use for running conditional statements.

    :-(

  5. #5
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: Finding out what top level category a product belongs to?

    If you think about it, the shopping cart page for example can't belong to an individual product or category. What if there are two products in the cart? What if you get to the shopping cart page from the main page or the shipping & returns page?

    Perhaps what you need to do is grab the category id on each product page and save it in a global tracking variable if it is non-null, so a non-product page can "remember" what the last product category was.

 

 

Similar Threads

  1. v151 Remove product from Top Level Category
    By anjordan77 in forum Setting Up Categories, Products, Attributes
    Replies: 6
    Last Post: 5 Mar 2013, 09:18 PM
  2. Show product on top level category
    By Ivanna in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 10 Sep 2011, 12:53 AM
  3. I can't figure out how to move products from the top level category
    By pmarble in forum Setting Up Categories, Products, Attributes
    Replies: 9
    Last Post: 9 Dec 2009, 09:36 AM
  4. Best practice for finding out 'what does what'?
    By budfox in forum General Questions
    Replies: 6
    Last Post: 19 Aug 2007, 07:05 PM
  5. Replies: 3
    Last Post: 5 Jul 2007, 06:20 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR