Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Add-On to remove "Add to Cart" button when stock is 0


Mystefyer

Recommended Posts

Hi,

 

I'm working on a new add-on to remove the Add to Cart button on the product_listing.php and the product_info.php for OsCommerce 2.3. This is because I want to be able to show our customers products we carry but do not have in stock but prevent them from adding them to their cart.

 

On product_info.php I got it working perfectly. For now the button is replaced with some text stating to use the contact form for more info. In a later stage I will change this to a neat button linking to the contact form and move the text to beneath the product image. Here's the code I have so far for product_info.php for who is interested :

 

<div class="buttonSet">
<?php
if ($product_info['products_quantity'] >=1) {
?>
<span class="buttonAction"><?php echo tep_draw_hidden_field('products_id', $product_info['products_id']) . tep_draw_button(IMAGE_BUTTON_IN_CART, 'cart', null, 'primary'); ?></span>
<?php
} else {
?>
<span class="OutOfStock"><?php echo TEXT_OUT_OF_STOCK_CONTACT; ?></span>
<?php
}
?>

 

So far no real challenges there. But when it comes to product_listing.php I've hit a snag. What I want to accomplish is that when a products stock hits 0, the Add to Cart button is replaced by a Out of stock button which when clicked will open the product info page. Here's the code so far :

 

case 'PRODUCT_LIST_BUY_NOW':

  if ($listing['products_quantity'] == 0) {
$prod_list_contents .= '  <td align="center">' . tep_draw_button(IMAGE_BUTTON_OUT_OF_STOCK) . '</td>';		
  } else
  if ($listing['products_quantity'] > 0) {
$prod_list_contents .= '		<td align="center">' . tep_draw_button(IMAGE_BUTTON_BUY_NOW, 'cart', tep_href_link(basename($PHP_SELF), tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . $listing['products_id'])) . '</td>';
}
break;

 

The thing is it replaces all the Add to cart (Buy now) buttons for the Out of stock button and seems to ignore the else statement. So I hope any of you guys wants to pitch in and can find the thing I'm overlooking. Any help is much appreciated.

 

Regards,

 

Emile

Link to comment
Share on other sites

@@14steve14, I looked at that one, but alas, it is not compliant with 2.3. The code you need tho change according to the install html is for 2.2 which is drastically different than 2.3.

I could not find an addon which works for 2.3, hence I started making my own.

Link to comment
Share on other sites

14Steve14, if you are reffering to the code edits of http://addons.oscommerce.com/info/8507, I looked into it, but none of the entries you are supposed to edit can be found in 2.3 except for the parts in product_info.php, the differences in that file are not so big compared with 2.2.

 

As to the problem with my code lies within product_listing.php. It now replaces all Buy Now buttons for all items in the list, despite their stock status. Changing the 0 to a 1 in the 2nd

if ($listing['products_quantity'] > 0) {

result in Buy Now buttons for all products. The idea is to replace only the buttons for items which have a stock of 0

 

Regards,

 

Emile

Link to comment
Share on other sites

  • 4 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...