NEW. Dodanie opcji typ pola własnego

This commit is contained in:
Roman Pyrih
2026-01-20 11:33:18 +01:00
parent 5b02b65665
commit e31074506c
7 changed files with 114 additions and 48 deletions

View File

@@ -670,20 +670,36 @@ ob_start();
</div>
<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">
<div class="additional_fields pt-3">
<? 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">
<div class="form-group row custom-field-row bg-white p-4">
<div class="form-group row">
<label class="col-sm-3 control-label">Nazwa pola:</label>
<div class="col-sm-9">
<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>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 control-label">Rodzaj pola:</label>
<div class="col-sm-9">
<select class="form-control" name="custom_field_type[]">
<option value="text" <?= ($field['type'] ?? 'text') === 'text' ? 'selected' : '' ?>>Tekst</option>
<option value="image" <?= ($field['type'] ?? '') === 'image' ? 'selected' : '' ?>>Obrazek</option>
</select>
</div>
</div>
<div class="form-group row">
<label class="col-sm-3 control-label">Status pola:</label>
<div class="col-sm-9">
<label style="margin:0; font-weight:normal;" class="d-flex align-items-center mt-3">
<input type="checkbox" class="custom-field-required mt-0 mr-3" <?= $isRequired ? 'checked' : '' ?> name="custom_field_required[]" />
wymagane
</label>
</div>
</div>
<div class="form-group row">
<div class="col-sm-12 text-right">
<span class="input-group-addon btn btn-info" onclick="remove_custom_filed( $( this ) );">usuń</span>
</div>
</div>
@@ -803,20 +819,36 @@ echo $grid->draw();
$('body').on('click', '#add_custom_field', function() {
var html = '';
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 += '<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 += '<div class="form-group row custom-field-row bg-white p-4">';
html += '<div class="form-group row">';
html += '<label class="col-sm-3 control-label">Nazwa pola:</label>';
html += '<div class="col-sm-9">';
html += '<input type="text" class="form-control" name="custom_field_name[]" value="">';
html += '</div>';
html += '</div>';
html += '<div class="form-group row">';
html += '<label class="col-sm-3 control-label">Rodzaj pola:</label>';
html += '<div class="col-sm-9">';
html += '<select class="form-control" name="custom_field_type[]">';
html += '<option value="txt" selected="selected">Tekst</option>';
html += '<option value="img">Obrazek</option>';
html += '</select>';
html += '</div>';
html += '</div>';
html += '<div class="form-group row">';
html += '<label class="col-sm-3 control-label">Status pola:</label>';
html += '<div class="col-sm-9">';
html += '<label style="margin:0; font-weight:normal;" class="d-flex align-items-center mt-3">';
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 class="form-group row">';
html += '<div class="col-sm-12 text-right">';
html += '<span class="input-group-addon btn btn-info" onclick="remove_custom_filed( $( this ) );">usuń</span>';
html += '</div>';
html += '</div>';
html += '</div>';
html += '</div>';
$('.additional_fields').append(html);
});

View File

