Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2008
    Posts
    3
    Plugin Contributions
    0

    help question Trying to write function to return a products textual tax class... help!

    Hi everyone. This is my first post at this forum, so, hi! I'm a systems admin by trade and in no way a PHP guy, but I've been muddling through Zencart long enough to know roughly what's going on.

    In essence, I have a client that wants to display the text of a products tax class (eg San Francisco, CA) in the body of a particular product type. I've already got the product type setup and working, but I just can't figure out how to display the text of the tax class instead of the numeric value that's stored in the products table.

    I tried creating a new function using the categories lookup function as a model, but I can't actually get the function to return data (probably because I have no real idea what I am doing. ;) I suspect this is the sort of thing a real PHP programmer could hack out in a couple minutes, so I thought I would post here and see what y'all thought.

    ### Here is my busted fuction that is probably not useful for anything:

    <? php
    /*
    * Looks up a products tax class text description based on tax_class_id and return as $products_location.
    * Added to enable product location functionality.
    * TABLES: tax_class
    */

    function zen_get_products_location($tax_class_id) {
    global $db;

    $the_products_location_query = "select tax_class_id from " . TABLE_TAX_CLASS . " where tax_class_id = '" . (int)$tax_class_id . "'" . " order by tax_class_id";
    $the_products_location = $db->Execute($the_products_location_query);

    return $the_products_location->fields['tax_class_id'];
    }
    ?>

  2. #2
    Join Date
    Oct 2004
    Location
    Ontario
    Posts
    116
    Plugin Contributions
    1

    Default Re: Trying to write function to return a products textual tax class... help!

    Close, you are returning the wrong field. I believe you are looking for the tax_class_title field.

    Code:
    /*
    * Looks up a products tax class text description based on tax_class_id and return as $products_location.
    * Added to enable product location functionality.
    * TABLES: tax_class
    */
    
    function zen_get_products_location($tax_class_id) {
        global $db;
    
        $the_products_location_query = "select tax_class_title from " . TABLE_TAX_CLASS . " where tax_class_id = '" . (int)$tax_class_id . "'";
        $the_products_location =  $db->Execute($the_products_location_query);
    
        return $the_products_location->fields['tax_class_title'];
    }

  3. #3
    Join Date
    Dec 2008
    Posts
    3
    Plugin Contributions
    0

    Default Re: Trying to write function to return a products textual tax class... help!

    Awesome! Now for the real question: where do I put that function? I tried putting it in a properly formatted PHP file in 'functions\extra_functions' but it caused the site to start throwing errors on every page load. I suppose I can put it at the bottom of functions_general.php or something, but that doesn't seem like the right solution.

  4. #4
    Join Date
    Oct 2004
    Location
    Ontario
    Posts
    116
    Plugin Contributions
    1

    Default Re: Trying to write function to return a products textual tax class... help!

    Either solution should work. If you put in an extra_functions file.. just ensure you put <?php at the top. (The ?> at the bottom is optional).

  5. #5
    Join Date
    Dec 2008
    Posts
    3
    Plugin Contributions
    0

    Default Re: Trying to write function to return a products textual tax class... help!

    Hmm, still no go. The function doesn't seem to return any value. Here is the function as it stands:

    Code:
    /* 
     * Looks up a products tax class text description based on tax_class_id and return as $products_location.
     * Added to enable product location functionality.
     * TABLES: tax_class
     */
    
      function zen_get_products_location($tax_class_id) {
        global $db;
    
        $the_products_location_query = "select tax_class_id from " . TABLE_TAX_CLASS . " where tax_class_id = '" . (int)$tax_class_id . "'" . " order by tax_class_id";
        $the_products_location = $db->Execute($the_products_location_query);
    
        return $the_products_location->fields['tax_class_title'];
      }
    And here is the relevant section of my main_template_vars.php:

    Code:
      //Added to enable lot location display:
     
     $products_location = zen_get_products_location('products_tax_class_id');
    Does that look about right to you? *confused*

 

 

Similar Threads

  1. help to write function to return qty prices
    By bn17311 in forum General Questions
    Replies: 3
    Last Post: 14 May 2012, 06:04 PM
  2. Replies: 6
    Last Post: 23 Sep 2011, 08:12 AM
  3. which function or class return the final price of a product?
    By weber in forum Templates, Stylesheets, Page Layout
    Replies: 2
    Last Post: 24 Mar 2011, 11:58 PM
  4. PLEASE HELP...Quickest way to change tax class for ALL products already entered
    By tclayla in forum Currencies & Sales Taxes, VAT, GST, etc.
    Replies: 5
    Last Post: 8 Dec 2008, 05:03 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