Add support for 'requires_note' property in products module

Introduced a new 'requires_note' property to the product object, including its initialization, serialization, and integration in relevant routes. This change ensures the property can be set, retrieved, and properly processed in API requests. It also updates logging to capture changes to this field when editing products.
This commit is contained in:
Jepp9350
2025-03-06 14:49:33 +01:00
parent 2038547d1c
commit 02a5b811bc
2 changed files with 11 additions and 0 deletions
@@ -45,6 +45,11 @@ class products_o extends db
* @var object_property
*/
public object_property $apply_category_discount;
/**
* Whether the product requires a note
* @var object_property
*/
public object_property $requires_note;
/**
* The timestamp of when the object was created
* @var object_property
@@ -88,6 +93,7 @@ class products_o extends db
$this->piktogram = new object_property($this->table, $this->id, 'piktogram', 'string', false);
$this->economic_product_id = new object_property($this->table, $this->id, 'economic_product_id', 'int', false);
$this->apply_category_discount = new object_property($this->table, $this->id, 'apply_category_discount', 'bool', false);
$this->requires_note = new object_property($this->table, $this->id, 'requires_note', 'bool', false);
$this->created_at = new object_property($this->table, $this->id, 'created_at', 'string', false);
$this->updated_at = new object_property($this->table, $this->id, 'updated_at', 'string', false);
}
@@ -175,6 +181,7 @@ class products_o extends db
'piktogram' => $this->piktogram->value(),
'economic_product_id' => $this->economic_product_id->value(),
'apply_category_discount' => (bool)$this->apply_category_discount->value(),
'requires_note' => (bool)$this->requires_note->value(),
'created_at' => (string)$this->created_at->value(),
'updated_at' => (string)$this->updated_at->value(),
];
@@ -26,6 +26,7 @@ class productsRoute
'piktogram' => (string)$product['piktogram'],
'economic_product_id' => (int)$product['economic_product_id'],
'apply_category_discount' => (int)$product['apply_category_discount'],
'requires_note' => (int)$product['requires_note'],
'created_at' => (string)$product['created_at'],
'updated_at' => (string)$product['updated_at'],
'addons' => (new product_options_o())->getProductOptions($product['id'])
@@ -185,6 +186,9 @@ class productsRoute
if (self::isParametersSet(['apply_category_discount'])) {
$product->apply_category_discount->set($response->getRequestParameter('apply_category_discount') ? 1 : 0);
}
if (self::isParametersSet(['requires_note'])) {
$product->requires_note->set($response->getRequestParameter('requires_note') ? 1 : 0);
}
(new logs_o())->add('products', 'global', 1, $user->id, 'EDIT_PRODUCT', 'Product id: ' . $id);
// Return a success message
$response->success(['message' => 'Product edited successfully']);