@@ -186,7 +186,7 @@ class ShopProduct
$values['id'], $values['name'], $values['short_description'], $values['description'], $values['status'], $values['meta_description'], $values['meta_keywords'], $values['seo_link'],
$values['copy_from'], $values['categories'], $values['price_netto'], $values['price_brutto'], $values['vat'], $values['promoted'], $values['warehouse_message_zero'], $values['warehouse_message_nonzero'], $values['tab_name_1'],
$values['tab_description_1'], $values['tab_name_2'], $values['tab_description_2'], $values['layout_id'], $values['products_related'], (int) $values['set'], $values['price_netto_promo'], $values['price_brutto_promo'],
$values['new_to_date'], $values['stock_0_buy'], $values['wp'], $values['custom_label_0'], $values['custom_label_1'], $values['custom_label_2'], $values['custom_label_3'], $values['custom_label_4'], $values['additional_message'], (int)$values['quantity'], $values['additional_message_text'], $values['additional_message_required'] == 'on' ? 1 : 0, $values['canonical'], $values['meta_title'], $values['producer_id'], $values['sku'], $values['ean'], $values['product_unit'], $values['weight'], $values['xml_name'], $values['custom_field_name'], $values['custom_field_required'], $values['security_information']
$values['new_to_date'], $values['stock_0_buy'], $values['wp'], $values['custom_label_0'], $values['custom_label_1'], $values['custom_label_2'], $values['custom_label_3'], $values['custom_label_4'], $values['additional_message'], (int)$values['quantity'], $values['additional_message_text'], $values['additional_message_required'] == 'on' ? 1 : 0, $values['canonical'], $values['meta_title'], $values['producer_id'], $values['sku'], $values['ean'], $values['product_unit'], $values['weight'], $values['xml_name'], $values['custom_field_name'], $values['custom_field_required'], $values['security_information'], $values['custom_field_type']
) ) {
$response = [ 'status' => 'ok', 'msg' => 'Produkt został zapisany.', 'id' => $id ];
}

View File

