Enhance product management and coupon features
- Added styling for input group add-ons and additional fields in SCSS. - Updated shop coupon view to include a new column for usage count. - Display coupon code and amount in order details if applicable. - Improved product edit template to handle custom fields with required validation. - Modified product save logic to include custom field requirements. - Enhanced decimal normalization function for better input handling. - Implemented checkbox normalization for form submissions. - Updated custom fields in product templates to reflect required status. - Fixed URL for fetching changelog updates.
This commit is contained in:
@@ -485,6 +485,8 @@ jQuery( 'body' ).on( 'click', '#g-cancel', function() {
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
jQuery( 'body' ).on( 'click', '#g-save, #g-edit-save', function()
|
||||
{
|
||||
var back_url = jQuery( this ).attr( 'back_url' );
|
||||
@@ -534,6 +536,44 @@ jQuery( 'body' ).on( 'click', '#g-save, #g-edit-save', function()
|
||||
}
|
||||
});
|
||||
|
||||
/* === UNIWERSALNA NORMALIZACJA CHECKBOXÓW TABLICOWYCH ===
|
||||
Dla wszystkich input[type=checkbox] z name="coś[]":
|
||||
- jeśli wartości są typu boolean ('', '1', 'on', 'true', 'yes') → zbuduj pełną tablicę 1/0 w kolejności DOM,
|
||||
tak aby indeksy były ciągłe [0..N-1] nawet gdy część jest odznaczona.
|
||||
- jeśli to lista wyboru (np. categories[] z różnymi ID) → pozostaw jak z serializeArray (tylko zaznaczone).
|
||||
*/
|
||||
(function normalizeCheckboxArrays() {
|
||||
var $form = jQuery('#fg-' + gtable);
|
||||
if (!$form.length) return;
|
||||
|
||||
// zgrupuj checkboxy po pełnej nazwie (z [] na końcu)
|
||||
var groups = {};
|
||||
$form.find('input[type="checkbox"][name$="[]"]').each(function () {
|
||||
var n = this.name; // np. "required[]", "visible[]", "categories[]"
|
||||
(groups[n] = groups[n] || []).push(this);
|
||||
});
|
||||
|
||||
Object.keys(groups).forEach(function (nameWithBrackets) {
|
||||
var inputs = groups[nameWithBrackets];
|
||||
if (!inputs.length) return;
|
||||
|
||||
// sprawdź, czy wszystkie wartości wyglądają „booleanowo”
|
||||
var uniqVals = Array.from(new Set(inputs.map(function (el) {
|
||||
return (el.getAttribute('value') || '').toLowerCase();
|
||||
})));
|
||||
var boolSet = new Set(['', '1', 'on', 'true', 'yes']);
|
||||
var isBooleanLike = uniqVals.every(function (v) { return boolSet.has(v); });
|
||||
|
||||
if (isBooleanLike) {
|
||||
var baseKey = nameWithBrackets.replace(/\[\]$/, ''); // usuń [] → "required", "visible"
|
||||
// pełna tablica 1/0 w kolejności w formularzu
|
||||
formattedValues[baseKey] = inputs.map(function (el) { return el.checked ? '1' : '0'; });
|
||||
}
|
||||
// else: zostawiamy formattedValues tak jak już zbudowane z serializeArray()
|
||||
});
|
||||
})();
|
||||
|
||||
|
||||
var url = jQuery( this ).attr( 'url' );
|
||||
|
||||
if ( url !== '' )
|
||||
|
||||
Reference in New Issue
Block a user