Add is_required column to pp_shop_products_custom_fields table

This commit introduces a new column `is_required` to the `pp_shop_products_custom_fields` table. The column is of type TINYINT, cannot be null, and has a default value of 1. This change is intended to enhance the product custom fields by allowing the specification of whether a field is mandatory.
This commit is contained in:
2025-08-19 20:31:44 +02:00
parent 84333c1b59
commit ef15f16e18
16 changed files with 137 additions and 28 deletions

View File

@@ -663,12 +663,19 @@ ob_start();
<div>
<a href="#" class="btn btn-success" id="add_custom_field"><i class="fa fa-plus"></i> dodaj niestandardowe pole</a>
<div class="additional_fields">
<? if ( is_array( $this -> product['custom_fields'] ) ) : foreach ( $this -> product['custom_fields'] as $field ):?>
<div class="form-group row">
<? if ( is_array( $this->product['custom_fields'] ) ) : foreach ( $this->product['custom_fields'] as $field ):?>
<? $isRequired = !empty($field['is_required']); ?>
<div class="form-group row custom-field-row">
<label class="col-lg-4 control-label">Nazwa pola:</label>
<div class="col-lg-8">
<div class="input-group">
<input type="text" class="form-control" name="custom_field_name[]" value="<?= $field['name']; ?>">
<input type="text" class="form-control" name="custom_field_name[]" value="<?= htmlspecialchars($field['name']); ?>">
<span class="input-group-addon">
<label style="margin:0; font-weight:normal;">
<input type="checkbox" class="custom-field-required" <?= $isRequired ? 'checked' : '' ?> name="custom_field_required[]" />
wymagane
</label>
</span>
<span class="input-group-addon btn btn-info" onclick="remove_custom_filed( $( this ) );">usuń</span>
</div>
</div>
@@ -740,17 +747,23 @@ echo $grid->draw();
$(function() {
$( 'body' ).on( 'click', '#add_custom_field', function() {
$('body').on('click', '#add_custom_field', function() {
var html = '';
html += '<div class="form-group row">';
html += '<div class="form-group row custom-field-row">';
html += '<label class="col-lg-4 control-label">Nazwa pola:</label>';
html += '<div class="col-lg-8">';
html +='<div class="input-group">';
html += '<div class="input-group">';
html += '<input type="text" class="form-control" name="custom_field_name[]" value="">';
html += '<span class="input-group-addon">';
html += '<label style="margin:0; font-weight:normal;">';
html += '<input type="checkbox" class="custom-field-required" name="custom_field_required[]"> wymagane';
html += '</label>';
html += '</span>';
html += '<span class="input-group-addon btn btn-info" onclick="remove_custom_filed( $( this ) );">usuń</span>';
html += '</div>';
html += '</div>';
html += '</div>';
$( '.additional_fields' ).append( html );
$('.additional_fields').append(html);
});
$('body').on('click', '#product-preview', function() {