Jump to content

- - - - -

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

  • Please log in to reply
5 replies to this topic

#1   Supertex

  • Members
  • 279 posts
  • Real Name:Shawn
  • Gender:Male
  • Location:Wichita Falls, Texas

Posted 16 January 2017 - 19:24

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.

#2   Supertex

  • Members
  • 279 posts
  • Real Name:Shawn
  • Gender:Male
  • Location:Wichita Falls, Texas

Posted 16 January 2017 - 20:45

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...

#3   auzStar

  • Members
  • 537 posts
  • Real Name:Dominic C.
  • Gender:Male
  • Location:Australia

Posted 16 January 2017 - 23:11



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;



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

#4   Jack_mcs

  • Members
  • 28,382 posts
  • Real Name:Jack
  • Gender:Male

Posted 17 January 2017 - 01:29

@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?

#5   burt


    I drink and I know things

  • Community Team
  • 12,492 posts
  • Real Name:G Burton
  • Gender:Male
  • Location:UK/DEV/on

Posted 17 January 2017 - 10:04

A disabled field is just that. It's disabled from any use.

Use readonly instead of disabled.

This is a signature that appears on all my posts.  It is not specifically aimed at you.


IF YOU MAKE A POST REQUESTING HELP...please state the exact version of osCommerce that you are using. THANKS
If you are still on the old style osCommerce, it is time to move to Responsive.


#6   Supertex

  • Members
  • 279 posts
  • Real Name:Shawn
  • Gender:Male
  • Location:Wichita Falls, Texas

Posted 11 February 2017 - 19:24

@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') . '&nbsp;' . 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') . '&nbsp;' . TEXT_QUANTITY_ADJUSTMENT . tep_draw_separator('pixel_trans.gif', '24', '15') . '&nbsp;' . 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.