Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Adding IF statement to $lc_text ???


fat_dog

Recommended Posts

Hi,

 

I'm trying to get the code below (from modules/product_listing.php) to change the colour of the background of the table depending on if the product is in stock, or out of stock. For instance, green for in stock, and it turns the background red if out of stock.

 

Original Code:

if (isset($HTTP_GET_VARS['manufacturers_id'])) {
				$lc_text = '<table width="95%" height="50"><tr><td class="productinfo" align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';

 

The code I want I presume is something like:

if (isset($HTTP_GET_VARS['manufacturers_id'])) {
				$lc_text = '<table width="95%" height="50"><tr><td ' . if ((tep_get_products_stock($product_info['products_id']) < 1)) {
		 echo 'bgcolor="red">';
		} else {
		  echo 'bgcolor="green"';
		} . ' align="center"><a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'manufacturers_id=' . $HTTP_GET_VARS['manufacturers_id'] . '&products_id=' . $listing['products_id']) . '">' . $listing['products_name'] . '</a>';

 

I think $lc_text can't handle the if statement in the middle of it, but what is the workaround? Can anyone help me on this please?

Link to comment
Share on other sites

It's not that straight-forward - the code is actually put together in /includes/classes/boxes.php.

 

You can use concatenation over several lines like this:

$var = 'text';

if (something) {

$var .= 'more text';

} else {

$var .= 'different text';

}

$var .= 'rest of my text';

 

to do what you want though you'd really need to look into rewriting the boxes.php code. Might be easier to add a new column with a green tick / red cross depending on status?

 

all the best, Terra

My code for combining PayPal IPN with ** QTPro 4.25 ** osC Affiliate ** CCGV(trad)

and how to solve the invoice already paid error

General info: Allow customer to delete order comment ** FTP Programs & Text Editors ** Amending order email **

Link to comment
Share on other sites

thanks for your reply. i'm sure its me being stupid, but I've tried your code in case 'PRODUCT_LIST_NAME': and it just doesn't display - no error, but nothing changes either.

 

would it be possible for you to put the if statement together for me as an example so that when I come to mod the product info page it displays? I'm not experienced at php, I just get by :blink:

Link to comment
Share on other sites

  • 2 weeks later...

Try something like this:

 

Just before:

 

$list_box_contents[$cur_row][] = array('align' => $lc_align,
										   'params' => 'class="productListing-data"',
										   'text'  => $lc_text);

 

 

add:

 

if (tep_get_products_stock($product_info['products_id']) < 1) {
$params = 'class ="myClass"';
} else {
$params = 'class="productListing-data"';
}

 

then change the above to:

 

$list_box_contents[$cur_row][] = array('align' => $lc_align,
										   'params' => $params,
										   'text'  => $lc_text);

 

 

Then add an appropriate 'myClass' to your stylesheet :)

 

Matti

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...