Post by jakekimpton » Tue Nov 10, 2009 9:07 pm

Well the title kind of explains it. I'm running 1.3.4 version and would like to know if there's a way of getting stock to be disabled when they run out of stock. This would be really helpful, thanks.

Newbie

Posts

Joined
Tue Sep 29, 2009 9:28 pm

Post by fido-x » Tue Nov 10, 2009 11:35 pm

There is no "disable product if out of stock" function. However, if you change the following lines in "catalog/controller/product/product.php" (lines 195 to 203) from:-

Code: Select all

if ($product_info['quantity'] <= 0) {
	$this->data['stock'] = $product_info['stock'];
} else {
	if ($this->config->get('config_stock_display')) {
		$this->data['stock'] = $product_info['quantity'];
	} else {
		$this->data['stock'] = $this->language->get('text_instock');
	}
}
to:

Code: Select all

if ($product_info['quantity'] <= 0) {
	$this->data['stock'] = $product_info['stock'];
	$this->data['stock_level'] = FALSE;
} else {
	if ($this->config->get('config_stock_display')) {
		$this->data['stock'] = $product_info['quantity'];
		$this->data['stock_level'] = TRUE;
	} else {
		$this->data['stock'] = $this->language->get('text_instock');
		$this->data['stock_level'] = TRUE;
	}
}
Then, in "catalog/view/theme/default/template/product/product.tpl", change the following (lines 89 to 91) from:-

Code: Select all

<div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px;"><?php echo $text_qty; ?>
  <input type="text" name="quantity" size="3" value="1" />
  <a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a></div>
to:

Code: Select all

<?php if ($stock_level) { ?>
  <div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px;"><?php echo $text_qty; ?>
    <input type="text" name="quantity" size="3" value="1" />
    <a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a></div>
<?php } ?>
The "Add to Cart" button will no longer appear on the page when a product is out of stock.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by jakekimpton » Tue Nov 10, 2009 11:50 pm

Oh ok cool fix, althought instead of just removing the button you could just make a non-clickable one saying "Out Of Stock"

Newbie

Posts

Joined
Tue Sep 29, 2009 9:28 pm

Post by fido-x » Wed Nov 11, 2009 12:27 am

OK then, try this. From the above post change:

Code: Select all

<?php if ($stock_level) { ?>
  <div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px;"><?php echo $text_qty; ?>
    <input type="text" name="quantity" size="3" value="1" />
    <a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a></div>
<?php } ?>
to:

Code: Select all

<div style="background: #F7F7F7; border: 1px solid #DDDDDD; padding: 10px;">
  <?php if ($stock_level) { ?>
    <?php echo $text_qty; ?>
    <input type="text" name="quantity" size="3" value="1" />
    <a onclick="$('#product').submit();" id="add_to_cart" class="button"><span><?php echo $button_add_to_cart; ?></span></a>
  <?php } else {?>
    <a  class="button"><span><?php echo $stock; ?></span></a>
  <?php } ?>
</div>

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by jakekimpton » Wed Nov 11, 2009 12:50 am

Ah brilliant, i added in another CSS style to make the button red when out of stock too. Thanks

Although i think this function should already be implemented imho. But oh well :D Thanks anyway

Newbie

Posts

Joined
Tue Sep 29, 2009 9:28 pm
Who is online

Users browsing this forum: No registered users and 50 guests