Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

out of stock on orders.php


lifeisboost

Recommended Posts

Posted

basically i have everything working but on the orders page

 

 

I have a new field that captures the products stock status on checkout and places it in the orders products table. the problem is on the orders page.

 

here is the code i have

    for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {


if ($order->products[$i]['stock'] < 1 ) {
 	$OutStock = 'OUT OF STOCK';

}

          '            <td class="dataTableContent" valign="top">'$OutStock . '  ' . $order->products[$i]['name'];

 

 

 

 

if i echo out $order->products[$i]['stock'] it prints the stock of each product int he order, the problem is that if just one of them is at 0 all of them show the out of stock message, I am lost on this one. if anyone has any insight that would be great. basically if an item is out of stock on the website and ordered i want out of stock to be displayed on the orders page in the orders detail screen.

Posted

In PHP, variables inside a loop aren't limited in their scope (like they are in C++, for example). So once you set $OutStock, it persists and is never reset. You need to add an "else" statement, like so:

 

if ($order->products[$i]['stock'] < 1 ) {
  $OutStock = 'OUT OF STOCK';
} else {
  $OutStock = '';
}

Check out Chad's News.

Posted

You are right i thought of it as that for the loop it would check the if statement for each product. i did not think about it having to be reset each time. Works perfectly now.

Archived

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

×
×
  • Create New...