From 575d4aace0d542ad5b76d14bff04ab53042d3b7f Mon Sep 17 00:00:00 2001 From: Jacek Pyziak Date: Wed, 29 Jan 2025 22:53:41 +0100 Subject: [PATCH] Add minimum ROAS functionality to product management; implement saving and display in product listing --- .vscode/ftp-kr.sync.cache.json | 22 ++++++++++++++-------- autoload/controls/class.Products.php | 17 ++++++++++++++++- autoload/factory/class.Products.php | 16 ++++++++++------ templates/products/main_view.php | 23 +++++++++++++++++++++++ 4 files changed, 63 insertions(+), 15 deletions(-) diff --git a/.vscode/ftp-kr.sync.cache.json b/.vscode/ftp-kr.sync.cache.json index 0bb540b..bf3d61b 100644 --- a/.vscode/ftp-kr.sync.cache.json +++ b/.vscode/ftp-kr.sync.cache.json @@ -15,6 +15,12 @@ }, "autoload": { "controls": { + "class.Allegro.php": { + "type": "-", + "size": 6456, + "lmtime": 0, + "modified": false + }, "class.Api.php": { "type": "-", "size": 11018, @@ -29,14 +35,14 @@ }, "class.Cron.php": { "type": "-", - "size": 18166, + "size": 18168, "lmtime": 1734812301104, - "modified": false + "modified": true }, "class.Products.php": { "type": "-", - "size": 6779, - "lmtime": 1734386753537, + "size": 6777, + "lmtime": 1736159781898, "modified": false }, "class.Site.php": { @@ -67,8 +73,8 @@ }, "class.Products.php": { "type": "-", - "size": 3708, - "lmtime": 1734812409871, + "size": 4108, + "lmtime": 1736159665616, "modified": false }, "class.Users.php": { @@ -2712,8 +2718,8 @@ "products": { "main_view.php": { "type": "-", - "size": 6819, - "lmtime": 1734385931827, + "size": 6808, + "lmtime": 1736161322024, "modified": false }, "product_history.php": { diff --git a/autoload/controls/class.Products.php b/autoload/controls/class.Products.php index d7110a6..998c7ad 100644 --- a/autoload/controls/class.Products.php +++ b/autoload/controls/class.Products.php @@ -58,7 +58,8 @@ class Products \S::number_display( $row['cpc'] ), round( $row['conversions'], 2 ), \S::number_display( $row['conversions_value'] ), - $row['roas'], + $row['roas'] <= $row['min_roas'] ? '' . $row['roas'] . '' : $row['roas'], + '', '', '' ]; @@ -68,6 +69,20 @@ class Products exit; } + static public function save_min_roas() + { + $product_id = \S::get( 'product_id' ); + $min_roas = \S::get( 'min_roas' ); + + if ( \factory\Products::save_min_roas( $product_id, $min_roas ) ) + { + echo json_encode( [ 'status' => 'ok' ] ); + } + else + echo json_encode( [ 'status' => 'error' ] ); + exit; + } + static public function save_custom_label_4() { $product_id = \S::get( 'product_id' ); diff --git a/autoload/factory/class.Products.php b/autoload/factory/class.Products.php index f99ce93..24fcde2 100644 --- a/autoload/factory/class.Products.php +++ b/autoload/factory/class.Products.php @@ -2,16 +2,20 @@ namespace factory; class Products { + static public function save_min_roas( $product_id, $min_roas ) + { + global $mdb; + return $mdb -> update( 'products', [ 'min_roas' => $min_roas ], [ 'id' => $product_id ] ); + } + static public function get_products( $client_id, $search, $limit, $start, $order_name, $order_dir ) { global $mdb; if ( $search ) - return $mdb -> query( 'SELECT pt.*, p.offer_id FROM products_temp AS pt INNER JOIN products AS p ON p.id = pt.product_id WHERE client_id = \'' . $client_id . '\' AND pt.name LIKE \'%' . $search . '%\' ORDER BY ' . $order_name . ' ' . $order_dir . ' LIMIT ' . $start . ', ' . $limit ) -> fetchAll(); - else { - // echo 'SELECT pt.*, p.offer_id FROM products_temp AS pt INNER JOIN products AS p ON p.id = pt.product_id WHERE client_id = \'' . $client_id . '\' ORDER BY ' . $order_name . ' ' . $order_dir . ' LIMIT ' . $start . ', ' . $limit; - return $mdb -> query( 'SELECT pt.*, p.offer_id FROM products_temp AS pt INNER JOIN products AS p ON p.id = pt.product_id WHERE client_id = \'' . $client_id . '\' ORDER BY ' . $order_name . ' ' . $order_dir . ' LIMIT ' . $start . ', ' . $limit ) -> fetchAll(); - } + return $mdb -> query( 'SELECT pt.*, p.offer_id, p.min_roas FROM products_temp AS pt INNER JOIN products AS p ON p.id = pt.product_id WHERE client_id = \'' . $client_id . '\' AND ( pt.name LIKE \'%' . $search . '%\' OR offer_id = ' . (int)$search . ' ) ORDER BY ' . $order_name . ' ' . $order_dir . ' LIMIT ' . $start . ', ' . $limit ) -> fetchAll(); + else + return $mdb -> query( 'SELECT pt.*, p.offer_id, p.min_roas FROM products_temp AS pt INNER JOIN products AS p ON p.id = pt.product_id WHERE client_id = \'' . $client_id . '\' ORDER BY ' . $order_name . ' ' . $order_dir . ' LIMIT ' . $start . ', ' . $limit ) -> fetchAll(); } static public function get_records_total_products( $client_id, $search ) @@ -19,7 +23,7 @@ class Products global $mdb; if ( $search ) - return $mdb -> query( 'SELECT COUNT(0) FROM products_temp AS pt INNER JOIN products AS p ON p.id = pt.product_id WHERE client_id = \'' . $client_id . '\' AND pt.name LIKE \'%' . $search . '%\'' ) -> fetchColumn(); + return $mdb -> query( 'SELECT COUNT(0) FROM products_temp AS pt INNER JOIN products AS p ON p.id = pt.product_id WHERE client_id = \'' . $client_id . '\' AND ( pt.name LIKE \'%' . $search . '%\' OR offer_id = ' . (int)$search . ' )' ) -> fetchColumn(); else return $mdb -> query( 'SELECT COUNT(0) FROM products_temp AS pt INNER JOIN products AS p ON p.id = pt.product_id WHERE client_id = \'' . $client_id . '\'' ) -> fetchColumn(); } diff --git a/templates/products/main_view.php b/templates/products/main_view.php index 734cda3..c821c4a 100644 --- a/templates/products/main_view.php +++ b/templates/products/main_view.php @@ -37,6 +37,7 @@ Konw. Wartość konw. ROAS + Min. ROAS CL3 CL4 @@ -79,12 +80,34 @@ { width: 'auto', name: 'conversions' }, { width: 'auto', name: 'conversions_value', className: "dt-type-numeric" }, { width: 'auto', name: 'roas' }, + { width: '100px', name: 'min_roas' }, { width: 'auto', name: 'cl3', orderable: false }, { width: '200px', orderable: false }], order: [ [ 5, 'desc' ] ] }); }); + $( 'body' ).on( 'change', '.min_roas', function() + { + var input = $( this ); + var product_id = $( this ).attr( 'product_id' ); + var min_roas = $( this ).val(); + + input.addClass('saving'); + $.ajax({ + url: '/products/save_min_roas/', + type: 'POST', + data: { + product_id: product_id, + min_roas: min_roas + }, + success: function( response ) { + }, + complete: function() { + } + }); + }) + $( 'body' ).on( 'change', '.custom_label_4', function() { var input = $( this );