Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Set status offline when product is out of stock


sinopia

Recommended Posts

Hello,

I've been looking but didn't find anything. I was looking for some addon or bit of code that set the status of product offline when it became out of stock instead showing a ribbon "out of stock" or at checkout the message that products marked are out of stock.

I have some products low cost but with quantity limited, would be more friendly for customer dont saw the product instead of trying to buy it and later have to remove due the stock message.

For example when adding to cart a verification after add to cart and then something like this:

if (($stock_left < 1) {

tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");

}

So at the last stock it disables the product.. otherwise I can always do something like 

if ($product_info['products_quantity'] < 1) 

And output a message/disable add to cart button ..

Link to comment
Share on other sites

Hello @sinopia,

This what you ask for is included in standard OsCommerce. You should state in all your posts that you are using a heavy modified themed version (Themeforest).

As already pointed out by others, it is very difficult to give support for a themed version and in most cases it is impossible.

Link to comment
Share on other sites

Hi @raiwa I understand and I'm sorry to ask here and didn't mention the version I'm using. I don't have any solutions. Some parts of the entire code are normal.

I do have stock report and it decreases the quantity as the products are bought. Just needed a few modifications to set status of the product to offline when it's the last stock.

I've to make just a few modifications on this website and then I can have time to migrate all into CE version, my modifications were made apart the core so that's a start.

About this template it doesn't have much modifications about the osCommerce code. Users on the forum can try to help that I might get into the problem, that was a forum is all about, to help each others.

Best regards

Link to comment
Share on other sites

35 minutes ago, sinopia said:

Hi @raiwa I understand and I'm sorry to ask here and didn't mention the version I'm using. I don't have any solutions. Some parts of the entire code are normal.

I do have stock report and it decreases the quantity as the products are bought. Just needed a few modifications to set status of the product to offline when it's the last stock.

I've to make just a few modifications on this website and then I can have time to migrate all into CE version, my modifications were made apart the core so that's a start.

About this template it doesn't have much modifications about the osCommerce code. Users on the forum can try to help that I might get into the problem, that was a forum is all about, to help each others.

Best regards

If it dosn't work in your store it's just that your code is modified and we can't help without knowing your code. The only thing we can recommend is to compare your code with the original OsCommerce code and try to revert your theme modifications related to stock in the product listing and shopping cart.

The forum and the forum members are ready to help all users of original oscommerce code and the add-ons offered in the marketplace. But is has been pointed out many times that the forum and the members/users can't help on heavy modified stores which use third party themes and which code is unknown. You should ask the provider you paid for the theme. Your store is considered an own fork of OsCommerce.

Please see also Guidelines: General Rules 1:
https://www.oscommerce.com/forums/guidelines/

 

Best regards
Rainer

Link to comment
Share on other sites

1 hour ago, sinopia said:

Only difference from yours is that "Allow Checkout" is set to false

So you have all the right settings, turning a product offline not sure about that. If you are never going to sell it again then ok but if you are expecting new stock then better to display a an expected date than remove product. Only my view 😊

 

Link to comment
Share on other sites

@JcMagpie let's say it's a lowcost product but the stock is only one quantity. I can always set if the quantity is < 1 to output a message and block the add to cart button. But what I really needed is to set product offline so it won't show on the products listings.. @raiwa I understand, and once I've time I'll migrate into CE. By the way I can't do it right now due the lack of time. I've noticed that I've QT Pro functions in some files but I'm not actually using it. It already came with the theme, can be something related with this?

 

Link to comment
Share on other sites

1 hour ago, sinopia said:

I've noticed that I've QT Pro functions in some files but I'm not actually using it. It already came with the theme, can be something related with this?

Hello @sinopia,

The standard QTPro version does only interfere in attributes stock control and deduction if correct configured. It does neither interfere in switching products status nor in showing or not showing out of stock/off status products in product listing/product page.

But, as already (how often) pointed out: we do not know which QTPto version you are using, if it's coding is modified or if there are additional coding modifications in your themed store which may have an influence.

If you are not able to compare your store's code to a standard OsComemrce store code and find out what to do, I recommend you to post in the commercial support thread to find someone who can do it for you.

Best regards
Rainer

Link to comment
Share on other sites

4 hours ago, sinopia said:

But what I really needed is to set product offline so it won't show on the products listings

So all your links will go back to a product not found at best or a page not found error! not the best for rankings! But hey if it's what you need. I'm not sure you can do this in one place easly as products are shown by several sections of the code like new products , specials , manufacurers etc. Not sure ? you will have to do some digging into the code.

 

Link to comment
Share on other sites

@sinopiaYou could install the sold out addon. That will prevent the product from being ordered and you won't lose the listing with the search engines like you will if you change its status.

Support Links:

For Hire: Contact me for anything you need help with for your shop: upgrading, hosting, repairs, code written, etc.

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

13 hours ago, sinopia said:

But what I really needed is to set product offline so it won't show on the products listings.

What are you trying to accomplish here? As others have pointed out, completely taking down the product page is probably going to hurt you on search engine results. If this product is gone for good, that may be appropriate (even better would be to redirect to a replacement product). If it's soon going to be back, why not keep the product page around so that it doesn't get dropped from search engines, and acts as advertising so customers will be encouraged to come back and buy it at a later date. Just make sure it's clearly marked as "out of stock" and the customer can't put it in their cart.

Link to comment
Share on other sites

Hello everyone. Thanks for your answers.

About the search engine issues I could redirect as a temp only for the product category as the product is offline.

But best thing to do, is to check it's out of stock, and if yes, to disable the button "add to cart" and show a notice that the product is out of stock,  this way client won't add the product to shopping cart. (this way avoiding at the shopping cart a message that the product is out of stock.)

Best regards.

Link to comment
Share on other sites

Was unable to find a way to do this without core code changes!  button code is in several places so no option but to edit files? (Unless I have missed something) Only done this on CE BS4 and looks to work ok. Buttons get deactivated and turn red. This will need to be repeted for every module that allows or display add to cart or buy!!

As it's core code changes will not post but if anyone needs it PM and I'll send you the edits. Oh and as the core files were beeing edited :( decided to add the % discount at the same time. It's on the test site if you wish to see it in action. Still a few improvments need as buttons deactivate fully in listings but on product info page buy button is deactivated and nothing is added to cart, but for some reason the page still refreshes? Clearly i've missed somthing and it's still firing on click.

  https://chilleddisplays.co.uk 

So for product listings you get,

image.png.89ef15e3aca1d3babb7fb22785742c3a.png

and on product page you get,

image.png.c19603a68b6d9dfb46822cc642d435d2.png

 

Link to comment
Share on other sites

Why not use a HT module on checkout_success?  The HT module would perform the following functions;

  1. get the "in stock" number of each product
  2. if stock is less than 1, set the product inactive
  3. maybe send an email to shopowner to tell them what has just gone inactive

You could then also have a dashboard module to show the latest X products that have been set to inactive.

It seems fairly simple if you keep it simple as the above ?

Link to comment
Share on other sites

5 minutes ago, burt said:

Why not use a HT module on checkout_success?  The HT module would perform the following functions;

  1. get the "in stock" number of each product
  2. if stock is less than 1, set the product inactive
  3. maybe send an email to shopowner to tell them what has just gone inactive

You could then also have a dashboard module to show the latest X products that have been set to inactive.

It seems fairly simple if you keep it simple as the above ?

Having thought about it for a whole 30 seconds, you wouldn't even need to do that.  The HT module would just need to run;

update products set products_status = 0, products_last_modified = now() where products_quantity < 1

Link to comment
Share on other sites

1 hour ago, burt said:

Having thought about it for a whole 30 seconds, you wouldn't even need to do that.  The HT module would just need to run;

update products set products_status = 0, products_last_modified = now() where products_quantity < 1

This is already done in core checkout_process.php:

        if ( ($stock_left < 1) && (STOCK_ALLOW_CHECKOUT == 'false') ) {
          tep_db_query("update " . TABLE_PRODUCTS . " set products_status = '0' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
        }

It seems the OP has this modified/removed in her themeforest theme. She only needs to re-establish it like already explained at the very beginning of this thread.

Link to comment
Share on other sites

You could simply replace your admin with the new one by @shetch as it has this already coverd in the dashbord! Stock control is something you just have to get a grip on, no short cuts to this.

https://apps.oscommerce.com/LCrov&amp;bootstrap-v4-oscommerce-admin-ce

 

image.png.4bf294a0dc2be6acfbacea0a92fdbafb.png

Turning products off in not a good solution, better to have them  display out of stock and not be allowed to be added to cart than lose links. Better still show new stock arrival date as well.

image.png.89f621ed483f33cd91bae9fe13113a27.png

 

Link to comment
Share on other sites

  • 1 month later...

Hi everyone, sorry I just saw this today.. At my checkout_process.php it's like this:

<?php
//....
for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
//++++ QT Pro: Begin Changed code
    $products_stock_attributes=null;
    if (STOCK_LIMITED == 'true') {
        $products_attributes = $order->products[$i]['attributes'];
//      if (DOWNLOAD_ENABLED == 'true') {
//++++ QT Pro: End Changed Code
        $stock_query_raw = "SELECT products_quantity, pad.products_attributes_filename 
                            FROM " . TABLE_PRODUCTS . " p
                            LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES . " pa
                             ON p.products_id=pa.products_id
                            LEFT JOIN " . TABLE_PRODUCTS_ATTRIBUTES_DOWNLOAD . " pad
                             ON pa.products_attributes_id=pad.products_attributes_id
                            WHERE p.products_id = '" . tep_get_prid($order->products[$i]['id']) . "'";
// Will work with only one option for downloadable products
// otherwise, we have to build the query dynamically with a loop
        $products_attributes = (isset($order->products[$i]['attributes'])) ? $order->products[$i]['attributes'] : '';
        if (is_array($products_attributes)) {
          $stock_query_raw .= " AND pa.options_id = '" . (int)$products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . (int)$products_attributes[0]['value_id'] . "'";
        }
        $stock_query = tep_db_query($stock_query_raw);
      } else {
        $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
      }
      if (tep_db_num_rows($stock_query) > 0) {
        $stock_values = tep_db_fetch_array($stock_query);
// do not decrement quantities if products_attributes_filename exists
        $actual_stock_bought = $order->products[$i]['qty'];
        $download_selected = false;
        if ((DOWNLOAD_ENABLED == 'true') && isset($stock_values['products_attributes_filename']) && tep_not_null($stock_values['products_attributes_filename'])) {
          $download_selected = true;
          $products_stock_attributes='$$DOWNLOAD$$';
        }
// If not downloadable and attributes present, adjust attribute stock
        if (!$download_selected && is_array($products_attributes)) {
          $all_nonstocked = true;
          $products_stock_attributes_array = array();
          foreach ($products_attributes as $attribute) {
            if ($attribute['track_stock'] == 1) {
              $products_stock_attributes_array[] = $attribute['option_id'] . "-" . $attribute['value_id'];
              $all_nonstocked = false;
            }
          } 
          if ($all_nonstocked) {
            $actual_stock_bought = $order->products[$i]['qty'];
          }  else {
            asort($products_stock_attributes_array, SORT_NUMERIC);
            $products_stock_attributes = implode(",", $products_stock_attributes_array);
            $attributes_stock_query = tep_db_query("select products_stock_quantity from " . TABLE_PRODUCTS_STOCK . " where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
            if (tep_db_num_rows($attributes_stock_query) > 0) {
              $attributes_stock_values = tep_db_fetch_array($attributes_stock_query);
              $attributes_stock_left = $attributes_stock_values['products_stock_quantity'] - $order->products[$i]['qty'];
              tep_db_query("update " . TABLE_PRODUCTS_STOCK . " set products_stock_quantity = '" . $attributes_stock_left . "' where products_stock_attributes = '$products_stock_attributes' AND products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
              $actual_stock_bought = ($attributes_stock_left < 1) ? $attributes_stock_values['products_stock_quantity'] : $order->products[$i]['qty'];
            } else {
              $attributes_stock_left = 0 - $order->products[$i]['qty'];
              tep_db_query("insert into " . TABLE_PRODUCTS_STOCK . " (products_id, products_stock_attributes, products_stock_quantity) values ('" . tep_get_prid($order->products[$i]['id']) . "', '" . $products_stock_attributes . "', '" . $attributes_stock_left . "')");
              $actual_stock_bought = 0;
            }
          }
        }
//        $stock_query = tep_db_query("select products_quantity from " . TABLE_PRODUCTS . " where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
//      }
//      if (tep_db_num_rows($stock_query) > 0) {
//        $stock_values = tep_db_fetch_array($stock_query);
// do not decrement quantities if products_attributes_filename exists
        if (!$download_selected) {
          $stock_left = $stock_values['products_quantity'] - $actual_stock_bought;
          tep_db_query("UPDATE " . TABLE_PRODUCTS . " 
                        SET products_quantity = products_quantity - '" . $actual_stock_bought . "' 
                        WHERE products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
//++++ QT Pro: End Changed Code
      }
    }
  //....
 ?>

 

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...