#### فایل `wpt-ajax.js` (اصلاح‌شده برای شماره صفحات کامل) ```javascript jQuery(document).ready(function ($) { // Loader function showLoader() { $('#wpt-loader').show(); } function hideLoader() { $('#wpt-loader').hide(); } // Search $('#wpt-search').on('input', _.debounce(function () { var term = $(this).val(); var paged = 1; showLoader(); $.ajax({ url: wpt_ajax.ajax_url, type: 'POST', data: { action: 'wpt_search', nonce: wpt_ajax.nonce, term: term, paged: paged, }, success: function (response) { hideLoader(); if (response.success) { updateTable(response.data, response.current_page, response.total_pages); } else { $('#wpt-product-table tbody').html('محصولی یافت نشد.'); $('.wpt-pagination').empty(); } }, error: function () { hideLoader(); alert('خطایی در ارتباط رخ داد. لطفاً دوباره تلاش کنید.'); }, }); }, 300)); // Autocomplete $('#wpt-search').autocomplete({ source: function (request, response) { $.ajax({ url: wpt_ajax.ajax_url, type: 'POST', data: { action: 'wpt_search_autocomplete', nonce: wpt_ajax.nonce, term: request.term, }, success: function (data) { response(data.data); }, }); }, minLength: 2, select: function (event, ui) { $('#wpt-search').val(ui.item.value).trigger('input'); }, }); // Pagination $(document).on('click', '.wpt-pagination a', function (e) { e.preventDefault(); var href = $(this).attr('href'); var paged = href.match(/wpt_page=(\d+)/) ? parseInt(href.match(/wpt_page=(\d+)/)[1]) : 1; var term = $('#wpt-search').val(); showLoader(); $.ajax({ url: wpt_ajax.ajax_url, type: 'POST', data: { action: 'wpt_search', nonce: wpt_ajax.nonce, term: term, paged: paged, }, success: function (response) { hideLoader(); if (response.success) { updateTable(response.data, response.current_page, response.total_pages); } else { $('#wpt-product-table tbody').html('محصولی یافت نشد.'); $('.wpt-pagination').empty(); } }, error: function () { hideLoader(); alert('خطایی در ارتباط رخ داد. لطفاً دوباره تلاش کنید.'); }, }); }); // Update Table function updateTable(data, current_page, total_pages) { var tbody = $('#wpt-product-table tbody'); tbody.empty(); $.each(data, function (index, product) { var row = '' + '' + product.title + '' + '' + (product.price ? wpt_ajax.wc_price_prefix + product.price + wpt_ajax.wc_price_suffix : '-') + '' + '' + (product.stock_status === 'instock' ? '
' + '' + '' + '' + '
' : 'ناموجود') + '' + '' + (product.stock_status === 'instock' ? '' : '') + '' + ''; tbody.append(row); }); var pagination = $('.wpt-pagination'); pagination.empty(); if (total_pages > 1) { var pagination_html = 'صفحه ' + current_page + ' از ' + total_pages + ''; pagination_html += ''; pagination.html(pagination_html); } } // تابع کمکی برای افزودن پارامتر به URL بدون از دست دادن پارامترهای موجود function addQueryArg(url, key, value) { var newurl = new URL(url); newurl.searchParams.set(key, value); return newurl.toString(); } // Quantity controls $(document).on('click', '.wpt-minus', function () { var input = $(this).siblings('.wpt-quantity'); var val = parseInt(input.val()); if (val > 0) { input.val(val - 1); } }); $(document).on('click', '.wpt-plus', function () { var input = $(this).siblings('.wpt-quantity'); var max = parseInt(input.attr('max')); var val = parseInt(input.val()); if (val < max) { input.val(val + 1); } }); // Add to cart $(document).on('click', '.wpt-add-to-cart', function () { var button = $(this); var product_id = button.data('product-id'); var quantity = button.closest('tr').find('.wpt-quantity').val(); if (quantity <= 0) { alert('لطفاً تعداد را انتخاب کنید.'); return; } showLoader(); $.ajax({ url: wpt_ajax.ajax_url, type: 'POST', data: { action: 'wpt_add_to_cart', product_id: product_id, quantity: quantity, nonce: wpt_ajax.nonce, }, success: function (response) { hideLoader(); if (response.success) { alert(response.data.message); $(document.body).trigger('wc_fragment_refresh'); window.location.href = response.data.cart_url; } else { alert(response.data.message || 'خطایی در افزودن به سبد خرید رخ داد.'); } }, error: function (xhr, status, error) { hideLoader(); console.log('AJAX Error:', xhr.responseText, status, error); // Log for debugging alert('خطایی در ارتباط رخ داد. لطفاً دوباره تلاش کنید.'); }, }); }); // Notify me $(document).on('click', '.wpt-notify-me', function () { var button = $(this); var product_id = button.data('product-id'); showLoader(); $.ajax({ url: wpt_ajax.ajax_url, type: 'POST', data: { action: 'wpt_notify_me', product_id: product_id, nonce: wpt_ajax.nonce, }, success: function (response) { hideLoader(); if (response.success) { alert(response.data.message); } else { alert(response.data.message || 'خطایی در ثبت درخواست رخ داد.'); } }, error: function () { hideLoader(); alert('خطایی در ارتباط رخ داد.'); }, }); }); }); قفل سوئیچی درب های پیکان (2تکه) نصیری - نیک پلاس

قفل سوئیچی درب های پیکان (2تکه) نصیری

شناسه محصول: 1427 دسته‌بندی: برچسب:
ویژگی های محصول:
  • تضمین بهترین قیمت بازار
  • اصالت کالاها از برترین برندها

2,596,000 ریال

12 در انبار

نقد و بررسی ها

نقد و بررسی وجود ندارد.

افزودن نقد و بررسی

نشانی ایمیل شما منتشر نخواهد شد. بخش‌های موردنیاز علامت‌گذاری شده‌اند *

1 of 5 stars 2 of 5 stars 3 of 5 stars 4 of 5 stars 5 of 5 stars

سبد خرید

سبد خرید شما خالی است.

ورود به سایت