@@ -761,7 +761,7 @@ class ShopProduct
}
public static function save(
$product_id, $name, $short_description, $description, $status, $meta_description, $meta_keywords, $seo_link, $copy_from, $categories, $price_netto, $price_brutto, $vat, $promoted, $warehouse_message_zero, $warehouse_message_nonzero, $tab_name_1, $tab_description_1, $tab_name_2, $tab_description_2, $layout_id, $products_related, int $set_id, $price_netto_promo, $price_brutto_promo, $new_to_date, $stock_0_buy, $wp, $custom_label_0, $custom_label_1, $custom_label_2, $custom_label_3, $custom_label_4, $additional_message, int $quantity, $additional_message_text, int $additional_message_required, $canonical, $meta_title, $producer_id, $sku, $ean, $product_unit, $weight, $xml_name, $custom_field_name, $custom_field_required, $security_information
$product_id, $name, $short_description, $description, $status, $meta_description, $meta_keywords, $seo_link, $copy_from, $categories, $price_netto, $price_brutto, $vat, $promoted, $warehouse_message_zero, $warehouse_message_nonzero, $tab_name_1, $tab_description_1, $tab_name_2, $tab_description_2, $layout_id, $products_related, int $set_id, $price_netto_promo, $price_brutto_promo, $new_to_date, $stock_0_buy, $wp, $custom_label_0, $custom_label_1, $custom_label_2, $custom_label_3, $custom_label_4, $additional_message, int $quantity, $additional_message_text, int $additional_message_required, $canonical, $meta_title, $producer_id, $sku, $ean, $product_unit, $weight, $xml_name, $custom_field_name, $custom_field_required, $security_information, $custom_field_type
)
{
global $mdb, $user;
@@ -948,11 +948,13 @@ class ShopProduct
if ( !empty( $custom_field_name[$i] ) )
{
$custom_field = $custom_field_name[$i];
$custom_field_type_data = $custom_field_type[$i];
$custom_field_required = isset( $custom_field_required[$i] ) ? 1 : 0;
$mdb -> insert( 'pp_shop_products_custom_fields', [
'id_product' => (int) $id,
'name' => $custom_field,
'type' => $custom_field_type_data,
'is_required' => $custom_field_required,
] );
}
@@ -1281,15 +1283,26 @@ class ShopProduct
{
if ( !empty( $custom_field ) )
{
$custom_field_type_data = $custom_field_type[$i];
$is_required = !empty( $custom_field_required[$i] ) ? 1 : 0;
if ( !$mdb -> count( 'pp_shop_products_custom_fields', [ 'AND' => [ 'id_product' => $product_id, 'name' => $custom_field ] ] ) )
{
$mdb -> insert( 'pp_shop_products_custom_fields', [ 'id_product' => $product_id, 'name' => $custom_field, 'is_required' => $is_required ] );
$mdb -> insert( 'pp_shop_products_custom_fields', [
'id_product' => $product_id,
'name' => $custom_field,
'type' => $custom_field_type_data,
'is_required' => $is_required
]);
}
else
{
$mdb -> update( 'pp_shop_products_custom_fields', [ 'is_required' => $is_required ], [ 'AND' => [ 'id_product' => $product_id, 'name' => $custom_field ] ] );
$mdb -> update( 'pp_shop_products_custom_fields',
[
'type' => $custom_field_type_data,
'is_required' => $is_required
],
[ 'AND' => [ 'id_product' => $product_id, 'name' => $custom_field ] ]);
}
}
}

View File

@@ -1,13 +1,20 @@
<? if ( $this -> custom_fields ): foreach ( $this -> custom_fields as $key => $val ):?>
<div class="custom-field">
<div class="_name">
<?
$custom_field = \shop\ProductCustomField::getFromCache( $key );
echo $custom_field['name'] . ':';
?>
</div>
<div class="_text">
<?= $val;?>
</div>
</div>
<? endforeach; endif;?>
<? if ( $this -> custom_fields ) : ?>
<? foreach ( $this -> custom_fields as $key => $val ) : ?>
<? $custom_field = \shop\ProductCustomField::getFromCache( $key ); ?>
<? if ( $custom_field['type'] == 'text' ) : ?>
<div class="custom-field">
<div class="_name">
<?
echo $custom_field['name'] . ':';
?>
</div>
<div class="_text">
<?= $val;?>
</div>
</div>
<? elseif ( $custom_field['type'] == 'image' ) : ?>
<? endif; ?>
<? endforeach; ?>
<? endif;?>

View File

@@ -1,10 +1,23 @@
<? if ( is_array( $this -> custom_fields ) ): foreach ( $this -> custom_fields as $custom_field ):?>
<div class="custom-field">
<div class="_name">
<?= $custom_field['name'];?><? if ( !empty( $custom_field['is_required'] ) ): ?>*<? endif; ?>:
</div>
<div class="_input">
<input type="text" class="form-control" name="custom_field[<?= $custom_field['id_additional_field'];?>]" field_name="<?= $custom_field['name'];?>" value="" <? if ( !empty( $custom_field['is_required'] ) ): ?>required<? endif; ?>>
</div>
</div>
<? endforeach; endif;?>
<? if ( is_array( $this -> custom_fields ) ) : ?>
<? foreach ( $this -> custom_fields as $custom_field ): ?>
<? if ( $custom_field['type'] == 'text' ) : ?>
<div class="custom-field">
<div class="_name">
<?= $custom_field['name'];?><? if ( !empty( $custom_field['is_required'] ) ): ?>*<? endif; ?>:
</div>
<div class="_input">
<input type="text" class="form-control" name="custom_field[<?= $custom_field['id_additional_field'];?>]" field_name="<?= $custom_field['name'];?>" value="" <? if ( !empty( $custom_field['is_required'] ) ): ?>required<? endif; ?>>
</div>
</div>
<? elseif ( $custom_field['type'] == 'image' ) : ?>
<div class="custom-field">
<div class="_name">
<?= $custom_field['name'];?><? if ( !empty( $custom_field['is_required'] ) ): ?>*<? endif; ?>:
</div>
<div class="_input">
<input type="file" class="form-control-file" name="custom_field[<?= $custom_field['id_additional_field'];?>]" field_name="<?= $custom_field['name'];?>" src="" alt="" <? if ( !empty( $custom_field['is_required'] ) ): ?>required<? endif; ?>>
</div>
</div>
<? endif; ?>
<? endforeach; ?>
<? endif;?>

BIN
updates/0.20/ver_0.233.zip Normal file

Binary file not shown.

View File

@@ -0,0 +1 @@
ALTER TABLE pp_shop_products_custom_fields ADD COLUMN `type` VARCHAR(30) NOT NULL AFTER `name`