Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Change stock level when order status is shipped


mdeloach

Recommended Posts

Hello,

 

I have run into a bit of a problem with a client site, and I'm wondering if anyone knew of a fix or workaround for this....

 

Currently the way OScommerce works is that when a customer completes and order and submits it, the stock level for those particular products will change.

 

What I need to do is change the stock level when changing the status of the order in the Admin section of oscommerce (Customers/Orders) to "shipped"... Then, and then only, I would like for the stock level to subtract for those particular products.

 

Does anyone out there possibly know how to change this? I couldn't find a contribution much less a thread where this was addressed.

 

Would appreciate any help,

 

Matt

Link to comment
Share on other sites

That may be a mistake to do...That leaves you wide open to sell an item that is no longer in stock....

You may want to rethink what you ask for...

 

 

Mike

Link to comment
Share on other sites

You would need to take the stock update section out of catalog/checkout_process.php and put it in catalog/admin/orders.php

 

This adjust the quantity when changing the status from pending to processing.

 

Mainly I do it this way because all the items are quantity 1 and this eliminates fraud orders from depleting the stock.

 

case 'update_order':

...


if ($status == 2 && $check_status['orders_status'] == 1) {
           $order = new order($oID);

           for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
             if (STOCK_LIMITED == 'true') {
               if (DOWNLOAD_ENABLED == 'true') {
                 $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 = $order->products[$i]['attributes'];
                 if (is_array($products_attributes)) {
                   $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $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
                 if ((DOWNLOAD_ENABLED != 'true') || (!$stock_values['products_attributes_filename'])) {
                   $stock_left = $stock_values['products_quantity'] - $order->products[$i]['qty'];
                 } else {
                   $stock_left = $stock_values['products_quantity'];
                 }
                 tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
                 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']) . "'");
                 }
               }
             }
           }
         }

Link to comment
Share on other sites

The code in checkout_process.php differers from what you seem to have:

 

  for ($i=0, $n=sizeof($order->products); $i<$n; $i++) {
// Stock Update - Joao Correia
   if (STOCK_LIMITED == 'true') {
     if (DOWNLOAD_ENABLED == 'true') {
       $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 = $order->products[$i]['attributes'];
       if (is_array($products_attributes)) {
         $stock_query_raw .= " AND pa.options_id = '" . $products_attributes[0]['option_id'] . "' AND pa.options_values_id = '" . $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
       if ((DOWNLOAD_ENABLED != 'true') || (!$stock_values['products_attributes_filename'])) {
         $stock_left = $stock_values['products_quantity'] - $order->products[$i]['qty'];
       } else {
         $stock_left = $stock_values['products_quantity'];
       }
       tep_db_query("update " . TABLE_PRODUCTS . " set products_quantity = '" . $stock_left . "' where products_id = '" . tep_get_prid($order->products[$i]['id']) . "'");
       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']) . "'");
       }
     }
   }

 

 

 

Also, in "orders.php" my code differs from yours as well

 

        if ( ($check_status['orders_status'] != $status) || tep_not_null($comments)) {
         tep_db_query("update " . TABLE_ORDERS . " set orders_status = '" . tep_db_input($status) . "', last_modified = now() where orders_id = '" . (int)$oID . "'");

 

 

I tried to remove the above in checkout_process.php and add it to orders.php to no avail. Hope I don't sound too ignorant, but I'm wondering if you or anyone might be able to help.

 

Thanks again,

 

Matt

Link to comment
Share on other sites

This is so it only updates when you change the status from 1 to 2.

 

if ($status == 2 && $check_status['orders_status'] == 1) {
 $order = new order($oID);

 Stock update code from checkout_process.php

}

 

This doesnt exist in orders.php so you have to add it to orders.php in the case 'update_order': section and then remove it from checkout_process.php

Link to comment
Share on other sites

  • 4 weeks later...

I get this error when following ur instructions above :

 

Fatal error: Cannot instantiate non-existent class: order in /data/web/com.roystontong/dvd/catalog/admin/orders.php on line 71

 

line 71 says:

 

$order = new order($oID);

 

I tried require(DIR_WS_CLASSES . 'order.php'); but that doesn't work. It doesnt like the order.php file in the admin/classes folder.

 

So how did u guys fix this? Cause im sure u guys had the same problem.

 

Thanks

I'm an Idiot !

Link to comment
Share on other sites

  • 2 years 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...