Last week a new client approached me to help out with an admin function within her site. Here’s the basic idea;
Each Order received has a tickbox by the product:
The tickbox would update an entry in the database to state whether the product is “in stock” (1) or “out of stock” (0). The system worked well, but was coded as part of the form so needed the [update] button to be pushed. That’s not a massive big deal, but it’s an extra step that might get forgotten by the data entry people and so on.
Once the days orders of products had been “ticked”, a report is run to show the shopwoner what needs to be ordered from her suppliers and what she has already on hand. This was already coded.
The brief (in brief!!)
Make the checkbox fire automatically, to update the database entry on a per product, per order basis. Make the table row highlight if the checkbox is ticked.
The first step was to get it all working on a new RC2 (note that the client does not yet run 2.3.1, though 2.3.1 and 2.2 are very similar in most resepects especially in the admin area). I installed rc2 and amended the orders_products DB table to hold a tinyint flag saying 0 or 1 for stock purposes.
I then added a checkbox for each product ordered, the result looked exactly the same;
Next up, I coded up a .js file which (on checkbox tick) reads the value of the checkbox (1 or 0) and the value of the product ID and the Order ID. It then uses the ajax function of jquery to open a standalone php file which takes those inputs and updates the database accordingly. The .js file also fires off a css update using addClass to highight (or un-highlight) to row affected (which means anyone doing data work, can straightaway see what has been changed);
And no need to press the update button any more.