Results 1 to 6 of 6

Hybrid View

  1. #1
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,371
    Plugin Contributions
    23

    Default Get parent id function

    I'm having to edit someone else's code. He's used $current_category_id to create if statements but what I also need is a function to use in case all subcategories fall under the same top category - ie the parent category.

    So instead of this:
    Code:
    elseif($current_category_id == 104 || $current_category_id == 29 || $current_category_id == 41 || $current_category_id == 43 || $current_category_id == 47 || $current_category_id == 49)
    it would something like this
    Code:
    elseif($parent_category_id == 1 )
    I don't think any of the category functions can be used for this (but could be wrong) so writing a new function would be in order.

    Wanted to make sure there wasn't something already usable in zen cart before I do something new.
    The full-time Zen Cart Guru. WizTech4ZC.com
    New template for 2.0 viewable here: 2.0 Demo

  2. #2
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Get parent id function

    How deep are your Categories?

    Top Cat 1
    -sub Cat1
    -sub Cat2

    Or do they go ...
    Top Cat 1
    -sub Cat1
    --subsub CatA
    --subcat CatB
    -sub Cat2
    --subsub CatA
    --subsub CatB
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  3. #3
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,371
    Plugin Contributions
    23

    Default Re: Get parent id function

    just one level of subs right now
    The full-time Zen Cart Guru. WizTech4ZC.com
    New template for 2.0 viewable here: 2.0 Demo

  4. #4
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Get parent id function

    You could build a function to get the parent_id by adding to a file in the:
    /includes/functions/extra_functions/my_extra_functions.php

    Code:
    <?php
    
    //// look up parent_id
      function zen_get_categories_parent_id($categories_id) {
        global $db;
    
        $lookup_query = "select parent_id from " . TABLE_CATEGORIES . " where categories_id='" . (int)$categories_id . "'";
        $lookup = $db->Execute($lookup_query);
    
        return $lookup->fields['parent_id'];
      }
    Or if you already have a functions file in there for your customizations, just add that function to the bottom of it ...

    Now, sent the categories_id you need to look up the parent_id for and it will return it ...

    NOTE: if you go more than 1 level of Categories, you will need something more robust to dig up the cat tree ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

  5. #5
    Join Date
    May 2006
    Location
    Gardiner, Maine
    Posts
    2,371
    Plugin Contributions
    23

    Default Re: Get parent id function

    great, that'll do for now.

    Thank you Linda!
    The full-time Zen Cart Guru. WizTech4ZC.com
    New template for 2.0 viewable here: 2.0 Demo

  6. #6
    Join Date
    Sep 2003
    Location
    Ohio
    Posts
    69,402
    Plugin Contributions
    6

    Default Re: Get parent id function

    You are most welcome ...
    Linda McGrath
    If you have to think ... you haven't been zenned ...

    Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!

    Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
    Officially PayPal-Certified! Just click here

    Try our Zen Cart Recommended Services - Hosting, Payment and more ...
    Signup for our Announcements Forums to stay up to date on important changes and updates!

 

 

Similar Threads

  1. How to get content below subcategory listings on a parent category page
    By stoneroses6300 in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 24 Jan 2013, 12:24 AM
  2. v150 how to get the subcategories linkage or ID by built in function?
    By loafer in forum General Questions
    Replies: 3
    Last Post: 21 May 2012, 06:28 AM
  3. function to get cPath by passing the products_id?
    By rajoo.sharma in forum General Questions
    Replies: 2
    Last Post: 14 Aug 2009, 07:09 AM
  4. Get category parent ID
    By karl19 in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 5 May 2008, 08:56 AM
  5. function to get the total weight?
    By bangsters in forum General Questions
    Replies: 2
    Last Post: 8 Nov 2007, 02:12 PM

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