I want to keep inventory logs. So I created in MySql a table cataloginventory_stock_item_log
, which is updated by triggers
to capture the qty BEFORE UPDATE
and AFTER UPDATE
from table cataloginventory_stock_item
. So later I can run a report with the qty additions or subtractions.
My question is, I also want to capture the admin username (or email) so I know what user made the change to the quantity.
Is there a way the php files would pass to MySql the admin username out of the box? If not, what php files will have to be modified to accomplish this?
Below is the AFTER trigger I have used, I need to populate field by_user with the then current logged in @adminUser
CREATE TRIGGER qty_log_after_update
AFTER UPDATE
ON cataloginventory_stock_item FOR EACH ROW
BEGIN
INSERT INTO cataloginventory_stock_item_log
set
type = 'after',
product_id = old.product_id,
qty_before = new.qty,
qty_changed = (new.qty-old.qty),
created_at = now(),
by_user = @adminUser;
END;
Joell