| 1 |
jQuery(document).ready(function ($) { |
| 2 |
$(".confirm-order").click(function () { |
| 3 |
if (confirm("آیا از تایید سفارش اط� |
| 4 |
ینان دارید؟")) { |
| 5 |
var orderId = $(this).data("order"); |
| 6 |
var nonce = $(this).data("nonce"); |
| 7 |
|
| 8 |
$.ajax({ |
| 9 |
url: ajaxurl, |
| 10 |
method: "POST", |
| 11 |
data: { |
| 12 |
action: "confirm_basalam_order", |
| 13 |
order_id: orderId, |
| 14 |
_wpnonce: nonce, |
| 15 |
}, |
| 16 |
success: function (data) { |
| 17 |
if (data.success) { |
| 18 |
window.BasalamToast.success(data.data?.message || "ع� |
| 19 |
لیات با � |
| 20 |
وفقیت انجا� |
| 21 |
شد."); |
| 22 |
} else { |
| 23 |
window.BasalamToast.error(data.data?.message || "خطایی رخ داده است."); |
| 24 |
} |
| 25 |
location.reload(); |
| 26 |
}, |
| 27 |
error: function () { |
| 28 |
window.BasalamToast.error("خطایی در ارسال درخواست رخ داد."); |
| 29 |
location.reload(); |
| 30 |
}, |
| 31 |
}); |
| 32 |
} |
| 33 |
}); |
| 34 |
|
| 35 |
$(".cancel-order").click(function () { |
| 36 |
var orderId = $(this).data("order"); |
| 37 |
var nonce = $(this).data("nonce"); |
| 38 |
|
| 39 |
$("#cancel-order-popup").show(); |
| 40 |
}); |
| 41 |
|
| 42 |
$("#cancel-cancel-order").click(function () { |
| 43 |
$("#cancel-order-popup").hide(); |
| 44 |
$("#cancel-reason").val(""); |
| 45 |
$("#cancel-description").val(""); |
| 46 |
}); |
| 47 |
|
| 48 |
$("#submit-cancel-order").click(function () { |
| 49 |
var orderId = $(this).data("order"); |
| 50 |
var nonce = $(this).data("nonce"); |
| 51 |
var reasonId = $("#cancel-reason").val(); |
| 52 |
var description = $("#cancel-description").val(); |
| 53 |
|
| 54 |
if (!reasonId) { |
| 55 |
window.BasalamToast.warning("لطفاً دلیل لغو سفارش را انتخاب کنید."); |
| 56 |
return; |
| 57 |
} |
| 58 |
|
| 59 |
if (!description.trim()) { |
| 60 |
window.BasalamToast.warning("لطفاً توضیحات را وارد کنید."); |
| 61 |
return; |
| 62 |
} |
| 63 |
|
| 64 |
$.ajax({ |
| 65 |
url: ajaxurl, |
| 66 |
type: "POST", |
| 67 |
data: { |
| 68 |
action: "cancel_basalam_order", |
| 69 |
order_id: orderId, |
| 70 |
reason_id: reasonId, |
| 71 |
description: description, |
| 72 |
_wpnonce: nonce, |
| 73 |
}, |
| 74 |
success: function (data) { |
| 75 |
if (data.success) { |
| 76 |
window.BasalamToast.success(data.data?.message || "ع� |
| 77 |
لیات با � |
| 78 |
وفقیت انجا� |
| 79 |
شد."); |
| 80 |
} else { |
| 81 |
window.BasalamToast.error(data.data?.message || "خطایی رخ داده است."); |
| 82 |
console.error("Server error:", data); |
| 83 |
} |
| 84 |
location.reload(); |
| 85 |
}, |
| 86 |
error: function () { |
| 87 |
window.BasalamToast.error("خطایی در ارسال درخواست رخ داد."); |
| 88 |
}, |
| 89 |
}); |
| 90 |
}); |
| 91 |
|
| 92 |
$(".request-cancel-order").click(function () { |
| 93 |
var orderId = $(this).data("order"); |
| 94 |
var nonce = $(this).data("nonce"); |
| 95 |
|
| 96 |
$("#request-cancel-order-popup").show(); |
| 97 |
|
| 98 |
$("#submit-request-cancel-order") |
| 99 |
.data("order", orderId) |
| 100 |
.data("nonce", nonce); |
| 101 |
}); |
| 102 |
|
| 103 |
$("#cancel-request-cancel-order").click(function () { |
| 104 |
$("#request-cancel-order-popup").hide(); |
| 105 |
$("#request-cancel-description").val(""); |
| 106 |
}); |
| 107 |
|
| 108 |
$("#submit-request-cancel-order").click(function () { |
| 109 |
var orderId = $(this).data("order"); |
| 110 |
var nonce = $(this).data("nonce"); |
| 111 |
var description = $("#request-cancel-description").val(); |
| 112 |
|
| 113 |
if (!description.trim()) { |
| 114 |
window.BasalamToast.warning("لطفاً توضیحات را وارد کنید."); |
| 115 |
return; |
| 116 |
} |
| 117 |
|
| 118 |
$.ajax({ |
| 119 |
url: ajaxurl, |
| 120 |
type: "POST", |
| 121 |
data: { |
| 122 |
action: "request_cancel_basalam_order", |
| 123 |
order_id: orderId, |
| 124 |
description: description, |
| 125 |
_wpnonce: nonce, |
| 126 |
}, |
| 127 |
success: function (response) { |
| 128 |
if (response.success) { |
| 129 |
window.BasalamToast.success( |
| 130 |
response.data?.message || "درخواست لغو سفارش با � |
| 131 |
وفقیت ارسال شد." |
| 132 |
); |
| 133 |
location.reload(); |
| 134 |
} else { |
| 135 |
window.BasalamToast.error(response.data?.message || "خطایی رخ داده است"); |
| 136 |
} |
| 137 |
}, |
| 138 |
error: function () { |
| 139 |
window.BasalamToast.error("خطایی در ارسال درخواست رخ داد."); |
| 140 |
}, |
| 141 |
}); |
| 142 |
}); |
| 143 |
|
| 144 |
$(".save-tracking-code").click(function () { |
| 145 |
var orderId = $(this).data("order"); |
| 146 |
var trackingCode = $("#order_tracking_code").val(); |
| 147 |
var phoneNumber = $("#phone_number").val(); |
| 148 |
|
| 149 |
if (!trackingCode || !phoneNumber) { |
| 150 |
window.BasalamToast.warning("لطفاً کد رهگیری و ش� |
| 151 |
اره تلفن را وارد کنید."); |
| 152 |
return; |
| 153 |
} |
| 154 |
|
| 155 |
$("#shipping-method-popup").show(); |
| 156 |
}); |
| 157 |
|
| 158 |
$("#cancel-shipping-method").click(function () { |
| 159 |
$("#shipping-method-popup").hide(); |
| 160 |
}); |
| 161 |
|
| 162 |
$("#submit-shipping-method").click(function (e) { |
| 163 |
e.preventDefault(); |
| 164 |
var orderId = $(".save-tracking-code").data("order"); |
| 165 |
var trackingCode = $("#order_tracking_code").val(); |
| 166 |
var phoneNumber = $("#phone_number").val(); |
| 167 |
var shippingMethod = $("#shipping-method").val(); |
| 168 |
var nonce = $(this).data("nonce"); |
| 169 |
|
| 170 |
if (!shippingMethod) { |
| 171 |
window.BasalamToast.warning("لطفاً روش ارسال را انتخاب کنید."); |
| 172 |
return; |
| 173 |
} |
| 174 |
|
| 175 |
$.ajax({ |
| 176 |
url: ajaxurl, |
| 177 |
method: "POST", |
| 178 |
data: { |
| 179 |
action: "tracking_code_basalam_order", |
| 180 |
order_id: orderId, |
| 181 |
tracking_code: trackingCode, |
| 182 |
phone_number: phoneNumber, |
| 183 |
shipping_method: shippingMethod, |
| 184 |
_wpnonce: nonce, |
| 185 |
}, |
| 186 |
success: function (data) { |
| 187 |
if (data.success) { |
| 188 |
window.BasalamToast.success(data.data?.message || "ع� |
| 189 |
لیات با � |
| 190 |
وفقیت انجا� |
| 191 |
شد."); |
| 192 |
} else { |
| 193 |
window.BasalamToast.error(data.data?.message || "خطایی رخ داده است."); |
| 194 |
console.error("Server error:", data); |
| 195 |
} |
| 196 |
location.reload(); |
| 197 |
}, |
| 198 |
error: function (xhr) { |
| 199 |
let errorMsg = "خطایی در ارسال درخواست رخ داد."; |
| 200 |
try { |
| 201 |
const json = JSON.parse(xhr.responseText); |
| 202 |
errorMsg = json.data?.message || errorMsg; |
| 203 |
} catch (e) { |
| 204 |
console.error("JSON parse error:", e); |
| 205 |
} |
| 206 |
window.BasalamToast.error(errorMsg); |
| 207 |
console.error("AJAX error:", xhr); |
| 208 |
location.reload(); |
| 209 |
}, |
| 210 |
}); |
| 211 |
}); |
| 212 |
|
| 213 |
$(".request-delay").click(function () { |
| 214 |
$("#delay-request-popup").show(); |
| 215 |
}); |
| 216 |
|
| 217 |
$("#cancel-delay-request").click(function () { |
| 218 |
$("#delay-request-popup").hide(); |
| 219 |
}); |
| 220 |
|
| 221 |
$("#submit-delay-request").click(function () { |
| 222 |
event.preventDefault(); |
| 223 |
var orderId = $(".request-delay").data("order"); |
| 224 |
var description = $("#delay-description").val(); |
| 225 |
var postponeDays = $("#postpone-days").val(); |
| 226 |
var nonce = $(this).data("nonce"); |
| 227 |
|
| 228 |
if (!description || !postponeDays) { |
| 229 |
window.BasalamToast.warning("لطفاً توضیحات و تعداد روزهای تاخیر را وارد کنید."); |
| 230 |
return; |
| 231 |
} |
| 232 |
|
| 233 |
$.ajax({ |
| 234 |
url: ajaxurl, |
| 235 |
method: "POST", |
| 236 |
data: { |
| 237 |
action: "delay_req_basalam_order", |
| 238 |
order_id: orderId, |
| 239 |
description: description, |
| 240 |
postpone_days: postponeDays, |
| 241 |
_wpnonce: nonce, |
| 242 |
}, |
| 243 |
success: function (data) { |
| 244 |
if (data.success) { |
| 245 |
window.BasalamToast.success(data.data?.message || "ع� |
| 246 |
لیات با � |
| 247 |
وفقیت انجا� |
| 248 |
شد."); |
| 249 |
} else { |
| 250 |
window.BasalamToast.error(data.data?.message || "خطایی رخ داده است."); |
| 251 |
} |
| 252 |
location.reload(); |
| 253 |
}, |
| 254 |
error: function (xhr) { |
| 255 |
let errorMsg = "خطایی در ارسال درخواست رخ داد."; |
| 256 |
try { |
| 257 |
const json = JSON.parse(xhr.responseText); |
| 258 |
errorMsg = json.data?.message || errorMsg; |
| 259 |
} catch (e) {} |
| 260 |
window.BasalamToast.error(errorMsg); |
| 261 |
location.reload(); |
| 262 |
}, |
| 263 |
}); |
| 264 |
}); |
| 265 |
}); |
| 266 |
|