Zen Cart Logo
Forums / General Questions / How to access a product variable in tpl_product_info_display

How to access a product variable in tpl_product_info_display

Locked

Views: 1,520

Results 1 to 5 of 5
This thread is locked. New replies are disabled.
16 Apr 2007, 3:20 AM
#1
woodymon avatar

woodymon

Totally Zenned

Join Date:
Sep 2004
Posts:
2,309
Plugin Contributions:
1

How to access a product variable in tpl_product_info_display

I'm attempting to display (echo) a product related variable on tpl_product_info_display.php

<?php echo ('<li>' . $products_name . '</li>') . "\n"; ?>
<?php echo ('<li>' . $products_virtual . '</li>') . "\n"; ?>
<?php echo ('<li>' . $products_quantity . '</li>') . "\n"; ?>

The first and last variables above echo fine but $products_virtual does not.

$products_virtual and $products_quantity exist in the same database table ('products').

So I suspect the $products_virtual variable is not included in the product array available to tpl_product_info_display.php

As I am just a PHP coder wannabe I'm not sure how to proceed.

Any suggestions on how to to pull a specific variable from the 'products' table (e.g. $products_virtual) and make available to product_info_display ?

Woody

16 Apr 2007, 3:59 AM
#2
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: How to access a product variable in tpl_product_info_display

Woody,

Dumb question:

Are you checking this on a product that is virtual??
And as the values are "0" or "1" what are you expecting to have displayed?

From includes/functions/functions_lookups.php

 * look up whether a product is virtual
 */
  function zen_get_products_virtual($lookup) {
    global $db;

    $sql = "select p.products_virtual from " . TABLE_PRODUCTS . " p  where p.products_id='" . (int)$lookup . "'";
    $look_up = $db->Execute($sql);

    if ($look_up->fields['products_virtual'] == '1') {
      return true;
    } else {
      return false;
    }
  }
16 Apr 2007, 5:40 AM
#3
woodymon avatar

woodymon

Totally Zenned

Join Date:
Sep 2004
Posts:
2,309
Plugin Contributions:
1

Re: How to access a product variable in tpl_product_info_display

kobra:

Dumb question:
Are you checking this on a product that is virtual??
And as the values are "0" or "1" what are you expecting to have displayed?
From includes/functions/functions_lookups.php
Hi Jack.

Not a dumb question at all. I'm the one feeling dumb here ;-)

I want to eventually test if product is a virtual product and then print some text to the page stating such.

But my attempts to retrieve the value for products_virtual for the specific product have been unsuccessful (i thought I knew how to do this but my noggin is not working for me today).

At this point I'm just trying to echo the content of products_virtual back to the web page so at least I know I have data to work with.

If it is a 1 or a 0, or a true or false, doesn't matter at this point, I think. I can test on whichever data type (integer or boolean) format it is retrieved in.

The data type for products_virtual in the 'products' table is tinyint(1) .

So I'm uncertain how to employ zen_get_products_virtual function to retrieve the data variable, and then echo it?

I've searched on 'products_virtual' via Developers Toolkit but still don't see how to do this. I'm sure it is such a simple thing.

Thanks for any tips,
Woody

16 Apr 2007, 8:40 AM
#4
kobra avatar

kobra

Black Belt

Join Date:
Aug 2005
Location:
Arizona
Posts:
31,500
Plugin Contributions:
4

Re: How to access a product variable in tpl_product_info_display

Well you are asking the king of hacks(this is not a virtue) but it looks as though virtual is only a lookup and does not add a value to the array for you to echo and as this is used for other valiation checks I would not change it but you might add something that starts with something like this and add your if/else items and pass to the array somehow??

   * check whether a product is virtual
 */
  function zen_get_products_virtual($someVar or $virtual_ID) {
    global $db;

    $virtual_id = zen_get_products_virtual($virtual_id);

    if ($virtual_id = true)  {

(Not responsible for poor syntax)

16 Apr 2007, 9:38 AM
#5
woodymon avatar

woodymon

Totally Zenned

Join Date:
Sep 2004
Posts:
2,309
Plugin Contributions:
1

Re: How to access a product variable in tpl_product_info_display

kobra:

Well you are asking the king of hacks(this is not a virtue) but it looks as though virtual is only a lookup and does not add a value to the array for you to echo and as this is used for other valiation checks I would not change it but you might add something that starts with something like this and add your if/else items and pass to the array somehow??

  • check whether a product is virtual
    */
    function zen_get_products_virtual($someVar or $virtual_ID) {
    global $db;
    $virtual_id = zen_get_products_virtual($virtual_id);
    if ($virtual_id = true) {
> 
> (Not responsible for poor syntax)

Jack,

You might be the king of hacks but I'm the king of nothing on this. Meaning I have no clue where you're leading me, but thanks for trying. If you can point me to a working example I can try and emulate :wink2:

Assuming I have to set-up my own query and pass an array.

To reiterate, I want to be able to make a true or false test/compare directly within the template file, so I need to pass the value of $products_virtual for a specific $product_id, into a variable within the calling statement. Or pass the full associative array and be able to pull out the specific value for the specific product (for which ever product page is displayed at the time).

(I'm no coder so the terms I apply here may be incorrect.)

I've searched through various Zen Cart core fies to locate a similar example but have yet to find anything. I thought it would be such a simple thing.

A related question: How do identify which variables are available on a specific page? In this example, tpl_product_info_display.php

Hope this is making sense.

This is fairly simple stuff and I know I'm making it too complicated. I've searched through php.net and mysql.com docs to no avail. My PHP/MySQL book has lots of examples like this. Of course the only time I've needed the book in the past year, and the darned thing is loaned out. 

Woody