Send Email Alert When Quantity Reaches Specified Level?

hominid4

Member
Hi. I'm building a product purchase order form for a printing company to allow one of their customers to re-order brochures. We'll have a product table (id|brochure_name|brochure_description|quantity) that will start out with 2500 brochures initially available, and each time an order is placed it'll deduct from that 2500 quantity; and when the quantity level reaches 300 they need to receive a "quantity is low" alert email.

I'll be using the calc element to deduct from the quantity on submit, and a second calc element to check when the form loads (or maybe use the same calc on submit) the product table's quantity field and if it's (300<) send an alert email to the printing company's owner.

Doing the quantity deducting and checking shouldn't be a problem, but I'm not sure where to start with sending the email. Such as:
Code:
if ($productQty < 300) {
send email; // what would I put here to send/trigger email?
}
Could I please get a push in the right direction on what I should look for?

Thanks!
J! 3
Fabrik: latest GitHub
 
The calc element wasn't really designed to do things like this.

I would consider using a MySQL View to create a view of the product table which has the decremented quantities in it, which creates a qty_remaining field, by doing some simple math with a dependent subquery on the order table (that totals the sales count grouped on product id), rather than using a calc element.

Either that, or use a form submission plugin on the orders table, running onAfterProcess, which does the decrementing. Also think carefully about whether you allow editing of the sales orders, as changing qty's is tricky.

For the email, just use the "Condition" on a normal form email plugin. As you won't have the qty from the products table available as a placeholder, you can either set it as session data in the first plugin, or just look it up with a query (using the product_id on your sales form).

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top