Zaktualizuj metodę set_product_data w klasie Products, aby obsługiwała wstawianie nowych danych, jeśli produkt nie istnieje.

This commit is contained in:
2025-08-12 09:57:03 +02:00
parent c9f2f66457
commit a14512dd19
2 changed files with 8 additions and 3 deletions

View File

@@ -73,8 +73,8 @@
}, },
"class.Products.php": { "class.Products.php": {
"type": "-", "type": "-",
"size": 4561, "size": 4579,
"lmtime": 1744062307424, "lmtime": 1754740016569,
"modified": false "modified": false
}, },
"class.Users.php": { "class.Users.php": {

View File

@@ -49,7 +49,12 @@ class Products
static public function set_product_data( $product_id, $field, $value ) static public function set_product_data( $product_id, $field, $value )
{ {
global $mdb; global $mdb;
return $mdb -> update( 'products_data', [ $field => $value ], [ 'product_id' => $product_id ] );
if ( !$mdb -> count( 'products_data', [ 'product_id' => $product_id ] ) )
$result = $mdb -> insert( 'products_data', [ 'product_id' => $product_id, $field => $value ] );
else
$result = $mdb -> update( 'products_data', [ $field => $value ], [ 'product_id' => $product_id ] );
return $result;
} }
static public function get_product_history( $client_id, $product_id, $start, $limit ) static public function get_product_history( $client_id, $product_id, $start, $limit )