Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Need to write sum of two input fields to DB column - product quantity


Supertex

Recommended Posts

Im trying to modify my store to track manual quantity changes.  Part of the process is disallowing direct manipulation of the 'quantity' field in the 'edit' function of categories.php.  I've set that field to 'disabled', so you can see what it's pulled from the DB, but you can't modify it.  I've also added a field for "inventory_adjustment", but I cant figure out how to use 

$sql_data_array = array('products_quantity' => (int)tep_db_prepare_input($HTTP_POST_VARS['products_quantity']),

to post the sum of the two fields: 'products_quantity' and 'inventory_adjustment'.  

 

I'd really appreciate a hand if someone has a few moments to spare.

Link to comment
Share on other sites

Hrm...it seems the reason I was having trouble had more to do with the fact that the quantity field was set 'disabled'.  If I remove that, then I have no trouble posting the sum back to the DB...but now I have to figure out how to disable the field...

Link to comment
Share on other sites

@@Supertex

 

One way of doing it Shawn is to use a hidden filed to post the qty. So you could change "tep_draw_input_field(" to "tep_draw_hidden_field(" and then place the output qty next to it i.e.:

tep_draw_hidden_field('products_quantity', $pInfo->products_quantity) . $pInfo->products_quantity;

cheers

 

My Add-ons
Advanced Cache Control Tool for osCommerce 2.3.x (non-bootstrap) Download Support
Ajax Product Listing for osC 2.3.4 (bootstrap) Download Support
Category New Products Carousel for osC 2.3.4 (bootstrap) Download Support
Category Popular Products Carousel for osC 2.3.4 (bootstrap) Download Support
Customer Testimonials for osCommerce 2.3.4 (bootstrap and non-bootstrap) Download Support
Front Page New Products Carousel for osC 2.3.4 (bootstrap) Download Support

Index Nested - Product Listing for osC 2.3.4 (bootstrapDownload Support
Match Categories in Search Results for osCommerce versions 2.3.x (non-bootstrap) Download Support
Modular Category Page for osC 2.3.4 (bootstrap)
Download Support

NEW Australia Post Shipping Modules for osCommerce 2.3.x (non-bootstrap) Download Support
NEW Equal Height Module for osC 2.3.4 (bootstrapDownload Support
Products Low Stock Report for osC 2.3.x (bootstrap and non-bootstrap) Download Support
Twitter Typeahead Autocomplete Search for osCommerce 2.3.4 (bootstrap and non-bootstrap)
Download Support

Upcoming Products Modules for osC 2.3.4 (bootstrap) Download Support

 
Assisted Add-ons
Scroll Boxes for osCommerce 2.3.x (bootstrap and non-bootstrap) Download Support
 
Bootstrap Add-ons created by other members
osCommerce Bootstrap Addons and Code

Link to comment
Share on other sites

@@Supertex I'm confused about what you mean when you say you want to disable the field. Your use of the word field indicated you are talking about the database but, as far as I know, it isn't possible to disable a field in the database. Can you explain in more detail what you mean?

Support Links:

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

All of My Addons

Get the latest versions of my addons

Recommended SEO Addons

Link to comment
Share on other sites

  • 4 weeks later...

@@Jack_mcs I was talking about the "Quantity" input form field in admin/categories.php.  I wanted it to show, but not be editable, because I added a 'quantity adjustment' form field to be used instead.  

 

At the same time, I added a new DB table with an auto-incrementing field for 'event_id', and then fields for event_date, products_quantity, adjustment_quantity, product_id, products_name, and products_model.

 

So when you 'save' a product, the quantity and adjustment are combined and the result is then saved in the "products_quantity" field of the products table, and a snapshot of the quantity before the update, as well as the adjustment, etc. is saved to my "inventory" table.

 

With this, I can create an inventory report that will show modifications to product quantities that were made manually, but ignore any stock decrements due to order processing.  I've had ...issues... with keeping quantities right, like entering a shipment quantity instead of adding the shipment to what I have on-hand and THEN adding it (because I'm a dummy).  This will just help with tracking down any inconsistencies in site inventory vs shelf inventory.

 

At AuzStar's advice, I ended up doing this: 

            <td class="main" border="1"><?php echo tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_hidden_field('products_quantity', $pInfo->products_quantity) . tep_draw_input_field('products_quantity', $pInfo->products_quantity, 'disabled') . tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . TEXT_QUANTITY_ADJUSTMENT . tep_draw_separator('pixel_trans.gif', '24', '15') . ' ' . tep_draw_input_field('quantity_adjustment'); ?></td>

And as far as I can tell, this seems to work great.  

 

Now I have to integrate my "stats_low_stock.php" file to do the same.  Right now, it uses this:

    function tep_add_product_shipment($products_id, $shipment) {
          $sql = "update " . TABLE_PRODUCTS . " set products_quantity = products_quantity + " . $shipment . " where products_id = '" . (int)$products_id . "'";
					echo  'update successful'; //add a button here after verbose
          return tep_db_query($sql);
  	}

But now I need for it to update the 'inventory' table as well.  Haven't jumped on this yet.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...