Site maintenance: Tuesday 17 Nov, from 10:00 UTC, about 4–6 hours. Details

This cutover relies on some testing that is still incomplete so may be cancelled at short notice

Forums / Basic Configuration / Not display input If a product is out of stock

Not display input If a product is out of stock

Locked

Started by wiggst3r on 4 Aug 2008, 9:16 AM · Views: 1,282

Results 1 to 1 of 1
This thread is locked. New replies are disabled.
4 Aug 2008, 9:16 AM
#1
wiggst3r avatar

wiggst3r

New Zenner

Join Date:
Mar 2008
Posts:
39
Plugin Contributions:
0

Not display input If a product is out of stock

Hi

I'm not sure where this should go, but I'll post here anyways.

I have a product, which has 2 different product arributes; Book and Box.

So far, both input boxes are shown if both, or one or the other is in stock.

What I'm looking to do is, If one of them is out of stock, then the input box which can be filled out, isn't displayed, but possibly replaced by an image.

You can see below

In my example, the first input box's product attribute is out of stock (i.e. there are no single books, yet there are 50 box's in stock, yet you can still input a quantity.

My code in tpl_modules_attributes.php is as follows:

<?php
if($products_quantity)
{

	global $db;
	//instead of using the currrent attributes.php field. Get the here manually and create the text fields
	$sql = " SELECT * FROM products_attributes atr, products_options_values val, products_options opt " .
		   " WHERE atr.products_id = '{$_GET['products_id']}' " .
		   " AND val.products_options_values_id = atr.options_values_id " .
		   " AND opt.products_options_id = atr.options_id " .
		   " ORDER BY val.products_options_values_sort_order ";
	$count = 0;
	$result = $db->Execute($sql);
	$num_attributes = mysql_num_rows($result->resource);
	if($num_attribute)
	{
		?><h4>Purchase Options</h4><?php
	}
	else
	{
		?><h4>Purchase Options</h4><?php
	}

	?>



	<div id="purchase_options_selections">
	<script type="text/javascript" src="includes/templates/bullbrand/scripts/product_page_price_updator.js"></script>

	<?php

	while(!$result->EOF)
	{
		$count++;
		?>


		<div style="position: relative">

		<p class="left_option"><?=$result->fields['products_options_values_name']?></p>

			<div class="yeah"><label  class="test" for="product_quantity_<?=$count?>">Quantity</label>
			<input  class="test" name="id[1][<?=$result->fields['products_options_values_id']?>]" id="product_quantity_<?=$count?>" onkeyup="update_total_price();" />
			<input type="hidden" id="product_price_<?=$count?>" value="<?=$result->fields['options_values_price']?>"></input></div>

		</div>

		<?php
		$result->MoveNext();
	}
	if(!$count)
	{
		//must be a normal product with just 1 price. Display the 1 field
		$sql = " SELECT * FROM products pro, products_description des " .
			   " WHERE pro.products_id = '{$_GET['products_id']}' " .
			   " AND pro.products_id = des.products_id ";
		$result = $db->Execute($sql);

		?>
<div>
		<p class="left_option" ><?=$result->fields['products_name']?></p>


			<label class="testie" for="product_quantity_<?=$count?>">Quantity</label>
			<input class="testie" type="text" name="cart_quantity" id="product_quantity_1" value="0" onkeyup="update_total_price();" />
			<input type="hidden" id="product_price_1" value="<?=$result->fields['products_price']?>"></input>

		</div>

		<?php
	}

	?>

	<p class="product_add_to_basket"><input type="image" src="includes/templates/bullbrand/images/add_to_basket_button2.gif" class="add_to_basket_button" title="Add to Basket" value="Add to Basket"></input></p>
	<p class="product_price_total" id="product_price_total">Total £0</p>

	</div>
<?php

}
else
{
	?><p><br/>    Sorry this product has sold out, please check back soon</p><?php
}
?><?php

If anyone could help me with this, I'd much appreciate it.

Thanks