Jump to content
Latest News: (loading..)
puggybelle

Hide Add To Cart, Buy and Buy Now for out of stock items

Recommended Posts

Hi Lambros - I am very pleased to see you're still speaking to me!

It's very late here (East Coast, US), but I will certainly try your suggestions on Saturday and post back with good news, I hope!

After Malcolm and I ended our conversation, I messed around a bit with catalog/includes/modules/product_listing and the best I could do was to click on a category with 12 out of stock items and see twelve Out Of Stock buttons appear on the screen...before the products themselves appeared.  Sigh.

I'm no programmer.  Lots of work to do tomorrow!  Thanks!

- Andrea

 

 

Share this post


Link to post
Share on other sites

Much success but not all...

Product Listing is fixed.  Catalog/Products_New is fixed.  Catalog/Specials is fixed.  Very happy!

But, the New Products Module that appears on the homepage is showing Out Of Stock buttons for all items, whether they're in stock or not.

Here's the code I applied for both tpl_cm_i_new_products (index) and tpl_cm_in_new_products (index nested):

<?php
               if ($product_info['products_quantity'] >= 1) {   
              echo '<a href="' . tep_href_link($PHP_SELF, tep_get_all_get_params(array('action')) . 'action=buy_now&products_id=' . (int)$new_products['products_id']) . '" data-has-attributes="' . ((tep_has_product_attributes((int)$new_products['products_id']) === true) ? '1' : '0') . '" data-in-stock="' . (int)$new_products['in_stock'] . '" data-product-id="' . (int)$new_products['products_id'] . '" class="btn btn-success btn-index btn-buy" role="button">' . MODULE_CONTENT_NEW_PRODUCTS_BUTTON_BUY . '</a>';
               } else {
  echo tep_draw_button(IMAGE_BUTTON_DISABLE, 'fas fa-ban', null, 'primary', array('params' => 'disabled="disabled"'), 'btn-danger');
 }  
              ?>

Do you see anything wrong with  it? 

- Andrea

Share this post


Link to post
Share on other sites

@puggybelle

Close....
You cannot use $product_info[products_quantity] in the new_products modules. Two reasons why.

1. look at the code, all variables are like $new_products['products_id'] or $new_products['products_image'] use $new_products and not $product_info because well it is a new_products module.

2. the p.products_quantity check is not inside the new products database query so it cannot understand and check for it. Therefore we use the same function as we used in the product_listing file, tep_get_products_stock, which checks for the products_quantity. That combined with the right variable $new_products['products_id'] becomes

if ( tep_get_products_stock($new_products['products_id']) >= 1) {

If you want to know what the tep_get_products_stock does. Here the function code (inside general.php)

////
// Return a product's stock
// TABLES: products
  function tep_get_products_stock($products_id) {
    $products_id = tep_get_prid($products_id);
    $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . (int)$products_id . "'");
    $stock_values = tep_db_fetch_array($stock_query);

    return $stock_values['products_quantity'];
  }

 


When you ask for help/support:

  • Always state your osCommerce version
  • If possible, list up installed add-ons
  • 3rd party templates are not supported in the forum

Latest osC: osCommerce CE (Community Edition aka. v2.3.4.1 Frozen)

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×