diff --git a/wp-ingame-shop/wp-ingame-shop-pro.php b/wp-ingame-shop/wp-ingame-shop-pro.php index 0c150ec..c6b339b 100644 --- a/wp-ingame-shop/wp-ingame-shop-pro.php +++ b/wp-ingame-shop/wp-ingame-shop-pro.php @@ -246,6 +246,43 @@ add_action('wp_ajax_wis_save_cat_order', function() { wp_send_json_success('Reihenfolge gespeichert.'); }); +// AJAX: Angebot-Flag umschalten (Angebote-Übersicht) +add_action('wp_ajax_wis_angebote_toggle', function() { + check_ajax_referer('wis_angebote_nonce', 'nonce'); + if (!current_user_can('manage_options')) wp_send_json_error('Keine Berechtigung.'); + + global $wpdb; + $table = $wpdb->prefix . 'wis_items'; + $id = intval($_POST['id'] ?? 0); + $field = in_array($_POST['field'] ?? '', ['is_offer', 'is_daily_deal'], true) ? $_POST['field'] : null; + + if (!$id || !$field) wp_send_json_error('Ungültige Parameter.'); + + $current = (int) $wpdb->get_var($wpdb->prepare("SELECT $field FROM $table WHERE id = %d", $id)); + $new_val = $current ? 0 : 1; + + if ($field === 'is_daily_deal' && $new_val === 1) { + $wpdb->query("UPDATE $table SET is_daily_deal = 0 WHERE is_daily_deal = 1"); + } + $wpdb->update($table, [$field => $new_val], ['id' => $id]); + wp_send_json_success(['new_val' => $new_val]); +}); + +// AJAX: Angebotspreis direkt speichern (Angebote-Übersicht) +add_action('wp_ajax_wis_angebote_save_price', function() { + check_ajax_referer('wis_angebote_nonce', 'nonce'); + if (!current_user_can('manage_options')) wp_send_json_error('Keine Berechtigung.'); + + global $wpdb; + $table = $wpdb->prefix . 'wis_items'; + $id = intval($_POST['id'] ?? 0); + $offer_price = max(0, intval($_POST['offer_price'] ?? 0)); + + if (!$id) wp_send_json_error('Ungültige ID.'); + $wpdb->update($table, ['offer_price' => $offer_price], ['id' => $id]); + wp_send_json_success(['offer_price' => $offer_price]); +}); + // jQuery UI Sortable für die Kategorien-Seite laden add_action('admin_enqueue_scripts', function($hook) { if (isset($_GET['page']) && $_GET['page'] === 'wis_categories') { @@ -565,7 +602,16 @@ class WIS_Activator { $table = $wpdb->prefix . 'wis_items'; $discount = intval(get_option('wis_daily_deal_discount', 20)); - $wpdb->update($table, ['is_daily_deal' => 0], ['is_daily_deal' => 1]); + // Altes Daily-Deal-Item vollständig zurücksetzen: + // is_daily_deal, is_offer und offer_price werden alle auf 0 gesetzt, + // damit das Item nicht als normales Angebot mit gesenktem Preis hängen bleibt. + $wpdb->query( + "UPDATE $table + SET is_daily_deal = 0, + is_offer = 0, + offer_price = 0 + WHERE is_daily_deal = 1" + ); $item = $wpdb->get_row("SELECT * FROM $table WHERE status = 'publish' AND price > 0 ORDER BY RAND() LIMIT 1"); @@ -1544,6 +1590,7 @@ class WIS_Admin { add_submenu_page('wis_shop', 'Bestellungen', 'Bestellungen', 'manage_options', 'wis_orders', [self::class, 'page_orders']); add_submenu_page('wis_shop', 'Server', 'Server', 'manage_options', 'wis_servers', [self::class, 'page_servers']); add_submenu_page('wis_shop', 'Kategorien', 'Kategorien', 'manage_options', 'wis_categories', [self::class, 'page_categories']); + add_submenu_page('wis_shop', 'Angebote', 'Angebote', 'manage_options', 'wis_angebote', [self::class, 'page_angebote']); add_submenu_page('wis_shop', 'Gutscheine', 'Gutscheine', 'manage_options', 'wis_coupons', [self::class, 'page_coupons']); add_submenu_page('wis_shop', 'Analyse', 'Analyse', 'manage_options', 'wis_analyse', [self::class, 'page_analyse']); add_submenu_page('wis_shop', 'Top Spender', 'Top Spender', 'manage_options', 'wis_top_spenders', [self::class, 'page_top_spenders']); @@ -4987,6 +5034,243 @@ class WIS_Admin { prefix . 'wis_items'; + $currency = get_option('wis_currency_name', 'Coins'); + $nonce = wp_create_nonce('wis_angebote_nonce'); + + $filter = sanitize_text_field($_GET['filter'] ?? 'all'); + $search = sanitize_text_field($_GET['s'] ?? ''); + + $where = "1=1"; + if ($filter === 'offer') $where .= " AND is_offer = 1 AND is_daily_deal = 0"; + elseif ($filter === 'daily') $where .= " AND is_daily_deal = 1"; + elseif ($filter === 'none') $where .= " AND is_offer = 0 AND is_daily_deal = 0"; + else $where .= " AND (is_offer = 1 OR is_daily_deal = 1)"; + + if ($search !== '') { + $like = '%' . $wpdb->esc_like($search) . '%'; + $where .= $wpdb->prepare(" AND (name LIKE %s OR item_id LIKE %s)", $like, $like); + } + + if ($filter !== 'none') { + $where .= " AND status = 'publish'"; + } + + $items = $wpdb->get_results("SELECT * FROM $table WHERE $where ORDER BY is_daily_deal DESC, name ASC"); + $count_offer = (int) $wpdb->get_var("SELECT COUNT(*) FROM $table WHERE is_offer = 1 AND is_daily_deal = 0 AND status='publish'"); + $count_daily = (int) $wpdb->get_var("SELECT COUNT(*) FROM $table WHERE is_daily_deal = 1 AND status='publish'"); + $count_all = $count_offer + $count_daily; + + $img_base = get_option('wis_image_base_url', ''); + $base_url = admin_url('admin.php?page=wis_angebote'); + ?> +
+

🔥 Angebote Übersicht

+

Alle Items die als Angebot oder Daily Deal markiert sind – mit direkter Bearbeitung.

+ + + + + +
+ + + + + + ✕ Zurücksetzen + +
+ + +
+ 📭
+ Keine Items gefunden. +
+ + + + + + + + + + + + + + + + + + custom_image_url) + ? esc_url($item->custom_image_url) + : $img_base . str_replace(':', '_', $item->item_id) . '.png'; + + $normal_price = intval($item->price); + $offer_price = intval($item->offer_price); + $discount_pct = ($normal_price > 0 && $offer_price > 0 && $offer_price < $normal_price) + ? round((1 - $offer_price / $normal_price) * 100) : 0; + + $is_daily = intval($item->is_daily_deal); + $is_offer = intval($item->is_offer); + $row_bg = $is_daily ? '#fffbe6' : ($is_offer ? '#f0fff4' : ''); + ?> + "> + + + + + + + + + + + + +
BildNameItem-IDNormalpreisAngebotspreisRabatt🏷️ Angebot🎁 Daily DealAktion
+ <?php echo esc_attr($item->name); ?> + + name); ?> + 🎁 DAILY DEAL'; ?> + 🔥 ANGEBOT'; ?> + item_id); ?> +
+ + + +
+
+ 0): ?> + + −% + + + + + + + + + + ✏️ +
+

Item(s) gefunden.

+ + +
+ + + + +