' . __('Napaka: Tabela za produkte ne obstaja. Prosimo, deaktivirajte in ponovno aktivirajte plugin.', 'wheel-of-fortune') . '
';
return;
}
if ($wheel_id > 0 && $product_id > 0 && $spins_per_purchase > 0) {
// Preveri, ali kolo obstaja
$wheel_exists = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM $wheels_table WHERE id = %d", $wheel_id));
error_log("Wheel exists: " . $wheel_exists);
if (!$wheel_exists) {
error_log("ERROR: Kolo z ID $wheel_id ne obstaja!");
echo '
' . __('Napaka: Izbrano kolo ne obstaja.', 'wheel-of-fortune') . '
';
return;
}
// Preveri, ali produkt obstaja
if (class_exists('WooCommerce')) {
$product = wc_get_product($product_id);
if (!$product) {
error_log("ERROR: Produkt z ID $product_id ne obstaja!");
echo '
' . __('Napaka: Izbrani produkt ne obstaja.', 'wheel-of-fortune') . '
';
return;
}
}
$data = [
'wheel_id' => $wheel_id,
'product_id' => $product_id,
'spins_per_purchase' => $spins_per_purchase
];
error_log("Data to insert: " . print_r($data, true));
// Preveri, ali je produkt že povezan s tem kolesom
$existing_product = $wpdb->get_var($wpdb->prepare(
"SELECT id FROM $wheel_products_table WHERE wheel_id = %d AND product_id = %d",
$wheel_id, $product_id
));
if ($existing_product) {
error_log("Product already exists for this wheel, updating...");
} else {
error_log("Adding new product to wheel...");
}
$result = $wpdb->replace(
$wheel_products_table,
$data,
['%d', '%d', '%d']
);
error_log("SQL result: " . $result);
error_log("Last SQL query: " . $wpdb->last_query);
error_log("Last SQL error: " . $wpdb->last_error);
if ($result !== false) {
echo '
' . __('Produkt je bil uspešno dodan ali posodobljen.', 'wheel-of-fortune') . '
' . __('Produkt je bil izbrisan.', 'wheel-of-fortune') . '
';
}
}
}
global $wpdb;
$wheels_table = $wpdb->prefix . 'wof_wheels';
$prizes_table = $wpdb->prefix . 'wheel_prizes';
// Get the current wheel ID from URL
$wheel_id = isset($_GET['wheel_id']) ? intval($_GET['wheel_id']) : 0;
// Fetch wheel data
$wheel = $wpdb->get_row($wpdb->prepare("SELECT * FROM $wheels_table WHERE id = %d", $wheel_id), ARRAY_A);
if (!$wheel) {
echo '
' . __('Wheel not found.', 'wheel-of-fortune') . '
';
return;
}
// Fetch prizes for this specific wheel
$prizes = $wpdb->get_results($wpdb->prepare("SELECT * FROM $prizes_table WHERE wheel_id = %d ORDER BY id ASC", $wheel_id), ARRAY_A);
$total_probability = array_sum(wp_list_pluck($prizes, 'probability'));
// Fetch povezane produkte za to kolo
$wheel_products_table = $wpdb->prefix . 'wheel_of_fortune_products';
$products = $wpdb->get_results($wpdb->prepare("SELECT * FROM $wheel_products_table WHERE wheel_id = %d", $wheel_id), ARRAY_A);
// Pridobi vse WooCommerce produkte za dropdown
if (class_exists('WooCommerce')) {
$all_products = wc_get_products(array('limit' => -1, 'status' => 'publish'));
} else {
$all_products = array();
}
?>