Auto update Order Status via barcode on invoice
1.3.8a - I know, we are upgrading soon
The code I'm working on should auto update the order_status when a barcode on an invoice is scanned into a text box.
I have placed this in admin/includes/header.php as I would like it visible always and mainly viewing admin home.
Also have "admin home" refresh when the order is updated with the cursor always ready to go in that checkbox if initially clicked there.
Here's the code I have based on super_orders id text box though a bit stuck. While in super_orders viewing an order, it's changing the dropdown to order_status 2? The input_field itself does nothing up in the header.
Any suggestions?
PHP Code:
<?php
echo zen_draw_input_field('oID', '', 'size="6"');
echo zen_draw_hidden_field('oID', $oID);
$db->Execute("UPDATE " . TABLE_ORDERS . " SET orders_status_id='2' where orders_id='".$oID."'");
echo '</form>'; ?>
Re: Auto update Order Status via barcode on invoice
I have recoded this, which breaks the behavior of the status displaying "2" in the dropdown menu.
I do think this is the wrong direction as I believe the previous code was actually updating the order to status "2", but not updating the order status history that is desired.
Thoughts?
PHP Code:
<?php
echo zen_draw_form('auto_update', '/index.php', '', 'get', '', true);
echo zen_draw_input_field('auto_update', '', 'size="6"');
echo zen_draw_hidden_field('auto_update', $oID);
?>
<?php
{
if(isset($_POST['auto_update']) ){
$orders_history = $db->Execute("UPDATE ".TABLE_ORDERS." SET orders_status='4' where orders_id='".$oID."'");
}
}
?>
<?php
echo '</form>'; ?>
Re: Auto update Order Status via barcode on invoice
Hmmm, I like where you are going with this since we are about to add barcodes to our warehouse fulfillment process and auto updating by scanning a barcode would be nice. But I would want it to send the email, too, so there's more to it than that. I'll have a think about this and try a few things out this coming weekend. I don't have time during the week to work on much code development anymore. Thanks for getting the conversation started!
Re: Auto update Order Status via barcode on invoice
excellent great hopeful move forward - default behavior of the comments is that the email notification is set to true. I have changed that to false.
Where I am stuck is that the 1st post is more correct - it needs the following to update the page and engage the form field.
PHP Code:
echo zen_draw_form('auto_update', '/index.php', '', 'get', '', true);
The code is making the dropdown status update to that status, just not updating the status_history. When I swap table_orders for table_orders_status_history and orders_status to include _id, ALL the previous statuses change to that ID.
It needs to still update the order and INSERT a new status as if I hit the update button on super_orders
PHP Code:
<?php echo zen_image_submit('button_update.gif', IMAGE_UPDATE); ?>
After the page refreshes, the cursor disappears from the form. Would need it to stay there ready to accept another scan.
Automation is the key to expediency!
Re: Auto update Order Status via barcode on invoice
For the barcode, I used this and it was extremely easy and effective
http://www.ladyada.net/library/zencart/barcodeinv.html
We currently use it in super_orders for the shipper to "bleep" the order in and go to that order instantaneously.
Re: Auto update Order Status via barcode on invoice
Very frustrating - I got this to work minus having the order_status_name appear in the history, it was a blank box.
Now that I come back to it later tonight - nothing works at all - what gives?!
PHP Code:
<td align="left" valign="middle"><?php
echo zen_draw_form('auto_update', '/index.php', '', 'get', '', true);
echo zen_draw_input_field('auto_update', '', 'size="6"');
echo zen_draw_hidden_field('auto_update', $oID);
// the order status name is blank on the update
if(isset($_POST['oID']) ){
$orders_status = $db->Execute("UPDATE " . TABLE_ORDERS . " SET orders_status='4' where orders_id='" . $oID . "'");
$orders_status_history = $db->Execute("INSERT into " . TABLE_ORDERS_STATUS_HISTORY . "
(orders_id, orders_status_id, date_added, customer_notified, comments)
values ('" . (int)$oID . "',
'" . zen_db_input($status) . "',
now(),
'" . zen_db_input($customer_notified) . "',
(SELECT IFNULL(admin_initials, '') FROM admin WHERE admin_id='" .$_SESSION["admin_id"] ."'))");
}
?>
<?php
echo '</form>'; ?>
<br />Update to Pulled</td>
</td>
Re: Auto update Order Status via barcode on invoice
ANSWER - POST needs to be GET
It works again.
So anyone know why the order_status_name is not populating upon the update?
Re: Auto update Order Status via barcode on invoice
I have gone as far as making a brand new module for this and have plans to contribute it as well.
I have everything set up and done except one measly hurdle.
The problem lies in after the order is auto-updated, the orders_status_name is blank on the order history - what am I overlooking here?
The variable $status is there, but it should be defined as the newly updated orders_status='4'
So $status = 'what'
I tried $status = "Order Pulled"; as a fall back and it did not work
PHP Code:
$db->Execute("INSERT into " . TABLE_ORDERS_STATUS_HISTORY . "
(orders_id, orders_status_id, date_added, customer_notified, comments)
values ('" . (int)$order_no . "',
'" . zen_db_input($status) . "',
now(),
'" . zen_db_input($customer_notified) . "',
(SELECT IFNULL(admin_initials, '') FROM admin WHERE admin_id='" .$_SESSION["admin_id"] ."'))");
Re: Auto update Order Status via barcode on invoice
In your prior post you are hard-coding a value of 4 for the new status in the prior query (the UPDATE statement). If you're relying on hard-coding numbers like thatn, then you'll need to do it consistently. So, either use a variable (like maybe $status if using it doesn't clash with other things already being done in original code, or pick something else) and use it in all relevant places, or hard-code it consistently in all relevant places.
Re: Auto update Order Status via barcode on invoice
hmm... I was unaware of how to code that section orders_status='4' differently. Here is the entire block...
PHP Code:
<?php
$auto_update = false;
if ($auto_update == false) {
if(isset($_POST['order_no'])) {
$auto_update = zen_db_prepare_input($_POST['order_no']);
$db->Execute("UPDATE " . TABLE_ORDERS . "
SET orders_status='4', last_modified = now()
where orders_id='" . $order_no . "'");
$db->Execute("INSERT into " . TABLE_ORDERS_STATUS_HISTORY . "
(orders_id, orders_status_id, date_added, customer_notified, comments)
values ('" . (int)$order_no . "',
'" . zen_db_input($status) . "',
now(),
'" . zen_db_input($customer_notified) . "',
(SELECT IFNULL(admin_initials, '') FROM admin WHERE admin_id='" .$_SESSION["admin_id"] ."'))");
zen_redirect(zen_href_link(FILENAME_AUTOUPDATE, '', 'SSL'));
}
}
?>
I don't mind hard coding '" . zen_db_input($status) . "', to be the order_status='4', but unsure how to tackle that.
I tried $status = "Order Pulled"; as a variable and that didn't work.