feat: add order form template HTML.
This commit is contained in:
@@ -1877,7 +1877,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
|
|
||||||
// Функция заполнения формы данными комплекта
|
// Функция заполнения формы данными комплекта
|
||||||
function fillFormWithKit(form, kitData) {
|
function fillFormWithKit(form, kitData) {
|
||||||
if (!kitData || !kitData.kit_id || !kitData.kit_name || !kitData.kit_price) {
|
if (!kitData || !kitData.kit_id || !kitData.kit_name || kitData.kit_price === undefined) {
|
||||||
console.error('Invalid kit data:', kitData);
|
console.error('Invalid kit data:', kitData);
|
||||||
alert('Ошибка: неверные данные комплекта');
|
alert('Ошибка: неверные данные комплекта');
|
||||||
return;
|
return;
|
||||||
@@ -1887,6 +1887,11 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
const kitSelect = form.querySelector('.select2-order-item');
|
const kitSelect = form.querySelector('.select2-order-item');
|
||||||
const quantityInput = form.querySelector('[name$="-quantity"]');
|
const quantityInput = form.querySelector('[name$="-quantity"]');
|
||||||
const priceInput = form.querySelector('[name$="-price"]');
|
const priceInput = form.querySelector('[name$="-price"]');
|
||||||
|
|
||||||
|
// ВАЖНО: Находим скрытые поля для product и product_kit
|
||||||
|
const productField = form.querySelector('[name$="-product"]');
|
||||||
|
const kitField = form.querySelector('[name$="-product_kit"]');
|
||||||
|
const isCustomPriceField = form.querySelector('[name$="-is_custom_price"]');
|
||||||
|
|
||||||
if (!kitSelect) {
|
if (!kitSelect) {
|
||||||
console.error('Kit select not found in form');
|
console.error('Kit select not found in form');
|
||||||
@@ -1895,7 +1900,17 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
|
|
||||||
// Используем Select2 API для добавления опции
|
// Используем Select2 API для добавления опции
|
||||||
const newOption = new Option(kitData.kit_name, `kit_${kitData.kit_id}`, true, true);
|
const newOption = new Option(kitData.kit_name, `kit_${kitData.kit_id}`, true, true);
|
||||||
$(kitSelect).append(newOption);
|
$(kitSelect).append(newOption).trigger('change');
|
||||||
|
|
||||||
|
// КЛЮЧЕВОЕ ИСПРАВЛЕНИЕ: Устанавливаем скрытые поля напрямую
|
||||||
|
// Это комплект, поэтому очищаем product и устанавливаем product_kit
|
||||||
|
if (productField) productField.value = '';
|
||||||
|
if (kitField) kitField.value = kitData.kit_id;
|
||||||
|
|
||||||
|
console.log('[fillFormWithKit] Установлены скрытые поля:', {
|
||||||
|
product: productField ? productField.value : 'not found',
|
||||||
|
product_kit: kitField ? kitField.value : 'not found'
|
||||||
|
});
|
||||||
|
|
||||||
// Устанавливаем количество и цену
|
// Устанавливаем количество и цену
|
||||||
if (quantityInput) quantityInput.value = '1';
|
if (quantityInput) quantityInput.value = '1';
|
||||||
@@ -1903,6 +1918,22 @@ document.addEventListener('DOMContentLoaded', function() {
|
|||||||
priceInput.value = kitData.kit_price;
|
priceInput.value = kitData.kit_price;
|
||||||
priceInput.dataset.originalPrice = kitData.kit_price;
|
priceInput.dataset.originalPrice = kitData.kit_price;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Сбрасываем флаг кастомной цены
|
||||||
|
if (isCustomPriceField) {
|
||||||
|
isCustomPriceField.value = 'false';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Скрываем единицы продажи для комплектов (у комплектов их нет)
|
||||||
|
const salesUnitContainer = form.querySelector('.sales-unit-container');
|
||||||
|
if (salesUnitContainer) {
|
||||||
|
salesUnitContainer.style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Обновляем сумму товаров
|
||||||
|
if (typeof window.updateOrderItemsTotal === 'function') {
|
||||||
|
window.updateOrderItemsTotal();
|
||||||
|
}
|
||||||
|
|
||||||
// Явно вызываем событие select2:select для запуска автосохранения
|
// Явно вызываем событие select2:select для запуска автосохранения
|
||||||
$(kitSelect).trigger('select2:select', {
|
$(kitSelect).trigger('select2:select', {
|
||||||
|
|||||||
Reference in New Issue
Block a user