diff --git a/wp-content/themes/cosmopet/global-functions/multilang-functions.php b/wp-content/themes/cosmopet/global-functions/multilang-functions.php index f79985d..27f112c 100644 --- a/wp-content/themes/cosmopet/global-functions/multilang-functions.php +++ b/wp-content/themes/cosmopet/global-functions/multilang-functions.php @@ -1713,4 +1713,11 @@ add_action('init', function () { pll_register_string('Редактировать питомца', 'Редактировать питомца', 'Profile'); + pll_register_string('Адрес доставки успешно обновлён.', 'Адрес доставки успешно обновлён.', 'profile-sub-single'); + pll_register_string('Ошибка безопасности. Обновите страницу.', 'Ошибка безопасности. Обновите страницу.', 'profile-sub-single'); + pll_register_string('Вы не авторизованы.', 'Вы не авторизованы.', 'profile-sub-single'); + pll_register_string('Недостаточно данных.', 'Недостаточно данных.', 'profile-sub-single'); + pll_register_string('Подписка не найдена или не принадлежит вам.', 'Подписка не найдена или не принадлежит вам.', 'profile-sub-single'); + pll_register_string('Адрес доставки', 'Адрес доставки', 'profile-sub-single'); + pll_register_string('Город', 'Город', 'profile-sub-single'); }); \ No newline at end of file diff --git a/wp-content/themes/cosmopet/modules/profile/assets/js/profile.js b/wp-content/themes/cosmopet/modules/profile/assets/js/profile.js index 0033817..619f6bf 100644 --- a/wp-content/themes/cosmopet/modules/profile/assets/js/profile.js +++ b/wp-content/themes/cosmopet/modules/profile/assets/js/profile.js @@ -65,10 +65,10 @@ jQuery(document).ready(function ($) { var $form = $(this); var $message = $form.find('.form-message'); var subscriptionId = $form.data('subscription-id'); - var address = $form.find('input[name="address"]').val(); + var address = $form.find('input[name="address_1"]').val(); var comment = $form.find('textarea[name="comment"]').val(); var nonce = $form.find('input[name="address_nonce"]').val(); - + var city = $form.find('input[name="city"]').val(); $message.hide().removeClass('success error').empty(); $.ajax({ @@ -79,6 +79,7 @@ jQuery(document).ready(function ($) { subscription_id: subscriptionId, address: address, comment: comment, + city: city, address_nonce: nonce }, success: function (response) { diff --git a/wp-content/themes/cosmopet/modules/profile/module-ajax-controller.php b/wp-content/themes/cosmopet/modules/profile/module-ajax-controller.php index 6d9fde9..2b2cc89 100644 --- a/wp-content/themes/cosmopet/modules/profile/module-ajax-controller.php +++ b/wp-content/themes/cosmopet/modules/profile/module-ajax-controller.php @@ -132,3 +132,51 @@ function ajax_edit_pet() { add_action('wp_ajax_edit_pet', 'ajax_edit_pet'); add_action('wp_ajax_nopriv_edit_pet', 'ajax_edit_pet'); + + +add_action('wp_ajax_update_subscription_address', 'handle_subscription_address_update'); +add_action('wp_ajax_nopriv_update_subscription_address', 'handle_subscription_address_update'); + +function handle_subscription_address_update() { + error_log('=== [AJAX] Запуск update_subscription_address ==='); + + error_log('[AJAX] Nonce из формы: ' . ($_POST['address_nonce'] ?? 'none')); + error_log('[AJAX] Проверка nonce: ' . (wp_verify_nonce($_POST['address_nonce'], 'update_subscription_address') ? 'OK' : 'FAIL')); + + if (!isset($_POST['address_nonce']) || !wp_verify_nonce($_POST['address_nonce'], 'update_subscription_address')) { + error_log('[AJAX] Ошибка nonce'); + wp_send_json_error(['message' => pll__('Ошибка безопасности. Обновите страницу.')]); + } + + if (!is_user_logged_in()) { + error_log('[AJAX] Пользователь не авторизован'); + wp_send_json_error(['message' => pll__('Вы не авторизованы.')]); + } + + $subscription_id = intval($_POST['subscription_id'] ?? 0); + $address_1 = sanitize_text_field($_POST['address'] ?? ''); + $city = sanitize_text_field($_POST['city'] ?? ''); + $comment = sanitize_textarea_field($_POST['comment'] ?? ''); + + error_log("[AJAX] Получено: ID={$subscription_id}, Address={$address_1}, City={$city}, Comment={$comment}"); + + if (!$subscription_id || empty($address_1)) { + wp_send_json_error(['message' => pll__('Недостаточно данных.')]); + } + + $subscription = wcs_get_subscription($subscription_id); + + if (!$subscription || $subscription->get_user_id() !== get_current_user_id()) { + wp_send_json_error(['message' => pll__('Подписка не найдена или не принадлежит вам.')]); + } + + update_post_meta($subscription_id, '_shipping_address_1', $address_1); + update_post_meta($subscription_id, '_shipping_city', $city); + update_post_meta($subscription_id, '_shipping_comment', $comment); + + $subscription->set_customer_note($comment); + $subscription->save(); + + error_log('[AJAX] Подписка обновлена: ' . $subscription_id); + wp_send_json_success(['message' => pll__('Адрес доставки успешно обновлён.')]); +} diff --git a/wp-content/themes/cosmopet/templates/profile/profile-subs-single.twig b/wp-content/themes/cosmopet/templates/profile/profile-subs-single.twig index ff1f0ee..5c603cd 100644 --- a/wp-content/themes/cosmopet/templates/profile/profile-subs-single.twig +++ b/wp-content/themes/cosmopet/templates/profile/profile-subs-single.twig @@ -94,12 +94,21 @@