Problem with what looks like a hook problem with newly created module
Posted: Sat Jun 21, 2025 11:13 am
Using Phoenix 1.0.9.0 PHP8.0
I am trying to create a page that shows back in stock products. Nothing too complicated. I have the page created in the root folder of the site. I have added in a new database column in the products table which shows the date that stock was updated. If I manually enter a date in tis column for a product the item shows in the new page.
The problem I am having is with the hook which is located in includes.hooks/admin/catalog. The product updates but nothing is entered into the new column.
Here is the hook code that I am using. can anyone see why this does not work.
Can anyone see anything glaringly obvious with this as to why the database table will not be added to.
I am trying to create a page that shows back in stock products. Nothing too complicated. I have the page created in the root folder of the site. I have added in a new database column in the products table which shows the date that stock was updated. If I manually enter a date in tis column for a product the item shows in the new page.
The problem I am having is with the hook which is located in includes.hooks/admin/catalog. The product updates but nothing is entered into the new column.
Here is the hook code that I am using. can anyone see why this does not work.
Code: Select all
<?php
/*
Hook: Update products_restocked_date when stock increases from 0
*/
class hook_admin_catalog_back_in_stock {
public function __construct() {}
public function update() {
$this->checkRestock();
}
protected function checkRestock() {
global $db, $products_id;
if (isset($products_id, $_POST['products_quantity']) && is_numeric($products_id)) {
$new_quantity = (int)$_POST['products_quantity'];
$current = $db->query("SELECT products_quantity FROM products WHERE products_id = " . (int)$products_id)->fetch_assoc();
if ((int)$current['products_quantity'] == 0 && $new_quantity > 0) {
$db->query("UPDATE products SET products_restocked_date = NOW() WHERE products_id = " . (int)$products_id);
}
}
}
}