feat(bridge): implement commitment form management and update auth tokens
Integrate commitment form functionality into the WordPress bridge and update authentication logic to use the Laravel-specific token. - Add AJAX functionality to fetch and display commitment forms in the order shortcode. - Implement client-side file upload handling for signed commitment forms. - Update `user-bridge.php` to use `ifnex_laravel_token` instead of `ifnex_api_token` for secure API requests. - Add Laravel migration to make file fields nullable in commitment forms to support incremental uploads.
This commit is contained in:
parent
2c924e2749
commit
d6f9ce5553
@ -1238,6 +1238,38 @@ jQuery(document).ready(function($) {
|
||||
success: function(r) { if (r.success) { alert('سفارش لغو شد.'); location.reload(); } else { alert('خطا: ' + r.data); btn.prop('disabled', false).text('❌ لغو'); } },
|
||||
error: function() { alert('خطا در ارتباط با سرور.'); btn.prop('disabled', false).text('❌ لغو'); }
|
||||
});
|
||||
|
||||
// بارگذاری تعهدنامهها
|
||||
$.ajax({
|
||||
url: ifnex_ajax.ajax_url,
|
||||
method: 'POST',
|
||||
data: { action: 'ifnex_get_commitment_forms', order_id: <?php echo $oid; ?>, nonce: ifnex_ajax.nonce },
|
||||
success: function(res) {
|
||||
if (res.success && res.data && res.data.length > 0) {
|
||||
var html = '';
|
||||
res.data.forEach(function(form) {
|
||||
var badge = form.upload_status === 'uploaded' ? '<span style="color:#10b981">✅ آپلود شده</span>'
|
||||
: form.upload_status === 'verified' ? '<span style="color:#10b981">✅ تأیید شده</span>'
|
||||
: '<span style="color:#94a3b8">⏳ آپلود نشده</span>';
|
||||
html += '<div style="border:1px solid #e2e8f0;border-radius:10px;padding:12px;margin-bottom:8px">';
|
||||
html += '<div style="display:flex;justify-content:space-between;align-items:start;gap:8px;flex-wrap:wrap">';
|
||||
html += '<div><strong>' + form.title + '</strong><br><small style="color:#64748b">' + (form.description || '') + '</small></div>';
|
||||
html += badge;
|
||||
html += '</div><div style="display:flex;gap:8px;margin-top:8px;flex-wrap:wrap">';
|
||||
if (form.file_url) html += '<a href="' + form.file_url + '" target="_blank" class="ifnex-btn ifnex-btn-sm ifnex-btn-info">📥 دانلود فرم</a>';
|
||||
if (form.uploaded_file_url) html += '<a href="' + form.uploaded_file_url + '" target="_blank" class="ifnex-btn ifnex-btn-sm ifnex-btn-success">📎 فایل آپلودشده</a>';
|
||||
html += '<label class="ifnex-btn ifnex-btn-sm ifnex-btn-warning" style="cursor:pointer">📤 آپلود امضاشده<input type="file" accept=".pdf,.jpg,.jpeg,.png" style="display:none" onchange="uploadCommitmentForm(<?php echo $oid; ?>,' + form.id + ',this)"></label>';
|
||||
html += '</div></div>';
|
||||
});
|
||||
$('#ifnex-commitment-forms').html(html);
|
||||
} else {
|
||||
$('#ifnex-commitment-forms').html('<p style="color:#94a3b8;font-size:13px">تعهدنامهای برای این سفارش موجود نیست.</p>');
|
||||
}
|
||||
},
|
||||
error: function() {
|
||||
$('#ifnex-commitment-forms').html('<p style="color:#ef4444;font-size:13px">خطا در بارگذاری تعهدنامهها.</p>');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
function uploadCommitmentForm(orderId, formId, input) {
|
||||
|
||||
@ -855,7 +855,7 @@ function ifnex_download_order_pdf_ajax() {
|
||||
$download_url = rtrim($api_url, '/') . "/customer/orders/{$order_id}/pdf/{$download_type}";
|
||||
|
||||
// ارسال درخواست به لاراول با توکن احراز هویت
|
||||
$token = get_user_meta($user_id, 'ifnex_api_token', true);
|
||||
$token = get_user_meta($user_id, 'ifnex_laravel_token', true);
|
||||
if (!$token) wp_send_json_error('توکن احراز هویت یافت نشد.');
|
||||
|
||||
$response = wp_remote_get($download_url, array(
|
||||
@ -908,7 +908,7 @@ function ifnex_get_commitment_forms_ajax() {
|
||||
$api_url = get_option('ifnex_api_url', 'http://localhost:8000/api/v1');
|
||||
$url = rtrim($api_url, '/') . "/customer/orders/{$order_id}/commitment-forms";
|
||||
|
||||
$token = get_user_meta($user_id, 'ifnex_api_token', true);
|
||||
$token = get_user_meta($user_id, 'ifnex_laravel_token', true);
|
||||
if (!$token) wp_send_json_error('توکن احراز هویت یافت نشد.');
|
||||
|
||||
$response = wp_remote_get($url, array(
|
||||
@ -973,7 +973,7 @@ function ifnex_upload_commitment_form_ajax() {
|
||||
$api_url = get_option('ifnex_api_url', 'http://localhost:8000/api/v1');
|
||||
$url = rtrim($api_url, '/') . "/customer/orders/{$order_id}/commitment-forms/{$form_id}/upload";
|
||||
|
||||
$token = get_user_meta($user_id, 'ifnex_api_token', true);
|
||||
$token = get_user_meta($user_id, 'ifnex_laravel_token', true);
|
||||
if (!$token) wp_send_json_error('توکن احراز هویت یافت نشد.');
|
||||
|
||||
$multipart = new CURLFile($upload['file'], $file['type'], $file['name']);
|
||||
|
||||
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
/**
|
||||
* file_type و file_size در commitment_forms NOT NULL بدون default بودن
|
||||
* و آپلود فایل شکست میخورد. nullable میشوند.
|
||||
*/
|
||||
return new class extends Migration
|
||||
{
|
||||
public function up(): void
|
||||
{
|
||||
if (DB::connection()->getDriverName() === 'sqlite') {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::statement("ALTER TABLE `commitment_forms` MODIFY COLUMN `file_type` VARCHAR(255) NULL");
|
||||
DB::statement("ALTER TABLE `commitment_forms` MODIFY COLUMN `file_size` BIGINT UNSIGNED NULL");
|
||||
}
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
if (DB::connection()->getDriverName() === 'sqlite') {
|
||||
return;
|
||||
}
|
||||
|
||||
DB::table('commitment_forms')->whereNull('file_type')->update(['file_type' => 'pdf']);
|
||||
DB::table('commitment_forms')->whereNull('file_size')->update(['file_size' => 0]);
|
||||
|
||||
DB::statement("ALTER TABLE `commitment_forms` MODIFY COLUMN `file_type` VARCHAR(255) NOT NULL");
|
||||
DB::statement("ALTER TABLE `commitment_forms` MODIFY COLUMN `file_size` BIGINT UNSIGNED NOT NULL");
|
||||
}
|
||||
};
|
||||
Loading…
Reference in New Issue
Block a user