Zen Cart Logo
Forums / General Questions / Trying to write function to return a products textual tax class... help!

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

Locked

Views: 997

Results 1 to 5 of 5
This thread is locked. New replies are disabled.
17 Dec 2008, 5:44 PM
#1
egovektor avatar

egovektor

New Zenner

Join Date:
Dec 2008
Posts:
3
Plugin Contributions:
0

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']; } ?>
17 Dec 2008, 8:19 PM
#2
flipside avatar

flipside

Zen Follower

Join Date:
Oct 2004
Location:
Ontario
Posts:
114
Plugin Contributions:
0

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.

/*
* 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'];
}
17 Dec 2008, 9:33 PM
#3
egovektor avatar

egovektor

New Zenner

Join Date:
Dec 2008
Posts:
3
Plugin Contributions:
0

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.

17 Dec 2008, 9:39 PM
#4
flipside avatar

flipside

Zen Follower

Join Date:
Oct 2004
Location:
Ontario
Posts:
114
Plugin Contributions:
0

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).

17 Dec 2008, 9:47 PM
#5
egovektor avatar

egovektor

New Zenner

Join Date:
Dec 2008
Posts:
3
Plugin Contributions:
0

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:

/* 
 * 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:

  //Added to enable lot location display:
 
 $products_location = zen_get_products_location('products_tax_class_id');

Does that look about right to you? confused