| 1 |
function openModal() { |
| 2 |
document.getElementById("Basalam-connect-modal").style.display = "block"; |
| 3 |
} |
| 4 |
|
| 5 |
function closeModal() { |
| 6 |
document.getElementById("Basalam-connect-modal").style.display = "none"; |
| 7 |
} |
| 8 |
|
| 9 |
jQuery(document).ready(function ($) { |
| 10 |
$("#basalam-search-btn").on("click", function (event) { |
| 11 |
event.preventDefault(); |
| 12 |
var searchTerm = $("#basalam-product-search").val(); |
| 13 |
var wooProductId = $("#Basalam-woo-product-id").val(); |
| 14 |
|
| 15 |
if (searchTerm.length > 0) { |
| 16 |
$("#basalam-product-results").html("<p>در حال جستجو...</p>"); |
| 17 |
$.ajax({ |
| 18 |
url: ajaxurl, |
| 19 |
type: "POST", |
| 20 |
data: { |
| 21 |
action: "basalam_search_products", |
| 22 |
title: searchTerm, |
| 23 |
woo_product_id: wooProductId, |
| 24 |
_wpnonce: $("#basalam-search-products-nonce").val(), |
| 25 |
}, |
| 26 |
success: function (response) { |
| 27 |
$("#basalam-product-results").html(response); |
| 28 |
}, |
| 29 |
error: function () { |
| 30 |
$("#basalam-product-results").html(error); |
| 31 |
}, |
| 32 |
}); |
| 33 |
} else { |
| 34 |
window.BasalamToast.warning("لطفاً عنوان � |
| 35 |
حصول را وارد کنید."); |
| 36 |
} |
| 37 |
}); |
| 38 |
|
| 39 |
$(document).on("click", ".basalam-connect-btn", function () { |
| 40 |
const $btn = $(this); |
| 41 |
const BasalamProductId = $btn.data("basalam-product-id"); |
| 42 |
const wooProductId = $btn.data("woo-product-id"); |
| 43 |
var nonce = $btn.data("_wpnonce"); |
| 44 |
if (!BasalamProductId || !wooProductId) { |
| 45 |
window.BasalamToast.error("� |
| 46 |
شخصات � |
| 47 |
حصول ناقص است."); |
| 48 |
return; |
| 49 |
} |
| 50 |
|
| 51 |
$btn.text("اتصال...").prop("disabled", true); |
| 52 |
|
| 53 |
$.ajax({ |
| 54 |
url: ajaxurl, |
| 55 |
method: "POST", |
| 56 |
data: { |
| 57 |
action: "basalam_connect_product", |
| 58 |
woo_product_id: wooProductId, |
| 59 |
basalam_product_id: BasalamProductId, |
| 60 |
_wpnonce: nonce, |
| 61 |
}, |
| 62 |
success: function (data) { |
| 63 |
if (data.success) { |
| 64 |
window.BasalamToast.success(data.data?.message || "ع� |
| 65 |
لیات با � |
| 66 |
وفقیت انجا� |
| 67 |
شد."); |
| 68 |
location.reload(); |
| 69 |
} else { |
| 70 |
window.BasalamToast.error(data.data?.message || "خطایی رخ داده است."); |
| 71 |
} |
| 72 |
}, |
| 73 |
error: function (xhr) { |
| 74 |
let response; |
| 75 |
try { |
| 76 |
response = JSON.parse(xhr.responseText); |
| 77 |
} catch (e) { |
| 78 |
response = {}; |
| 79 |
} |
| 80 |
window.BasalamToast.error(response?.data?.message || "خطایی رخ داده است."); |
| 81 |
}, |
| 82 |
}); |
| 83 |
}); |
| 84 |
}); |
| 85 |
|