Latest News: (loading..)
Supertex

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

6 posts in this topic

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.

Share this post


Link to post
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...

Share this post


Link to post
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

 

Share this post


Link to post
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?

Share this post


Link to post
Share on other sites

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

Use readonly instead of disabled.

Share this post


Link to post
Share on other sites

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

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